This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8078d8495fe07b5279630f50f30ecc4caf0a0894 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Mon Jul 20 14:03:54 2020 +0200 [CAMEL-11807] Upgrade camel-rest-openapi to junit5 --- components/camel-rest-openapi/pom.xml | 8 +- .../camel/component/rest/openapi/HttpsTest.java | 53 ++++++++----- .../camel/component/rest/openapi/HttpsV3Test.java | 55 +++++++++----- .../rest/openapi/RestOpenApiComponentTest.java | 88 +++++++++++++++------- .../rest/openapi/RestOpenApiComponentV3Test.java | 88 +++++++++++++++------- .../rest/openapi/RestOpenApiDelegateHttpsTest.java | 3 - .../openapi/RestOpenApiDelegateHttpsV3Test.java | 3 - .../rest/openapi/RestOpenApiEndpointTest.java | 13 ++-- .../openapi/RestOpenApiEndpointUriParsingTest.java | 32 ++------ .../rest/openapi/RestOpenApiEndpointV3Test.java | 13 ++-- .../rest/openapi/RestOpenApiHelperTest.java | 18 +++-- 11 files changed, 232 insertions(+), 142 deletions(-) diff --git a/components/camel-rest-openapi/pom.xml b/components/camel-rest-openapi/pom.xml index 7ed0726..2c49625 100644 --- a/components/camel-rest-openapi/pom.xml +++ b/components/camel-rest-openapi/pom.xml @@ -58,19 +58,19 @@ <!-- test --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> + <artifactId>camel-test-junit5</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsTest.java index 1a160c1..5b01a49 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsTest.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsTest.java @@ -32,8 +32,8 @@ import javax.net.ssl.TrustManagerFactory; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; +import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.common.HttpsSettings; -import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.common.io.Resources; import org.apache.camel.CamelContext; import org.apache.camel.RoutesBuilder; @@ -43,16 +43,14 @@ import org.apache.camel.converter.jaxb.JaxbDataFormat; import org.apache.camel.support.jsse.CipherSuitesParameters; import org.apache.camel.support.jsse.SSLContextParameters; import org.apache.camel.support.jsse.TrustManagersParameters; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.security.CertificateUtils; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.runners.Parameterized.Parameters; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; @@ -61,28 +59,49 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(Parameterized.class) public abstract class HttpsTest extends CamelTestSupport { - @ClassRule - public static WireMockRule petstore = new WireMockRule( + protected static WireMockServer petstore = new WireMockServer( wireMockConfig().httpServerFactory(new Jetty94ServerFactory()).containerThreads(13).dynamicPort() .dynamicHttpsPort().keystorePath(Resources.getResource("localhost.p12").toString()).keystoreType("PKCS12") .keystorePassword("changeit")); static final Object NO_BODY = null; - @Parameter public String componentName; - @Before + @BeforeAll + public static void startWireMockServer() { + petstore.start(); + } + + @AfterAll + public static void stopWireMockServer() { + petstore.stop(); + } + + @Override + public void setUp() throws Exception { + } + + @BeforeEach public void resetWireMock() { petstore.resetRequests(); } - @Test - public void shouldBeConfiguredForHttps() throws Exception { + public void doSetUp(String componentName) throws Exception { + this.componentName = componentName; + super.setUp(); + } + + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeConfiguredForHttps(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = template.requestBodyAndHeader("direct:getPetById", NO_BODY, "petId", 14, Pet.class); assertNotNull(pet); @@ -133,7 +152,7 @@ public abstract class HttpsTest extends CamelTestSupport { return producers; } - @BeforeClass + @BeforeAll public static void setupStubs() throws IOException, URISyntaxException { petstore.stubFor(get(urlEqualTo("/openapi.json")).willReturn(aResponse().withBody( Files.readAllBytes(Paths.get(RestOpenApiGlobalHttpsTest.class.getResource("/openapi.json").toURI()))))); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java index 7ab8d69..c6e0c0e 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java @@ -32,8 +32,8 @@ import javax.net.ssl.TrustManagerFactory; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; +import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.common.HttpsSettings; -import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.common.io.Resources; import org.apache.camel.CamelContext; import org.apache.camel.RoutesBuilder; @@ -43,17 +43,14 @@ import org.apache.camel.converter.jaxb.JaxbDataFormat; import org.apache.camel.support.jsse.CipherSuitesParameters; import org.apache.camel.support.jsse.SSLContextParameters; import org.apache.camel.support.jsse.TrustManagersParameters; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.security.CertificateUtils; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; @@ -61,28 +58,49 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(Parameterized.class) public abstract class HttpsV3Test extends CamelTestSupport { - @ClassRule - public static WireMockRule petstore = new WireMockRule( + public static WireMockServer petstore = new WireMockServer( wireMockConfig().httpServerFactory(new Jetty94ServerFactory()).containerThreads(13).dynamicPort() .dynamicHttpsPort().keystorePath(Resources.getResource("localhost.p12").toString()).keystoreType("PKCS12") .keystorePassword("changeit")); static final Object NO_BODY = null; - @Parameter public String componentName; - @Before + @BeforeAll + public static void startWireMockServer() { + petstore.start(); + } + + @AfterAll + public static void stopWireMockServer() { + petstore.stop(); + } + + @Override + public void setUp() throws Exception { + } + + @BeforeEach public void resetWireMock() { petstore.resetRequests(); } - @Test - public void shouldBeConfiguredForHttps() throws Exception { + public void doSetUp(String componentName) throws Exception { + this.componentName = componentName; + super.setUp(); + } + + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeConfiguredForHttps(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = template.requestBodyAndHeader("direct:getPetById", NO_BODY, "petId", 14, Pet.class); assertNotNull(pet); @@ -123,7 +141,6 @@ public abstract class HttpsV3Test extends CamelTestSupport { }; } - @Parameters(name = "component = {0}") public static Iterable<String> knownProducers() { final List<String> producers = new ArrayList<>(Arrays.asList(RestEndpoint.DEFAULT_REST_PRODUCER_COMPONENTS)); // skip http due security certificate testing problems @@ -131,7 +148,7 @@ public abstract class HttpsV3Test extends CamelTestSupport { return producers; } - @BeforeClass + @BeforeAll public static void setupStubs() throws IOException, URISyntaxException { petstore.stubFor(get(urlEqualTo("/openapi.json")).willReturn(aResponse().withBody( Files.readAllBytes(Paths.get(RestOpenApiGlobalHttpsTest.class.getResource("/openapi.json").toURI()))))); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentTest.java index a1e6046..761bf01 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentTest.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentTest.java @@ -29,20 +29,18 @@ import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; -import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.github.tomakehurst.wiremock.WireMockServer; import org.apache.camel.CamelContext; import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.rest.RestEndpoint; import org.apache.camel.converter.jaxb.JaxbDataFormat; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.runners.Parameterized.Parameters; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; @@ -54,25 +52,46 @@ import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(Parameterized.class) public class RestOpenApiComponentTest extends CamelTestSupport { - @ClassRule - public static WireMockRule petstore = new WireMockRule(wireMockConfig().dynamicPort()); + public static WireMockServer petstore = new WireMockServer(wireMockConfig().dynamicPort()); static final Object NO_BODY = null; - @Parameter public String componentName; - @Before + @BeforeAll + public static void startWireMockServer() { + petstore.start(); + } + + @AfterAll + public static void stopWireMockServer() { + petstore.stop(); + } + + @Override + public void setUp() throws Exception { + } + + @BeforeEach public void resetWireMock() { petstore.resetRequests(); } - @Test - public void shouldBeAddingPets() { + public void doSetUp(String componentName) throws Exception { + this.componentName = componentName; + super.setUp(); + } + + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeAddingPets(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = new Pet(); pet.name = "Jean-Luc Picard"; @@ -87,8 +106,11 @@ public class RestOpenApiComponentTest extends CamelTestSupport { .withHeader("Content-Type", equalTo("application/xml"))); } - @Test - public void shouldBeGettingPetsById() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsById(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = template.requestBodyAndHeader("direct:getPetById", NO_BODY, "petId", 14, Pet.class); assertNotNull(pet); @@ -100,8 +122,11 @@ public class RestOpenApiComponentTest extends CamelTestSupport { equalTo("application/xml, application/json"))); } - @Test - public void shouldBeGettingPetsByIdSpecifiedInEndpointParameters() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByIdSpecifiedInEndpointParameters(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = template.requestBody("direct:getPetByIdWithEndpointParams", NO_BODY, Pet.class); assertNotNull(pet); @@ -113,8 +138,11 @@ public class RestOpenApiComponentTest extends CamelTestSupport { equalTo("application/xml, application/json"))); } - @Test - public void shouldBeGettingPetsByIdWithApiKeysInHeader() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByIdWithApiKeysInHeader(String componentName) throws Exception { + doSetUp(componentName); + final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); headers.put("api_key", "dolphins"); @@ -130,8 +158,11 @@ public class RestOpenApiComponentTest extends CamelTestSupport { .withHeader("api_key", equalTo("dolphins"))); } - @Test - public void shouldBeGettingPetsByIdWithApiKeysInQueryParameter() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByIdWithApiKeysInQueryParameter(String componentName) throws Exception { + doSetUp(componentName); + final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); headers.put("api_key", "dolphins"); @@ -146,8 +177,11 @@ public class RestOpenApiComponentTest extends CamelTestSupport { equalTo("application/xml, application/json"))); } - @Test - public void shouldBeGettingPetsByStatus() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByStatus(String componentName) throws Exception { + doSetUp(componentName); + final Pets pets = template.requestBodyAndHeader("direct:findPetsByStatus", NO_BODY, "status", "available", Pets.class); @@ -207,7 +241,7 @@ public class RestOpenApiComponentTest extends CamelTestSupport { return Arrays.asList(RestEndpoint.DEFAULT_REST_PRODUCER_COMPONENTS); } - @BeforeClass + @BeforeAll public static void setupStubs() throws IOException, URISyntaxException { petstore.stubFor(get(urlEqualTo("/openapi.json")).willReturn(aResponse().withBody( Files.readAllBytes(Paths.get(RestOpenApiComponentTest.class.getResource("/openapi.json").toURI()))))); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java index 032fe7c..e5298c7 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java @@ -29,20 +29,18 @@ import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; -import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.github.tomakehurst.wiremock.WireMockServer; import org.apache.camel.CamelContext; import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.rest.RestEndpoint; import org.apache.camel.converter.jaxb.JaxbDataFormat; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.runners.Parameterized.Parameters; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; @@ -54,25 +52,46 @@ import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(Parameterized.class) public class RestOpenApiComponentV3Test extends CamelTestSupport { - @ClassRule - public static WireMockRule petstore = new WireMockRule(wireMockConfig().dynamicPort()); + public static WireMockServer petstore = new WireMockServer(wireMockConfig().dynamicPort()); static final Object NO_BODY = null; - @Parameter public String componentName; - @Before + @BeforeAll + public static void startWireMockServer() { + petstore.start(); + } + + @AfterAll + public static void stopWireMockServer() { + petstore.stop(); + } + + @Override + public void setUp() throws Exception { + } + + @BeforeEach public void resetWireMock() { petstore.resetRequests(); } - @Test - public void shouldBeAddingPets() { + public void doSetUp(String componentName) throws Exception { + this.componentName = componentName; + super.setUp(); + } + + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeAddingPets(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = new Pet(); pet.name = "Jean-Luc Picard"; @@ -87,8 +106,11 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { .withHeader("Content-Type", equalTo("application/xml"))); } - @Test - public void shouldBeGettingPetsById() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsById(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = template.requestBodyAndHeader("direct:getPetById", NO_BODY, "petId", 14, Pet.class); assertNotNull(pet); @@ -100,8 +122,11 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { equalTo("application/xml, application/json"))); } - @Test - public void shouldBeGettingPetsByIdSpecifiedInEndpointParameters() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByIdSpecifiedInEndpointParameters(String componentName) throws Exception { + doSetUp(componentName); + final Pet pet = template.requestBody("direct:getPetByIdWithEndpointParams", NO_BODY, Pet.class); assertNotNull(pet); @@ -113,8 +138,11 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { equalTo("application/xml, application/json"))); } - @Test - public void shouldBeGettingPetsByIdWithApiKeysInHeader() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByIdWithApiKeysInHeader(String componentName) throws Exception { + doSetUp(componentName); + final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); headers.put("api_key", "dolphins"); @@ -130,8 +158,11 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { .withHeader("api_key", equalTo("dolphins"))); } - @Test - public void shouldBeGettingPetsByIdWithApiKeysInQueryParameter() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByIdWithApiKeysInQueryParameter(String componentName) throws Exception { + doSetUp(componentName); + final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); headers.put("api_key", "dolphins"); @@ -146,8 +177,11 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { equalTo("application/xml, application/json"))); } - @Test - public void shouldBeGettingPetsByStatus() { + @ParameterizedTest + @MethodSource("knownProducers") + public void shouldBeGettingPetsByStatus(String componentName) throws Exception { + doSetUp(componentName); + final Pets pets = template.requestBodyAndHeader("direct:findPetsByStatus", NO_BODY, "status", "available", Pets.class); @@ -208,7 +242,7 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { return Arrays.asList(RestEndpoint.DEFAULT_REST_PRODUCER_COMPONENTS); } - @BeforeClass + @BeforeAll public static void setupStubs() throws IOException, URISyntaxException { petstore.stubFor(get(urlEqualTo("/openapi-v3.json")).willReturn(aResponse().withBody( Files.readAllBytes(Paths.get(RestOpenApiComponentV3Test.class.getResource("/openapi-v3.json").toURI()))))); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsTest.java index da1e1e7..056f436 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsTest.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsTest.java @@ -20,10 +20,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.Component; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.PropertyBindingSupport; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -@RunWith(Parameterized.class) public class RestOpenApiDelegateHttpsTest extends HttpsTest { @Override diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java index d1bb09a..c16ebed 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java @@ -20,10 +20,7 @@ import org.apache.camel.CamelContext; import org.apache.camel.Component; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.PropertyBindingSupport; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -@RunWith(Parameterized.class) public class RestOpenApiDelegateHttpsV3Test extends HttpsV3Test { @Override diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointTest.java index 755f0dc..9963f92 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointTest.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointTest.java @@ -34,10 +34,11 @@ import io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme; import org.apache.camel.CamelContext; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.spi.RestConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -47,7 +48,7 @@ public class RestOpenApiEndpointTest { URI endpointUri = URI.create("endpoint.json"); - @Test(expected = IllegalArgumentException.class) + @Test public void shouldComplainForUnknownOperations() throws Exception { final CamelContext camelContext = mock(CamelContext.class); when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver()); @@ -57,7 +58,8 @@ public class RestOpenApiEndpointTest { final RestOpenApiEndpoint endpoint = new RestOpenApiEndpoint("rest-openapi:unknown", "unknown", component, Collections.emptyMap()); - endpoint.createProducer(); + assertThrows(IllegalArgumentException.class, + () -> endpoint.createProducer()); } @Test @@ -374,12 +376,13 @@ public class RestOpenApiEndpointTest { assertThat(RestOpenApiEndpoint.pickBestScheme(null, null)).isNull(); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldRaiseExceptionsForMissingSpecifications() throws IOException { final CamelContext camelContext = mock(CamelContext.class); when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver()); - RestOpenApiEndpoint.loadSpecificationFrom(camelContext, URI.create("non-existant.json")); + assertThrows(IllegalArgumentException.class, + () -> RestOpenApiEndpoint.loadSpecificationFrom(camelContext, URI.create("non-existant.json"))); } @Test diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriParsingTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriParsingTest.java index 5c8c0ce..9a6904e 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriParsingTest.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointUriParsingTest.java @@ -19,31 +19,16 @@ package org.apache.camel.component.rest.openapi; import java.util.Arrays; import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Parameterized.class) public class RestOpenApiEndpointUriParsingTest { - @Parameter(3) - public String operationId; - - @Parameter(1) - public String remaining; - - @Parameter(2) - public String specificationUri; - - @Parameter(0) - public String uri; - - @Test - public void shouldParseEndpointUri() { + @ParameterizedTest + @MethodSource("parameters") + public void shouldParseEndpointUri(String uri, String remaining, String specificationUri, String operationId) { final RestOpenApiComponent component = new RestOpenApiComponent(); final RestOpenApiEndpoint endpoint = new RestOpenApiEndpoint(specificationUri, remaining, component, @@ -53,16 +38,13 @@ public class RestOpenApiEndpointUriParsingTest { assertThat(endpoint.getOperationId()).isEqualTo(operationId); } - @Parameters(name = "uri={0}, remaining={1}") public static Iterable<Object[]> parameters() { return Arrays.asList(params("rest-openapi:operation", "operation", "openapi.json", "operation"), params("rest-openapi:my-api.json#operation", "my-api.json#operation", "my-api.json", "operation"), - params("rest-openapi:http://api.example.com/swagger.json#operation", - "http://api.example.com/swagger.json#operation", "http://api.example.com/swagger.json", "operation")); + params("rest-openapi:http://api.example.com/swagger.json#operation", "http://api.example.com/swagger.json#operation", "http://api.example.com/swagger.json", "operation")); } - static Object[] params(final String uri, final String remaining, final String specificationUri, - final String operationId) { + static Object[] params(final String uri, final String remaining, final String specificationUri, final String operationId) { return new Object[] {uri, remaining, specificationUri, operationId}; } } diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointV3Test.java index 175dafe..1622238 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpointV3Test.java @@ -36,10 +36,11 @@ import io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme; import org.apache.camel.CamelContext; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.spi.RestConfiguration; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -49,7 +50,7 @@ public class RestOpenApiEndpointV3Test { URI endpointUri = URI.create("endpoint.json"); - @Test(expected = IllegalArgumentException.class) + @Test public void shouldComplainForUnknownOperations() throws Exception { final CamelContext camelContext = mock(CamelContext.class); when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver()); @@ -59,7 +60,8 @@ public class RestOpenApiEndpointV3Test { final RestOpenApiEndpoint endpoint = new RestOpenApiEndpoint("rest-openapi:unknown", "unknown", component, Collections.emptyMap()); - endpoint.createProducer(); + assertThrows(IllegalArgumentException.class, + () -> endpoint.createProducer()); } @Test @@ -385,12 +387,13 @@ public class RestOpenApiEndpointV3Test { assertThat(RestOpenApiEndpoint.pickBestScheme(null, null)).isNull(); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldRaiseExceptionsForMissingSpecifications() throws IOException { final CamelContext camelContext = mock(CamelContext.class); when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver()); - RestOpenApiEndpoint.loadSpecificationFrom(camelContext, URI.create("non-existant.json")); + assertThrows(IllegalArgumentException.class, + () -> RestOpenApiEndpoint.loadSpecificationFrom(camelContext, URI.create("non-existant.json"))); } @Test diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiHelperTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiHelperTest.java index 9104ba0..948257b 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiHelperTest.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiHelperTest.java @@ -16,25 +16,29 @@ */ package org.apache.camel.component.rest.openapi; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; public class RestOpenApiHelperTest { - @Test(expected = IllegalArgumentException.class) + @Test public void emptyHostParamsAreNotAllowed() { - RestOpenApiHelper.isHostParam(""); + assertThrows(IllegalArgumentException.class, + () -> RestOpenApiHelper.isHostParam("")); } - @Test(expected = IllegalArgumentException.class) + @Test public void nonUriHostParametersAreNotAllowed() { - RestOpenApiHelper.isHostParam("carrot"); + assertThrows(IllegalArgumentException.class, + () -> RestOpenApiHelper.isHostParam("carrot")); } - @Test(expected = IllegalArgumentException.class) + @Test public void nullHostParamsAreNotAllowed() { - RestOpenApiHelper.isHostParam(null); + assertThrows(IllegalArgumentException.class, + () -> RestOpenApiHelper.isHostParam(null)); } @Test