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 380b4b3777e7ff0f9f1a4060775304bc00a738d7 Author: Guillaume Nodet <[email protected]> AuthorDate: Thu Jun 11 09:24:02 2020 +0200 [CAMEL-11807] Upgrade camel-olingo2 to junit5 --- components/camel-olingo2/camel-olingo2-api/pom.xml | 2 +- .../camel-olingo2/camel-olingo2-component/pom.xml | 2 +- .../olingo2/AbstractOlingo2AppAPITestSupport.java | 8 ++--- .../olingo2/AbstractOlingo2TestSupport.java | 10 ++---- .../olingo2/Olingo2AppAPIETagEnabledTest.java | 16 ++++----- .../camel/component/olingo2/Olingo2AppAPITest.java | 29 +++++++++-------- .../olingo2/Olingo2ComponentConsumerTest.java | 17 +++++++--- .../olingo2/Olingo2ComponentProducerTest.java | 38 +++++++++++++--------- .../camel/component/olingo2/Olingo2RouteTest.java | 17 ++++++---- 9 files changed, 76 insertions(+), 63 deletions(-) diff --git a/components/camel-olingo2/camel-olingo2-api/pom.xml b/components/camel-olingo2/camel-olingo2-api/pom.xml index 7308383..fd3c9c3 100644 --- a/components/camel-olingo2/camel-olingo2-api/pom.xml +++ b/components/camel-olingo2/camel-olingo2-api/pom.xml @@ -72,7 +72,7 @@ <!-- testing --> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> + <artifactId>camel-test-junit5</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/components/camel-olingo2/camel-olingo2-component/pom.xml b/components/camel-olingo2/camel-olingo2-component/pom.xml index bb93c84..d167b5d 100644 --- a/components/camel-olingo2/camel-olingo2-component/pom.xml +++ b/components/camel-olingo2/camel-olingo2-component/pom.xml @@ -94,7 +94,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>camel-test</artifactId> + <artifactId>camel-test-junit5</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java index be1af95..c7f6521 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java @@ -35,8 +35,8 @@ import org.apache.olingo.odata2.api.ep.feed.ODataFeed; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; // CHECKSTYLE:OFF public class AbstractOlingo2AppAPITestSupport { @@ -178,11 +178,11 @@ public class AbstractOlingo2AppAPITestSupport { } public T await(long timeout, TimeUnit unit) throws Exception { - assertTrue("Timeout waiting for response", latch.await(timeout, unit)); + assertTrue(latch.await(timeout, unit), "Timeout waiting for response"); if (error != null) { throw error; } - assertNotNull("Response", response); + assertNotNull(response, "Response"); return response; } diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java index 392f527..2bfa3fe 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java @@ -24,12 +24,14 @@ import java.util.Properties; import org.apache.camel.CamelContext; import org.apache.camel.CamelExecutionException; import org.apache.camel.support.PropertyBindingSupport; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.TestInstance; /** * Abstract base class for Olingo Integration tests generated by Camel API * component maven plugin. */ +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public class AbstractOlingo2TestSupport extends CamelTestSupport { private static final String TEST_OPTIONS_PROPERTIES = "/test-options.properties"; @@ -68,12 +70,6 @@ public class AbstractOlingo2TestSupport extends CamelTestSupport { return context; } - @Override - public boolean isCreateCamelContextPerClass() { - // only create the context once for this class - return true; - } - @SuppressWarnings("unchecked") protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws CamelExecutionException { return (T)template().requestBodyAndHeaders(endpointUri, body, headers); diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPIETagEnabledTest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPIETagEnabledTest.java index 4c5c03c..6ac74158 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPIETagEnabledTest.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPIETagEnabledTest.java @@ -41,13 +41,13 @@ import org.apache.olingo.odata2.api.ep.EntityProvider; import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties; import org.apache.olingo.odata2.api.processor.ODataResponse; import org.eclipse.jetty.http.HttpHeader; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests support for concurrency properties which generate and require reading @@ -65,13 +65,13 @@ public class Olingo2AppAPIETagEnabledTest extends AbstractOlingo2AppAPITestSuppo private static Edm edm; private static EdmEntitySet manufacturersSet; - @BeforeClass + @BeforeAll public static void scaffold() throws Exception { initEdm(); initServer(); } - @AfterClass + @AfterAll public static void unscaffold() throws Exception { if (olingoApp != null) { olingoApp.close(); diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java index 04dda9b..1dba238 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java @@ -43,14 +43,15 @@ import org.apache.olingo.odata2.api.ep.entry.ODataEntry; import org.apache.olingo.odata2.api.ep.feed.ODataFeed; import org.apache.olingo.odata2.api.servicedocument.Collection; import org.apache.olingo.odata2.api.servicedocument.ServiceDocument; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** * Integration test for @@ -65,14 +66,14 @@ public class Olingo2AppAPITest extends AbstractOlingo2AppAPITestSupport { private static Olingo2SampleServer server; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { startServers(PORT); Olingo2SampleServer.generateSampleData(TEST_SERVICE_URL); setupClient(); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { if (olingoApp != null) { olingoApp.close(); @@ -117,11 +118,11 @@ public class Olingo2AppAPITest extends AbstractOlingo2AppAPITestSupport { final ServiceDocument serviceDocument = responseHandler.await(); final List<Collection> collections = serviceDocument.getAtomInfo().getWorkspaces().get(0).getCollections(); - assertEquals("Service Atom Collections", 3, collections.size()); + assertEquals(3, collections.size(), "Service Atom Collections"); LOG.info("Service Atom Collections: {}", collections); final List<EdmEntitySetInfo> entitySetsInfo = serviceDocument.getEntitySetsInfo(); - assertEquals("Service Entity Sets", 3, entitySetsInfo.size()); + assertEquals(3, entitySetsInfo.size(), "Service Entity Sets"); LOG.info("Service Document Entries: {}", entitySetsInfo); } @@ -132,7 +133,7 @@ public class Olingo2AppAPITest extends AbstractOlingo2AppAPITestSupport { olingoApp.read(edm, MANUFACTURERS, null, null, responseHandler); final ODataFeed dataFeed = responseHandler.await(); - assertNotNull("Data feed", dataFeed); + assertNotNull(dataFeed, "Data feed"); LOG.info("Entries: {}", prettyPrint(dataFeed)); } @@ -143,7 +144,7 @@ public class Olingo2AppAPITest extends AbstractOlingo2AppAPITestSupport { olingoApp.uread(edm, MANUFACTURERS, null, null, responseHandler); final InputStream rawfeed = responseHandler.await(); - assertNotNull("Data feed", rawfeed); + assertNotNull(rawfeed, "Data feed"); // for this test, we just let EP to verify the stream data final ODataFeed dataFeed = EntityProvider.readFeed(TEST_FORMAT_STRING, edmEntitySetMap.get(MANUFACTURERS), rawfeed, EntityProviderReadProperties.init().build()); LOG.info("Entries: {}", prettyPrint(dataFeed)); @@ -428,7 +429,7 @@ public class Olingo2AppAPITest extends AbstractOlingo2AppAPITestSupport { olingoApp.batch(edm, null, batchParts, responseHandler); final List<Olingo2BatchResponse> responseParts = responseHandler.await(15, TimeUnit.MINUTES); - assertEquals("Batch responses expected", 8, responseParts.size()); + assertEquals(8, responseParts.size(), "Batch responses expected"); assertNotNull(responseParts.get(0).getBody()); final ODataFeed feed = (ODataFeed)responseParts.get(1).getBody(); diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentConsumerTest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentConsumerTest.java index 3a22139..e24df0d 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentConsumerTest.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentConsumerTest.java @@ -23,9 +23,16 @@ import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.AvailablePortFinder; import org.apache.olingo.odata2.api.ep.entry.ODataEntry; import org.apache.olingo.odata2.api.ep.feed.ODataFeed; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** * Test class for {@link org.apache.camel.component.olingo2.api.Olingo2App} @@ -46,13 +53,13 @@ public class Olingo2ComponentConsumerTest extends AbstractOlingo2TestSupport { setDefaultTestProperty("serviceUri", "http://localhost:" + PORT + "/MyFormula.svc"); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { startServers(PORT); Olingo2SampleServer.generateSampleData(TEST_SERVICE_URL); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { if (server != null) { server.stop(); diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentProducerTest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentProducerTest.java index d351e57..04b64aa 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentProducerTest.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentProducerTest.java @@ -38,12 +38,18 @@ import org.apache.olingo.odata2.api.edm.Edm; import org.apache.olingo.odata2.api.ep.entry.ODataEntry; import org.apache.olingo.odata2.api.ep.feed.ODataFeed; import org.apache.olingo.odata2.api.servicedocument.ServiceDocument; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + /** * Test class for {@link org.apache.camel.component.olingo2.api.Olingo2App} * APIs. @@ -73,13 +79,13 @@ public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport { setDefaultTestProperty("serviceUri", "http://localhost:" + PORT + "/MyFormula.svc"); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { startServers(PORT); Olingo2SampleServer.generateSampleData(TEST_SERVICE_URL); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { if (server != null) { server.stop(); @@ -99,7 +105,7 @@ public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport { // read ServiceDocument final ServiceDocument document = requestBodyAndHeaders("direct:READSERVICEDOC", null, headers); assertNotNull(document); - assertFalse("ServiceDocument entity sets", document.getEntitySetsInfo().isEmpty()); + assertFalse(document.getEntitySetsInfo().isEmpty(), "ServiceDocument entity sets"); LOG.info("Service document has {} entity sets", document.getEntitySetsInfo().size()); // parameter type is java.util.Map @@ -111,7 +117,7 @@ public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport { final ODataFeed manufacturers = requestBodyAndHeaders("direct:READFEED", null, headers); assertNotNull(manufacturers); final List<ODataEntry> manufacturersEntries = manufacturers.getEntries(); - assertFalse("Manufacturers empty entries", manufacturersEntries.isEmpty()); + assertFalse(manufacturersEntries.isEmpty(), "Manufacturers empty entries"); LOG.info("Manufacturers feed has {} entries", manufacturersEntries.size()); // read ODataEntry @@ -120,7 +126,7 @@ public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport { final ODataEntry manufacturer = requestBodyAndHeaders("direct:READENTRY", null, headers); assertNotNull(manufacturer); final Map<String, Object> properties = manufacturer.getProperties(); - assertEquals("Manufacturer Id", "1", properties.get(ID_PROPERTY)); + assertEquals("1", properties.get(ID_PROPERTY), "Manufacturer Id"); LOG.info("Manufacturer: {}", properties); } @@ -130,9 +136,9 @@ public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport { Map<String, Object> address; final ODataEntry manufacturer = requestBody("direct:CREATE", data); - assertNotNull("Created Manufacturer", manufacturer); + assertNotNull(manufacturer, "Created Manufacturer"); final Map<String, Object> properties = manufacturer.getProperties(); - assertEquals("Created Manufacturer Id", "123", properties.get(ID_PROPERTY)); + assertEquals("123", properties.get(ID_PROPERTY), "Created Manufacturer Id"); LOG.info("Created Manufacturer: {}", properties); // update @@ -141,14 +147,14 @@ public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport { address.put("Street", "Main Street"); HttpStatusCodes status = requestBody("direct:UPDATE", data); - assertNotNull("Update status", status); - assertEquals("Update status", HttpStatusCodes.NO_CONTENT.getStatusCode(), status.getStatusCode()); + assertNotNull(status, "Update status"); + assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), status.getStatusCode(), "Update status"); LOG.info("Update status: {}", status); // delete status = requestBody("direct:DELETE", null); - assertNotNull("Delete status", status); - assertEquals("Delete status", HttpStatusCodes.NO_CONTENT.getStatusCode(), status.getStatusCode()); + assertNotNull(status, "Delete status"); + assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), status.getStatusCode(), "Delete status"); LOG.info("Delete status: {}", status); } @@ -206,8 +212,8 @@ public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport { // execute batch request final List<Olingo2BatchResponse> responseParts = requestBody("direct:BATCH", batchParts); - assertNotNull("Batch response", responseParts); - assertEquals("Batch responses expected", 9, responseParts.size()); + assertNotNull(responseParts, "Batch response"); + assertEquals(9, responseParts.size(), "Batch responses expected"); final Edm edm = (Edm)responseParts.get(0).getBody(); assertNotNull(edm); diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java index f3e7e21..4cf0f6e 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java @@ -24,11 +24,14 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.olingo2.api.Olingo2App; import org.apache.camel.component.olingo2.internal.Olingo2Constants; import org.apache.camel.test.AvailablePortFinder; -import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.olingo.odata2.api.ep.entry.ODataEntry; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class Olingo2RouteTest extends CamelTestSupport { private static final int PORT = AvailablePortFinder.getNextAvailable(); @@ -38,13 +41,13 @@ public class Olingo2RouteTest extends CamelTestSupport { private static Olingo2App olingoApp; private static Olingo2SampleServer server; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { startServers(PORT); Olingo2SampleServer.generateSampleData(TEST_SERVICE_URL); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { if (olingoApp != null) { olingoApp.close(); @@ -73,7 +76,7 @@ public class Olingo2RouteTest extends CamelTestSupport { final ODataEntry manufacturer = requestBodyAndHeaders("direct:READENTRY", null, headers); assertNotNull(manufacturer); final Map<String, Object> properties = manufacturer.getProperties(); - assertEquals("Manufacturer Id", "1", properties.get(ID_PROPERTY)); + assertEquals("1", properties.get(ID_PROPERTY), "Manufacturer Id"); } @Override
