You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/09/11 12:49:51 UTC
[camel] branch master updated: Camel-AWS2-SNS: Adding tests with
localstack and Testcontainers
This is an automated email from the ASF dual-hosted git repository.
acosentino 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 2e098fa Camel-AWS2-SNS: Adding tests with localstack and Testcontainers
2e098fa is described below
commit 2e098fa7969adbc72c5ff69d650426f3ad650043
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 11 14:43:41 2020 +0200
Camel-AWS2-SNS: Adding tests with localstack and Testcontainers
---
components/camel-aws2-sns/pom.xml | 70 ++++++++++++++++++++
.../aws2/sns/localstack/Aws2SNSBaseTest.java | 76 ++++++++++++++++++++++
.../localstack/SnsTopicProducerLocalstackTest.java | 64 ++++++++++++++++++
3 files changed, 210 insertions(+)
diff --git a/components/camel-aws2-sns/pom.xml b/components/camel-aws2-sns/pom.xml
index 43af404..02c3d6f 100644
--- a/components/camel-aws2-sns/pom.xml
+++ b/components/camel-aws2-sns/pom.xml
@@ -77,5 +77,75 @@
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-testcontainers-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
+
+ <profiles>
+ <profile>
+ <id>aws2-sns-skip-tests</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>true</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <!-- activate test if the docker socket file is accessible -->
+ <profile>
+ <id>aws2-sns-tests-docker-file</id>
+ <activation>
+ <file>
+ <exists>/var/run/docker.sock</exists>
+ </file>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <visibleassertions.silence>true</visibleassertions.silence>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <!-- activate test if the DOCKER_HOST env var is set -->
+ <profile>
+ <id>aws2-sns-tests-docker-env</id>
+ <activation>
+ <property>
+ <name>env.DOCKER_HOST</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>${skipTests}</skipTests>
+ <systemPropertyVariables>
+ <visibleassertions.silence>true</visibleassertions.silence>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
</project>
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
new file mode 100644
index 0000000..94c5ec5
--- /dev/null
+++ b/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/Aws2SNSBaseTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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.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;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Aws2SNSBaseTest extends ContainerAwareTestSupport {
+
+ public static final String CONTAINER_IMAGE = "localstack/localstack:0.11.4";
+ public static final String CONTAINER_NAME = "sns";
+
+ @Override
+ protected GenericContainer<?> createContainer() {
+ return localstackContainer();
+ }
+
+ 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 sqsClient = SnsClient
+ .builder()
+ .endpointOverride(URI.create("http://" + getS3Url()))
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxx", "yyy")))
+ .region(Region.EU_WEST_1)
+ .build();
+ return sqsClient;
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ Sns2Component sqs = context.getComponent("aws2-sns", Sns2Component.class);
+ sqs.getConfiguration().setAmazonSNSClient(getSNSClient());
+ 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
new file mode 100644
index 0000000..8058711
--- /dev/null
+++ b/components/camel-aws2-sns/src/test/java/org/apache/camel/component/aws2/sns/localstack/SnsTopicProducerLocalstackTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws2.sns.localstack;
+
+import org.apache.camel.Exchange;
+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.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+public class SnsTopicProducerLocalstackTest extends Aws2SNSBaseTest {
+
+ @Test
+ public void sendInOnly() throws Exception {
+ Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(Sns2Constants.SUBJECT, "This is my subject");
+ exchange.getIn().setBody("This is my message text.");
+ }
+ });
+
+ assertNotNull(exchange.getIn().getHeader(Sns2Constants.MESSAGE_ID));
+ }
+
+ @Test
+ public void sendInOut() throws Exception {
+ Exchange exchange = template.send("direct:start", ExchangePattern.InOut, new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(Sns2Constants.SUBJECT, "This is my subject");
+ exchange.getIn().setBody("This is my message text.");
+ }
+ });
+
+ assertNotNull(exchange.getMessage().getHeader(Sns2Constants.MESSAGE_ID));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .to("aws2-sns://MyNewTopic1?subject=The+subject+message");
+ }
+ };
+ }
+}