You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2020/11/10 15:56:54 UTC

[camel] branch master updated: Migrates the AWS v2 SNS tests to the new test-infra (#4590)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 3132254  Migrates the AWS v2 SNS tests to the new test-infra (#4590)
3132254 is described below

commit 313225456d9fe7e6ed7cb6fb9aae455342691798
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Tue Nov 10 16:45:19 2020 +0100

    Migrates the AWS v2 SNS tests to the new test-infra (#4590)
---
 components/camel-aws2-sns/pom.xml                  | 30 ++++++++++--
 .../aws2/sns/localstack/Aws2SNSBaseTest.java       | 54 ++++------------------
 .../localstack/SnsTopicProducerLocalstackTest.java |  8 +++-
 3 files changed, 42 insertions(+), 50 deletions(-)

diff --git a/components/camel-aws2-sns/pom.xml b/components/camel-aws2-sns/pom.xml
index 8745a198..97768f9 100644
--- a/components/camel-aws2-sns/pom.xml
+++ b/components/camel-aws2-sns/pom.xml
@@ -56,6 +56,31 @@
             <version>${aws-java-sdk2-version}</version>
         </dependency>
 
+        <!-- test infra -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-common</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-aws-common</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-aws-v2</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+
         <!-- for testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
@@ -82,11 +107,6 @@
             <artifactId>hamcrest</artifactId>
             <scope>test</scope>
         </dependency>
-       <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-testcontainers-junit5</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <profiles>
diff --git a/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/Aws2SNSBaseTest.java b/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/Aws2SNSBaseTest.java
index 78d7984..e8a5327 100644
--- a/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/Aws2SNSBaseTest.java
+++ b/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/Aws2SNSBaseTest.java
@@ -16,61 +16,27 @@
  */
 package org.apache.camel.component.aws2.sns.localstack;
 
-import java.net.URI;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.aws2.sns.Sns2Component;
-import org.apache.camel.test.testcontainers.junit5.ContainerAwareTestSupport;
-import org.apache.camel.test.testcontainers.junit5.Wait;
+import org.apache.camel.test.infra.aws.common.services.AWSService;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.apache.camel.test.infra.aws2.services.AWSServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
 import org.junit.jupiter.api.TestInstance;
-import org.testcontainers.containers.GenericContainer;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.sns.SnsClient;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import software.amazon.awssdk.services.sqs.SqsClient;
 
 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
-public class Aws2SNSBaseTest extends ContainerAwareTestSupport {
-
-    public static final String CONTAINER_IMAGE = "localstack/localstack:0.12.1";
-    public static final String CONTAINER_NAME = "sns";
-
-    @Override
-    protected GenericContainer<?> createContainer() {
-        return localstackContainer();
-    }
+public class Aws2SNSBaseTest extends CamelTestSupport {
 
-    public static GenericContainer localstackContainer() {
-        return new GenericContainer(CONTAINER_IMAGE)
-                .withNetworkAliases(CONTAINER_NAME)
-                .withEnv("SERVICES", "sns")
-                .withExposedPorts(4566)
-                .waitingFor(Wait.forListeningPort())
-                .waitingFor(Wait.forLogMessageContaining("Ready.", 1));
-    }
-
-    public String getS3Url() {
-        return String.format(
-                "%s:%d",
-                getContainerHost(CONTAINER_NAME),
-                getContainerPort(CONTAINER_NAME, 4566));
-    }
-
-    public SnsClient getSNSClient() {
-        SnsClient snsClient = SnsClient
-                .builder()
-                .endpointOverride(URI.create("http://" + getS3Url()))
-                .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxx", "yyy")))
-                .region(Region.EU_WEST_1)
-                .build();
-        return snsClient;
-    }
+    @RegisterExtension
+    public static AWSService<SqsClient> service = AWSServiceFactory.createSNSService();
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
         Sns2Component sqs = context.getComponent("aws2-sns", Sns2Component.class);
-        sqs.getConfiguration().setAmazonSNSClient(getSNSClient());
+        sqs.getConfiguration().setAmazonSNSClient(AWSSDKClientUtils.newSNSClient());
         return context;
     }
 }
diff --git a/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/SnsTopicProducerLocalstackTest.java b/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/SnsTopicProducerLocalstackTest.java
index 8058711..d190aec 100644
--- a/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/SnsTopicProducerLocalstackTest.java
+++ b/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/SnsTopicProducerLocalstackTest.java
@@ -21,12 +21,18 @@ import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.aws2.sns.Sns2Constants;
+import org.apache.camel.test.infra.common.SharedNameGenerator;
+import org.apache.camel.test.infra.common.TestEntityNameGenerator;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class SnsTopicProducerLocalstackTest extends Aws2SNSBaseTest {
 
+    @RegisterExtension
+    public static SharedNameGenerator sharedNameGenerator = new TestEntityNameGenerator();
+
     @Test
     public void sendInOnly() throws Exception {
         Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() {
@@ -57,7 +63,7 @@ public class SnsTopicProducerLocalstackTest extends Aws2SNSBaseTest {
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                        .to("aws2-sns://MyNewTopic1?subject=The+subject+message");
+                        .toF("aws2-sns://%s?subject=The+subject+message", sharedNameGenerator.getName());
             }
         };
     }