You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2020/06/25 17:52:48 UTC
[camel] 04/12: [CAMEL-11807] Upgrade camel-google-pubsub to junit5
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 4a6cc8b7fbf27581d673b74bf6702aefb8d12eba
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Jun 25 10:52:41 2020 +0200
[CAMEL-11807] Upgrade camel-google-pubsub to junit5
---
components/camel-google-pubsub/pom.xml | 8 +------
.../component/google/pubsub/PubsubTestSupport.java | 13 ++++++----
.../google/pubsub/integration/AckModeNoneTest.java | 8 +++----
.../pubsub/integration/AcknowledgementTest.java | 2 +-
.../google/pubsub/integration/BodyTypesTest.java | 28 ++++++++++++----------
.../integration/GroupedExchangeRoundtripTest.java | 6 +++--
.../integration/SingleExchangeRoundtripTest.java | 17 +++++++------
.../google/pubsub/unit/PubsubEndpointTest.java | 8 +++++--
.../google/pubsub/unit/PubsubProducerTest.java | 7 ++++--
9 files changed, 55 insertions(+), 42 deletions(-)
diff --git a/components/camel-google-pubsub/pom.xml b/components/camel-google-pubsub/pom.xml
index ad7b9cc..9ec87e0 100644
--- a/components/camel-google-pubsub/pom.xml
+++ b/components/camel-google-pubsub/pom.xml
@@ -131,7 +131,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
+ <artifactId>camel-testcontainers-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -139,12 +139,6 @@
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.testcontainers</groupId>
- <artifactId>testcontainers</artifactId>
- <version>${testcontainers-version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java
index bda219d..1d6c1dd 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/PubsubTestSupport.java
@@ -34,12 +34,11 @@ import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.apache.camel.BindToRegistry;
import org.apache.camel.CamelContext;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.ClassRule;
+import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
-public class PubsubTestSupport extends CamelTestSupport {
+public class PubsubTestSupport extends ContainerAwareTestSupport {
public static final String PROJECT_ID;
@@ -48,8 +47,7 @@ public class PubsubTestSupport extends CamelTestSupport {
PROJECT_ID = testProperties.getProperty("project.id");
}
- @ClassRule
- public static GenericContainer container = new GenericContainer("google/cloud-sdk:latest")
+ protected GenericContainer<?> container = new GenericContainer<>("google/cloud-sdk:latest")
.withExposedPorts(8383)
.withCommand("/bin/sh", "-c",
String.format("gcloud beta emulators pubsub start --project %s --host-port=0.0.0.0:%d",
@@ -69,6 +67,11 @@ public class PubsubTestSupport extends CamelTestSupport {
return testProperties;
}
+ @Override
+ protected GenericContainer<?> createContainer() {
+ return super.createContainer();
+ }
+
protected void addPubsubComponent(CamelContext context) {
GooglePubsubComponent component = new GooglePubsubComponent();
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AckModeNoneTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AckModeNoneTest.java
index 7a9365d..31dc0ce 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AckModeNoneTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AckModeNoneTest.java
@@ -27,11 +27,11 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.google.pubsub.PubsubTestSupport;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.support.DefaultExchange;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
+import org.junit.jupiter.api.MethodOrderer.Alphanumeric;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@TestMethodOrder(Alphanumeric.class)
public class AckModeNoneTest extends PubsubTestSupport {
private static final String TOPIC_NAME = "ackNoneTopic";
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AcknowledgementTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AcknowledgementTest.java
index 8d5a80c..2343376 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AcknowledgementTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/AcknowledgementTest.java
@@ -26,7 +26,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.google.pubsub.PubsubTestSupport;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.support.DefaultExchange;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class AcknowledgementTest extends PubsubTestSupport {
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java
index 552c8a4..f75ba4d 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/BodyTypesTest.java
@@ -33,7 +33,11 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.google.pubsub.PubsubTestSupport;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.support.DefaultExchange;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class BodyTypesTest extends PubsubTestSupport {
@@ -90,25 +94,25 @@ public class BodyTypesTest extends PubsubTestSupport {
producer.send(exchange);
List<Exchange> sentExchanges = sendResult.getExchanges();
- assertEquals("Sent exchanges", 1, sentExchanges.size());
+ assertEquals(1, sentExchanges.size(), "Sent exchanges");
Exchange sentExchange = sentExchanges.get(0);
- assertTrue("Sent body type is byte[]", sentExchange.getIn().getBody() instanceof byte[]);
+ assertTrue(sentExchange.getIn().getBody() instanceof byte[], "Sent body type is byte[]");
- assertTrue("Sent body type is the one sent", sentExchange.getIn().getBody() == body);
+ assertTrue(sentExchange.getIn().getBody() == body, "Sent body type is the one sent");
receiveResult.assertIsSatisfied(5000);
List<Exchange> receivedExchanges = receiveResult.getExchanges();
- assertNotNull("Received exchanges", receivedExchanges);
+ assertNotNull(receivedExchanges, "Received exchanges");
Exchange receivedExchange = receivedExchanges.get(0);
- assertTrue("Received body is of byte[] type", receivedExchange.getIn().getBody() instanceof byte[]);
+ assertTrue(receivedExchange.getIn().getBody() instanceof byte[], "Received body is of byte[] type");
- assertTrue("Received body equals sent", Arrays.equals(body, (byte[]) receivedExchange.getIn().getBody()));
+ assertTrue(Arrays.equals(body, (byte[]) receivedExchange.getIn().getBody()), "Received body equals sent");
}
@@ -127,25 +131,25 @@ public class BodyTypesTest extends PubsubTestSupport {
producer.send(exchange);
List<Exchange> sentExchanges = sendResult.getExchanges();
- assertEquals("Sent exchanges", 1, sentExchanges.size());
+ assertEquals(1, sentExchanges.size(), "Sent exchanges");
Exchange sentExchange = sentExchanges.get(0);
- assertTrue("Sent body type is byte[]", sentExchange.getIn().getBody() instanceof Map);
+ assertTrue(sentExchange.getIn().getBody() instanceof Map, "Sent body type is byte[]");
receiveResult.assertIsSatisfied(5000);
List<Exchange> receivedExchanges = receiveResult.getExchanges();
- assertNotNull("Received exchanges", receivedExchanges);
+ assertNotNull(receivedExchanges, "Received exchanges");
Exchange receivedExchange = receivedExchanges.get(0);
- assertTrue("Received body is of byte[] type", receivedExchange.getIn().getBody() instanceof byte[]);
+ assertTrue(receivedExchange.getIn().getBody() instanceof byte[], "Received body is of byte[] type");
Object bodyReceived = deserialize((byte[]) receivedExchange.getIn().getBody());
- assertTrue("Received body is a Map ", ((Map) bodyReceived).get("KEY").equals("VALUE1212"));
+ assertTrue(((Map) bodyReceived).get("KEY").equals("VALUE1212"), "Received body is a Map");
}
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java
index a5b98f6..c9a8507 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/GroupedExchangeRoundtripTest.java
@@ -28,7 +28,9 @@ import org.apache.camel.component.google.pubsub.PubsubTestSupport;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy;
import org.apache.camel.support.DefaultExchange;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class GroupedExchangeRoundtripTest extends PubsubTestSupport {
@@ -100,6 +102,6 @@ public class GroupedExchangeRoundtripTest extends PubsubTestSupport {
// Send result section
List<Exchange> results = sendResult.getExchanges();
- assertEquals("Received exchanges", 1, results.size());
+ assertEquals(1, results.size(), "Received exchanges");
}
}
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/SingleExchangeRoundtripTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/SingleExchangeRoundtripTest.java
index 1354fc9..d8e736f 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/SingleExchangeRoundtripTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/integration/SingleExchangeRoundtripTest.java
@@ -30,7 +30,10 @@ import org.apache.camel.component.google.pubsub.GooglePubsubConstants;
import org.apache.camel.component.google.pubsub.PubsubTestSupport;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.support.DefaultExchange;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class SingleExchangeRoundtripTest extends PubsubTestSupport {
@@ -93,24 +96,24 @@ public class SingleExchangeRoundtripTest extends PubsubTestSupport {
producer.send(exchange);
List<Exchange> sentExchanges = sendResult.getExchanges();
- assertEquals("Sent exchanges", 1, sentExchanges.size());
+ assertEquals(1, sentExchanges.size(), "Sent exchanges");
Exchange sentExchange = sentExchanges.get(0);
- assertEquals("Sent ID", exchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID), sentExchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID));
+ assertEquals(exchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID), sentExchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID), "Sent ID");
receiveResult.assertIsSatisfied(5000);
List<Exchange> receivedExchanges = receiveResult.getExchanges();
- assertNotNull("Received exchanges", receivedExchanges);
+ assertNotNull(receivedExchanges, "Received exchanges");
Exchange receivedExchange = receivedExchanges.get(0);
- assertNotNull("PUBSUB Message ID Property", receivedExchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID));
- assertNotNull("PUBSUB Published Time", receivedExchange.getIn().getHeader(GooglePubsubConstants.PUBLISH_TIME));
+ assertNotNull(receivedExchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID), "PUBSUB Message ID Property");
+ assertNotNull(receivedExchange.getIn().getHeader(GooglePubsubConstants.PUBLISH_TIME), "PUBSUB Published Time");
- assertEquals("PUBSUB Header Attribute", attributeValue, ((Map)receivedExchange.getIn().getHeader(GooglePubsubConstants.ATTRIBUTES)).get(attributeKey));
+ assertEquals(attributeValue, ((Map)receivedExchange.getIn().getHeader(GooglePubsubConstants.ATTRIBUTES)).get(attributeKey), "PUBSUB Header Attribute");
assertEquals(sentExchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID), receivedExchange.getIn().getHeader(GooglePubsubConstants.MESSAGE_ID));
}
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubEndpointTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubEndpointTest.java
index 7603998..f0fd7b7 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubEndpointTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubEndpointTest.java
@@ -23,7 +23,11 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.google.pubsub.GooglePubsubConstants;
import org.apache.camel.component.google.pubsub.GooglePubsubEndpoint;
import org.apache.camel.component.google.pubsub.PubsubTestSupport;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class PubsubEndpointTest extends PubsubTestSupport {
@@ -44,7 +48,7 @@ public class PubsubEndpointTest extends PubsubTestSupport {
// :1 identifies the first registered endpoint fo a type in the context
Endpoint endpoint = context.hasEndpoint(String.format("google-pubsub:%s:%s:1", PROJECT_ID, SUBSCRIPTION_URI));
- assertNotNull(String.format("Endpoint 'google-pubsub:%s:%s' is not found in Camel Context", PROJECT_ID, SUBSCRIPTION_URI), endpoint);
+ assertNotNull(endpoint, String.format("Endpoint 'google-pubsub:%s:%s' is not found in Camel Context", PROJECT_ID, SUBSCRIPTION_URI));
assertTrue(endpoint instanceof GooglePubsubEndpoint);
GooglePubsubEndpoint pubsubEndpoint = (GooglePubsubEndpoint)endpoint;
diff --git a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubProducerTest.java b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubProducerTest.java
index bb6ae24..3c7ad79 100644
--- a/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubProducerTest.java
+++ b/components/camel-google-pubsub/src/test/java/org/apache/camel/component/google/pubsub/unit/PubsubProducerTest.java
@@ -22,7 +22,10 @@ import org.apache.camel.Producer;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.google.pubsub.GooglePubsubProducer;
import org.apache.camel.component.google.pubsub.PubsubTestSupport;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class PubsubProducerTest extends PubsubTestSupport {
@@ -38,7 +41,7 @@ public class PubsubProducerTest extends PubsubTestSupport {
public void testProducerConfiguration() throws Exception {
// :1 indicates first of a component type in Camel context
Endpoint endpoint = context.hasEndpoint(String.format("google-pubsub:%s:%s:1", PROJECT_ID, TEST_TOPIC_NAME));
- assertNotNull(String.format("Endpoint 'google-pubsub:%s:$s' is not found in Camel Context", PROJECT_ID, TEST_TOPIC_NAME), endpoint);
+ assertNotNull(endpoint, String.format("Endpoint 'google-pubsub:%s:$s' is not found in Camel Context", PROJECT_ID, TEST_TOPIC_NAME));
Producer producer = endpoint.createProducer();
assertTrue(producer instanceof GooglePubsubProducer);