001/* 002 * acme4j - Java ACME client 003 * 004 * Copyright (C) 2015 Richard "Shred" Körber 005 * http://acme4j.shredzone.org 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 013 */ 014package org.shredzone.acme4j.provider; 015 016import static org.assertj.core.api.Assertions.assertThat; 017import static org.shredzone.acme4j.toolbox.TestUtils.DEFAULT_NETWORK_SETTINGS; 018 019import java.net.URI; 020import java.net.URISyntaxException; 021 022import org.junit.jupiter.api.Test; 023import org.shredzone.acme4j.connector.DefaultConnection; 024 025/** 026 * Unit tests for {@link GenericAcmeProvider}. 027 */ 028public class GenericAcmeProviderTest { 029 030 /** 031 * Tests if the provider accepts the correct URIs. 032 */ 033 @Test 034 public void testAccepts() throws URISyntaxException { 035 var provider = new GenericAcmeProvider(); 036 037 assertThat(provider.accepts(new URI("http://example.com/acme"))).isTrue(); 038 assertThat(provider.accepts(new URI("https://example.com/acme"))).isTrue(); 039 assertThat(provider.accepts(new URI("acme://example.com"))).isFalse(); 040 } 041 042 /** 043 * Test if the provider resolves the URI correctly. 044 */ 045 @Test 046 public void testResolve() throws URISyntaxException { 047 var serverUri = new URI("http://example.com/acme?foo=abc&bar=123"); 048 049 var provider = new GenericAcmeProvider(); 050 051 var resolvedUrl = provider.resolve(serverUri); 052 assertThat(resolvedUrl.toString()).isEqualTo(serverUri.toString()); 053 054 var connection = provider.connect(serverUri, DEFAULT_NETWORK_SETTINGS); 055 assertThat(connection).isInstanceOf(DefaultConnection.class); 056 } 057 058}