From a2a378647cfc8a86227b620ad4173fecb99fbc3b Mon Sep 17 00:00:00 2001 From: Otavio Rodolfo Piske Date: Thu, 8 Oct 2020 18:36:45 +0200 Subject: [PATCH] Migrates the camel-aws-sqs integration tests to the shared test infra --- components/camel-aws-sqs/README.md | 35 +++++++++++ components/camel-aws-sqs/pom.xml | 63 +++++++++++++++++++ .../SqsComponentIntegrationTest.java | 31 ++++++--- .../SqsConsumerMessageIntegrationTest.java | 37 ++++++++--- ...sProducerBatchSendFifoIntegrationTest.java | 35 +++++++++-- .../SqsProducerBatchSendIntegrationTest.java | 34 ++++++++-- ...sProducerDeleteMessageIntegrationTest.java | 44 ++++++++++--- .../sqs/integration/TestSqsConfiguration.java | 54 ++++++++++++++++ .../test/infra/aws/common/AWSConfigs.java | 4 +- .../infra/aws/clients/AWSClientUtils.java | 11 ++-- ...ystemPropertiesAWSCredentialsProvider.java | 26 ++++++++ .../infra/aws/common/TestAWSCredentials.java | 42 +++++++++++++ .../common/TestAWSCredentialsProvider.java | 28 --------- .../services/AWSLocalContainerService.java | 17 ++--- .../infra/aws/services/AWSRemoteService.java | 4 +- .../infra/common/SharedNameGenerator.java | 25 ++++++++ .../test/infra/common/SharedNameRegistry.java | 39 ++++++++++++ .../infra/common/TestEntityNameGenerator.java | 41 ++++++++++++ 18 files changed, 493 insertions(+), 77 deletions(-) create mode 100644 components/camel-aws-sqs/README.md create mode 100644 components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/TestSqsConfiguration.java create mode 100644 test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/SystemPropertiesAWSCredentialsProvider.java create mode 100644 test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentials.java create mode 100644 test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameGenerator.java create mode 100644 test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameRegistry.java create mode 100644 test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestEntityNameGenerator.java diff --git a/components/camel-aws-sqs/README.md b/components/camel-aws-sqs/README.md new file mode 100644 index 0000000000000..88b724501846b --- /dev/null +++ b/components/camel-aws-sqs/README.md @@ -0,0 +1,35 @@ +# AWS SQS component for SDK v1 + +# Running the tests + +This component contains integration tests that can be executed against a LocalStack instance, or an actual AWS +instance. The build determines the execution or not of the integration tests automatically by checking the `DOCKER_HOST` +environment variable. If set, then the build will try to execute the integration test. + +*Note*: the `DOCKER_HOST` variable is usually the address of the local unix socket `unix:///var/run/docker.sock`. + +It is possible to run the tests on a remote docker server by overwriting the value of the DOCKER_HOST variable: + + +``` +DOCKER_HOST=tcp://myhost:2375 mvn clean verify +``` + +# Force running the integration tests + +Should you need to force the execution of the integration tests, despite the value of the DOCKER_HOST variable, you can +do so by enabling the `aws-tests-docker-env` profile: + + +``` +mvn -Paws-tests-docker-env clean test verify +``` + +# Running the tests against AWS + +You can define the `aws-service.instance.type`, `aws.access.key` and `aws.secret.key` to switch the test execution from +using LocalStack and, instead, using AWS: + +``` +mvn -Paws-tests-docker-env -Daws-service.instance.type=remote -Daws.access.key=you-access-key -Daws.secret.key=you-secret-key clean test verify +``` \ No newline at end of file diff --git a/components/camel-aws-sqs/pom.xml b/components/camel-aws-sqs/pom.xml index 2995c38b696e2..e945e022169f3 100644 --- a/components/camel-aws-sqs/pom.xml +++ b/components/camel-aws-sqs/pom.xml @@ -46,6 +46,31 @@ ${aws-java-sdk-version} + + + org.apache.camel + camel-test-infra-common + ${project.version} + test-jar + test + + + + org.apache.camel + camel-test-infra-aws-common + ${project.version} + test-jar + test + + + + org.apache.camel + camel-test-infra-aws-v1 + ${project.version} + test-jar + test + + org.junit.jupiter @@ -73,4 +98,42 @@ test + + + + + aws-tests-docker-env + + + env.DOCKER_HOST + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + ${skipTests} + true + + true + + + **/*IntegrationTest.java + + + + + + integration-test + verify + + + + + + + + diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java index 3e6a1e81ef367..5652762de0aec 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsComponentIntegrationTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.aws.sqs.integration; +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.services.sqs.AmazonSQS; import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; @@ -24,18 +26,27 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.aws.sqs.SqsConstants; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.infra.aws.common.SystemPropertiesAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.TestAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.services.AWSService; +import org.apache.camel.test.infra.aws.services.AWSServiceFactory; +import org.apache.camel.test.infra.common.SharedNameGenerator; +import org.apache.camel.test.infra.common.TestEntityNameGenerator; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -@Disabled("Must be manually tested. Provide your own accessKey and secretKey!") public class SqsComponentIntegrationTest extends CamelTestSupport { - private String accessKey = "xxx"; - private String secretKey = "yyy"; + @SuppressWarnings("unused") + @RegisterExtension + public static AWSService service = AWSServiceFactory.createSQSService(); + + @RegisterExtension + public static SharedNameGenerator sharedNameGenerator = new TestEntityNameGenerator(); @EndpointInject("direct:start") private ProducerTemplate template; @@ -93,13 +104,19 @@ public void process(Exchange exchange) throws Exception { @Override protected RouteBuilder createRouteBuilder() throws Exception { + TestAWSCredentialsProvider awsCredentialsProvider = new SystemPropertiesAWSCredentialsProvider(); + AWSCredentials awsCredentials = awsCredentialsProvider.getCredentials(); + final String sqsEndpointUri = String - .format("aws-sqs://MyNewCamelQueue?accessKey=%s&secretKey=%s&messageRetentionPeriod=%s&maximumMessageSize=%s&visibilityTimeout=%s&policy=%s", - accessKey, secretKey, + .format("aws-sqs://%s?accessKey=%s&secretKey=%s&messageRetentionPeriod=%s&maximumMessageSize=%s&visibilityTimeout=%s&policy=%s®ion=US_EAST_1&configuration=%s", + sharedNameGenerator.getName(), + awsCredentials.getAWSAccessKeyId(), + awsCredentials.getAWSSecretKey(), "1209600", "65536", "60", "%7B%22Version%22%3A%222008-10-17%22%2C%22Id%22%3A%22%2F195004372649%2FMyNewCamelQueue%2FSQSDefaultPolicy%22%2C%22" + "Statement%22%3A%5B%7B%22Sid%22%3A%22Queue1ReceiveMessage%22%2C%22Effect%22%3A%22Allow%22%2C%22Principal%22%3A%7B%22AWS%22%3A%22*%22%7D%2C%22" - + "Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyNewCamelQueue%22%7D%5D%7D"); + + "Action%22%3A%22SQS%3AReceiveMessage%22%2C%22Resource%22%3A%22%2F195004372649%2FMyNewCamelQueue%22%7D%5D%7D", + "#class:" + TestSqsConfiguration.class.getName()); return new RouteBuilder() { @Override diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java index 8ce1abcd135c9..d0c0c4c028ac7 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsConsumerMessageIntegrationTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.aws.sqs.integration; +import com.amazonaws.services.sqs.AmazonSQS; import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; @@ -23,13 +24,25 @@ import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.infra.aws.common.SystemPropertiesAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.TestAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.services.AWSService; +import org.apache.camel.test.infra.aws.services.AWSServiceFactory; +import org.apache.camel.test.infra.common.SharedNameGenerator; +import org.apache.camel.test.infra.common.TestEntityNameGenerator; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -@Disabled("Must be manually tested. Provide your own accessKey and secretKey!") public class SqsConsumerMessageIntegrationTest extends CamelTestSupport { + @SuppressWarnings("unused") + @RegisterExtension + public static AWSService service = AWSServiceFactory.createSQSService(); + + @RegisterExtension + public static SharedNameGenerator sharedNameGenerator = new TestEntityNameGenerator(); + @EndpointInject("direct:start") private ProducerTemplate template; @@ -57,18 +70,28 @@ public void process(Exchange exchange) throws Exception { @Override protected RouteBuilder createRouteBuilder() throws Exception { + TestAWSCredentialsProvider awsCredentialsProvider = new SystemPropertiesAWSCredentialsProvider(); + final String sqsEndpointUri - = String.format("aws-sqs://camel-1?accessKey=RAW(xxxx)&secretKey=RAW(xxxx)®ion=EU_WEST_1"); + = String.format("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()); return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").startupOrder(2).to(sqsEndpointUri); - from("aws-sqs://camel-1?accessKey=RAW(xxxx)&secretKey=RAW(xxxx)®ion=EU_WEST_1&deleteAfterRead=false&deleteIfFiltered=true") - .startupOrder(1) - .filter(simple("${body} != 'ignore'")).log("${body}").log("${header.CamelAwsSqsReceiptHandle}") - .to("mock:result"); + fromF("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&deleteAfterRead=false&deleteIfFiltered=true&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()) + .startupOrder(1) + .filter(simple("${body} != 'ignore'")).log("${body}").log("${header.CamelAwsSqsReceiptHandle}") + .to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java index ff9faf5d2f8ee..684d7a6c47e48 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendFifoIntegrationTest.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collection; +import com.amazonaws.services.sqs.AmazonSQS; import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; @@ -27,13 +28,25 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.aws.sqs.SqsConstants; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.infra.aws.common.SystemPropertiesAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.TestAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.services.AWSService; +import org.apache.camel.test.infra.aws.services.AWSServiceFactory; +import org.apache.camel.test.infra.common.SharedNameGenerator; +import org.apache.camel.test.infra.common.TestEntityNameGenerator; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -@Disabled("Must be manually tested. Provide your own accessKey and secretKey!") public class SqsProducerBatchSendFifoIntegrationTest extends CamelTestSupport { + @SuppressWarnings("unused") + @RegisterExtension + public static AWSService service = AWSServiceFactory.createSQSService(); + + @RegisterExtension + public static SharedNameGenerator sharedNameGenerator = new TestEntityNameGenerator(); + @EndpointInject("direct:start") private ProducerTemplate template; @@ -61,9 +74,15 @@ public void process(Exchange exchange) throws Exception { @Override protected RouteBuilder createRouteBuilder() throws Exception { + TestAWSCredentialsProvider awsCredentialsProvider = new SystemPropertiesAWSCredentialsProvider(); + final String sqsEndpointUri = String.format( - "aws-sqs://camel-1.fifo?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&messageGroupIdStrategy=useExchangeId" - + "&messageDeduplicationIdStrategy=useContentBasedDeduplication"); + "aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&messageGroupIdStrategy=useExchangeId" + + "&messageDeduplicationIdStrategy=useContentBasedDeduplication&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()); return new RouteBuilder() { @Override @@ -71,8 +90,12 @@ public void configure() throws Exception { from("direct:start").startupOrder(2).setHeader(SqsConstants.SQS_OPERATION, constant("sendBatchMessage")) .to(sqsEndpointUri); - from("aws-sqs://camel-1.fifo?accessKey=RAW(xxx)&secretKey=RAW(xxxx)®ion=EU_WEST_1&deleteAfterRead=false") - .startupOrder(1).log("${body}").to("mock:result"); + fromF("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&deleteAfterRead=false&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()) + .startupOrder(1).log("${body}").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendIntegrationTest.java index 76288503a1bff..4a2f73523c3c3 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerBatchSendIntegrationTest.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collection; +import com.amazonaws.services.sqs.AmazonSQS; import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; @@ -27,13 +28,25 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.aws.sqs.SqsConstants; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.infra.aws.common.SystemPropertiesAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.TestAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.services.AWSService; +import org.apache.camel.test.infra.aws.services.AWSServiceFactory; +import org.apache.camel.test.infra.common.SharedNameGenerator; +import org.apache.camel.test.infra.common.TestEntityNameGenerator; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -@Disabled("Must be manually tested. Provide your own accessKey and secretKey!") public class SqsProducerBatchSendIntegrationTest extends CamelTestSupport { + @SuppressWarnings("unused") + @RegisterExtension + public static AWSService service = AWSServiceFactory.createSQSService(); + + @RegisterExtension + public static SharedNameGenerator sharedNameGenerator = new TestEntityNameGenerator(); + @EndpointInject("direct:start") private ProducerTemplate template; @@ -61,7 +74,14 @@ public void process(Exchange exchange) throws Exception { @Override protected RouteBuilder createRouteBuilder() throws Exception { - final String sqsEndpointUri = String.format("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1"); + TestAWSCredentialsProvider awsCredentialsProvider = new SystemPropertiesAWSCredentialsProvider(); + + final String sqsEndpointUri + = String.format("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()); return new RouteBuilder() { @Override @@ -69,8 +89,12 @@ public void configure() throws Exception { from("direct:start").startupOrder(2).setHeader(SqsConstants.SQS_OPERATION, constant("sendBatchMessage")) .to(sqsEndpointUri); - from("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&deleteAfterRead=true") - .startupOrder(1).log("${body}").to("mock:result"); + fromF("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&deleteAfterRead=true&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()) + .startupOrder(1).log("${body}").to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java index a457402593be4..6f1af714ea0e1 100644 --- a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/SqsProducerDeleteMessageIntegrationTest.java @@ -16,6 +16,7 @@ */ package org.apache.camel.component.aws.sqs.integration; +import com.amazonaws.services.sqs.AmazonSQS; import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; @@ -23,13 +24,25 @@ import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.infra.aws.common.SystemPropertiesAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.TestAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.services.AWSService; +import org.apache.camel.test.infra.aws.services.AWSServiceFactory; +import org.apache.camel.test.infra.common.SharedNameGenerator; +import org.apache.camel.test.infra.common.TestEntityNameGenerator; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -@Disabled("Must be manually tested. Provide your own accessKey and secretKey!") public class SqsProducerDeleteMessageIntegrationTest extends CamelTestSupport { + @SuppressWarnings("unused") + @RegisterExtension + public static AWSService service = AWSServiceFactory.createSQSService(); + + @RegisterExtension + public static SharedNameGenerator sharedNameGenerator = new TestEntityNameGenerator(); + @EndpointInject("direct:start") private ProducerTemplate template; @@ -51,18 +64,33 @@ public void process(Exchange exchange) throws Exception { @Override protected RouteBuilder createRouteBuilder() throws Exception { - final String sqsEndpointUri = String.format("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1"); + TestAWSCredentialsProvider awsCredentialsProvider = new SystemPropertiesAWSCredentialsProvider(); + + final String sqsEndpointUri + = String.format("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()); return new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").startupOrder(2).to(sqsEndpointUri); - from("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&deleteAfterRead=false") - .startupOrder(1).log("${body}") - .to("aws-sqs://camel-1?accessKey=RAW(xxx)&secretKey=RAW(xxx)®ion=EU_WEST_1&operation=deleteMessage") - .log("${body}").log("${header.CamelAwsSqsReceiptHandle}") - .to("mock:result"); + fromF("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&deleteAfterRead=false&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()) + .startupOrder(1).log("${body}") + .toF("aws-sqs://%s?accessKey=RAW(%s)&secretKey=RAW(%s)®ion=EU_WEST_1&operation=deleteMessage&configuration=#class:%s", + sharedNameGenerator.getName(), + awsCredentialsProvider.getCredentials().getAWSAccessKeyId(), + awsCredentialsProvider.getCredentials().getAWSSecretKey(), + TestSqsConfiguration.class.getName()) + .log("${body}").log("${header.CamelAwsSqsReceiptHandle}") + .to("mock:result"); } }; } diff --git a/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/TestSqsConfiguration.java b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/TestSqsConfiguration.java new file mode 100644 index 0000000000000..7bae0b7a80b12 --- /dev/null +++ b/components/camel-aws-sqs/src/test/java/org/apache/camel/component/aws/sqs/integration/TestSqsConfiguration.java @@ -0,0 +1,54 @@ +/* + * 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.aws.sqs.integration; + +import com.amazonaws.services.sqs.AmazonSQS; +import com.amazonaws.services.sqs.model.QueueDoesNotExistException; +import org.apache.camel.component.aws.sqs.SqsConfiguration; +import org.apache.camel.test.infra.aws.clients.AWSClientUtils; +import org.apache.camel.test.infra.common.SharedNameGenerator; +import org.apache.camel.test.infra.common.SharedNameRegistry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestSqsConfiguration extends SqsConfiguration { + private static final Logger LOG = LoggerFactory.getLogger(TestSqsConfiguration.class); + private final AmazonSQS client = AWSClientUtils.newSQSClient(); + + public TestSqsConfiguration() { + SharedNameGenerator sharedNameGenerator = SharedNameRegistry.getInstance().getSharedNameGenerator(); + + String name = sharedNameGenerator.getName(); + LOG.debug("Using the following shared resource name for the test: {}", name); + setQueueName(name); + } + + @Override + public String getQueueUrl() { + try { + return client.getQueueUrl(getQueueName()).getQueueUrl(); + } catch (QueueDoesNotExistException e) { + return client.createQueue(getQueueName()).getQueueUrl(); + } + } + + @Override + public AmazonSQS getAmazonSQSClient() { + return client; + } +} diff --git a/test-infra/camel-test-infra-aws-common/src/test/java/org/apache/camel/test/infra/aws/common/AWSConfigs.java b/test-infra/camel-test-infra-aws-common/src/test/java/org/apache/camel/test/infra/aws/common/AWSConfigs.java index c9503ea6f83f1..5a17902c7d521 100644 --- a/test-infra/camel-test-infra-aws-common/src/test/java/org/apache/camel/test/infra/aws/common/AWSConfigs.java +++ b/test-infra/camel-test-infra-aws-common/src/test/java/org/apache/camel/test/infra/aws/common/AWSConfigs.java @@ -17,8 +17,8 @@ package org.apache.camel.test.infra.aws.common; public final class AWSConfigs { - public static final String ACCESS_KEY = "access.key"; - public static final String SECRET_KEY = "secret.key"; + public static final String ACCESS_KEY = "aws.access.key"; + public static final String SECRET_KEY = "aws.secret.key"; public static final String REGION = "aws.region"; public static final String AMAZON_AWS_HOST = "aws.host"; public static final String PROTOCOL = "aws.protocol"; diff --git a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/clients/AWSClientUtils.java b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/clients/AWSClientUtils.java index 8b0094ec251e4..c80b5c6d38dd6 100644 --- a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/clients/AWSClientUtils.java +++ b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/clients/AWSClientUtils.java @@ -30,6 +30,7 @@ import com.amazonaws.services.sqs.AmazonSQS; import com.amazonaws.services.sqs.AmazonSQSClientBuilder; import org.apache.camel.test.infra.aws.common.AWSConfigs; +import org.apache.camel.test.infra.aws.common.SystemPropertiesAWSCredentialsProvider; import org.apache.camel.test.infra.aws.common.TestAWSCredentialsProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,7 +75,7 @@ public static AmazonSNS newSNSClient() { } else { clientBuilder .withRegion(region) - .withCredentials(new TestAWSCredentialsProvider()); + .withCredentials(new SystemPropertiesAWSCredentialsProvider()); } return clientBuilder.build(); @@ -87,9 +88,11 @@ public static AmazonSQS newSQSClient() { String awsInstanceType = System.getProperty("aws-service.instance.type"); String region = getRegion(); + LOG.debug("Using amazon region: {}", region); if (awsInstanceType == null || awsInstanceType.equals("local-aws-container")) { String amazonHost = System.getProperty(AWSConfigs.AMAZON_AWS_HOST); + LOG.debug("Using amazon host: {}", amazonHost); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProtocol(Protocol.HTTP); @@ -101,7 +104,7 @@ public static AmazonSQS newSQSClient() { } else { clientBuilder .withRegion(region) - .withCredentials(new TestAWSCredentialsProvider()); + .withCredentials(new SystemPropertiesAWSCredentialsProvider()); } return clientBuilder.build(); @@ -126,7 +129,7 @@ public static AmazonS3 newS3Client() { } else { clientBuilder .withRegion(region) - .withCredentials(new TestAWSCredentialsProvider()); + .withCredentials(new SystemPropertiesAWSCredentialsProvider()); } clientBuilder @@ -157,7 +160,7 @@ public static AmazonKinesis newKinesisClient() { } else { clientBuilder .withRegion(region) - .withCredentials(new TestAWSCredentialsProvider()); + .withCredentials(new SystemPropertiesAWSCredentialsProvider()); } return clientBuilder.build(); diff --git a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/SystemPropertiesAWSCredentialsProvider.java b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/SystemPropertiesAWSCredentialsProvider.java new file mode 100644 index 0000000000000..88ab1f69a0a17 --- /dev/null +++ b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/SystemPropertiesAWSCredentialsProvider.java @@ -0,0 +1,26 @@ +/* + * 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.test.infra.aws.common; + +public class SystemPropertiesAWSCredentialsProvider extends TestAWSCredentialsProvider { + + public SystemPropertiesAWSCredentialsProvider() { + super(System.getProperty(AWSConfigs.ACCESS_KEY), System.getProperty(AWSConfigs.SECRET_KEY)); + } + +} diff --git a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentials.java b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentials.java new file mode 100644 index 0000000000000..e5d77c1e80815 --- /dev/null +++ b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentials.java @@ -0,0 +1,42 @@ +/* + * 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.test.infra.aws.common; + +import java.util.Objects; + +import com.amazonaws.auth.AWSCredentials; + +public class TestAWSCredentials implements AWSCredentials { + private final String accessKey; + private final String secretKey; + + public TestAWSCredentials(String accessKey, String secretKey) { + this.accessKey = Objects.requireNonNull(accessKey); + this.secretKey = Objects.requireNonNull(secretKey); + } + + @Override + public String getAWSAccessKeyId() { + return accessKey; + } + + @Override + public String getAWSSecretKey() { + return secretKey; + } +}; diff --git a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentialsProvider.java b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentialsProvider.java index dcfba3dc9e166..d4c1d97ad261f 100644 --- a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentialsProvider.java +++ b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/common/TestAWSCredentialsProvider.java @@ -20,36 +20,8 @@ import com.amazonaws.auth.AWSCredentialsProvider; public class TestAWSCredentialsProvider implements AWSCredentialsProvider { - private static class TestAWSCredentials implements AWSCredentials { - private final String accessKey; - private final String secretKey; - - public TestAWSCredentials() { - this(System.getProperty(AWSConfigs.ACCESS_KEY), System.getProperty(AWSConfigs.SECRET_KEY)); - } - - public TestAWSCredentials(String accessKey, String secretKey) { - this.accessKey = accessKey; - this.secretKey = secretKey; - } - - @Override - public String getAWSAccessKeyId() { - return accessKey; - } - - @Override - public String getAWSSecretKey() { - return secretKey; - } - }; - private AWSCredentials credentials; - public TestAWSCredentialsProvider() { - credentials = new TestAWSCredentials(); - } - public TestAWSCredentialsProvider(String accessKey, String secretKey) { credentials = new TestAWSCredentials(accessKey, secretKey); } diff --git a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSLocalContainerService.java b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSLocalContainerService.java index 16a08fe186114..6460921ee1691 100644 --- a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSLocalContainerService.java +++ b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSLocalContainerService.java @@ -43,6 +43,7 @@ public AWSLocalContainerService(LocalStackContainer.Service... services) { @Override public void initialize() { + getConnectionProperties(); LOG.info("AWS service running at address {}", getServiceEndpoint()); } @@ -63,24 +64,24 @@ public Properties getConnectionProperties() { AWSCredentials credentials = getCredentials(); properties.put(AWSConfigs.ACCESS_KEY, credentials.getAWSAccessKeyId()); - properties.put(AWSConfigs.SECRET_KEY, credentials.getAWSSecretKey()); - properties.put(AWSConfigs.REGION, Regions.US_EAST_1.name()); - properties.put(AWSConfigs.AMAZON_AWS_HOST, getAmazonHost()); + properties.put(AWSConfigs.PROTOCOL, "http"); /** * We need to set this one. For some sets, when they instantiate the clients within Camel, they need to know - * what is the Amazon host being used (ie.: when creating them using the withEndpointConfiguration()). Because - * this happens within Camel, there's no way to pass that information easily. Therefore, the host is set as a - * property and read by whatever class/method creates the clients to pass to Camel. + * what is the Amazon details being used (ie.: when creating them using the withEndpointConfiguration()). + * Because this happens within Camel, there's no way to pass that information easily. Therefore, the information + * is set as a property and read by whatever class/method creates the clients to pass to Camel. * * Do not unset. */ + System.setProperty(AWSConfigs.SECRET_KEY, credentials.getAWSSecretKey()); + System.setProperty(AWSConfigs.ACCESS_KEY, credentials.getAWSAccessKeyId()); System.setProperty(AWSConfigs.AMAZON_AWS_HOST, getAmazonHost()); - - properties.put(AWSConfigs.PROTOCOL, "http"); + System.setProperty(AWSConfigs.REGION, Regions.US_EAST_1.name()); + System.setProperty(AWSConfigs.PROTOCOL, "http"); return properties; } diff --git a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSRemoteService.java b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSRemoteService.java index db499ecbcf8b3..a889d52863c52 100644 --- a/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSRemoteService.java +++ b/test-infra/camel-test-infra-aws-v1/src/test/java/org/apache/camel/test/infra/aws/services/AWSRemoteService.java @@ -24,11 +24,11 @@ import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.regions.Regions; import org.apache.camel.test.infra.aws.common.AWSConfigs; -import org.apache.camel.test.infra.aws.common.TestAWSCredentialsProvider; +import org.apache.camel.test.infra.aws.common.SystemPropertiesAWSCredentialsProvider; import org.apache.camel.test.infra.aws.common.services.AWSService; public class AWSRemoteService implements AWSService { - private static final AWSCredentialsProvider CREDENTIALS_PROVIDER = new TestAWSCredentialsProvider(); + private static final AWSCredentialsProvider CREDENTIALS_PROVIDER = new SystemPropertiesAWSCredentialsProvider(); private Supplier remoteClientSupplier; public AWSRemoteService(Supplier remoteClientSupplier) { diff --git a/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameGenerator.java b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameGenerator.java new file mode 100644 index 0000000000000..5e7af4be7a215 --- /dev/null +++ b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameGenerator.java @@ -0,0 +1,25 @@ +/* + * 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.test.infra.common; + +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; + +public interface SharedNameGenerator extends BeforeAllCallback, BeforeEachCallback { + String getName(); +} diff --git a/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameRegistry.java b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameRegistry.java new file mode 100644 index 0000000000000..9113dc1df153d --- /dev/null +++ b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/SharedNameRegistry.java @@ -0,0 +1,39 @@ +/* + * 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.test.infra.common; + +public class SharedNameRegistry { + private static SharedNameRegistry instance; + private SharedNameGenerator sharedNameGenerator; + + public SharedNameGenerator getSharedNameGenerator() { + return sharedNameGenerator; + } + + public void setSharedNameGenerator(SharedNameGenerator sharedNameGenerator) { + this.sharedNameGenerator = sharedNameGenerator; + } + + public static synchronized SharedNameRegistry getInstance() { + if (instance == null) { + instance = new SharedNameRegistry(); + } + + return instance; + } +} diff --git a/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestEntityNameGenerator.java b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestEntityNameGenerator.java new file mode 100644 index 0000000000000..dca6388c5e53d --- /dev/null +++ b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/TestEntityNameGenerator.java @@ -0,0 +1,41 @@ +/* + * 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.test.infra.common; + +import org.junit.jupiter.api.extension.ExtensionContext; + +public class TestEntityNameGenerator implements SharedNameGenerator { + private String testClass; + private String testName; + + @Override + public void beforeAll(ExtensionContext context) throws Exception { + testClass = context.getTestClass().get().getSimpleName(); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + testName = context.getTestMethod().get().getName(); + + SharedNameRegistry.getInstance().setSharedNameGenerator(this); + } + + public String getName() { + return testClass + testName; + } +}