[camel] branch master updated: Migrates the camel-aws2-lambda tests to the shared test infra (#4648)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: Migrates the camel-aws2-lambda tests to the shared test infra (#4648)

orpiske
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 041fb57  Migrates the camel-aws2-lambda tests to the shared test infra (#4648)
041fb57 is described below

commit 041fb57428642fa05ef7c9ffeb3d4ea2910409db
Author: Otavio Rodolfo Piske <[hidden email]>
AuthorDate: Fri Nov 20 17:06:30 2020 +0100

    Migrates the camel-aws2-lambda tests to the shared test infra (#4648)
---
 components/camel-aws2-lambda/pom.xml               | 22 ++++++++-
 .../aws2/lambda/localstack/Aws2LambdaBaseTest.java | 54 ++++------------------
 test-infra/camel-test-infra-aws-v2/pom.xml         |  6 +++
 .../test/infra/aws2/clients/AWSSDKClientUtils.java |  5 ++
 ...ce.java => AWSLambdaLocalContainerService.java} | 25 ++--------
 .../infra/aws2/services/AWSServiceFactory.java     |  4 ++
 .../camel/test/infra/aws2/services/Service.java    |  1 +
 7 files changed, 49 insertions(+), 68 deletions(-)

diff --git a/components/camel-aws2-lambda/pom.xml b/components/camel-aws2-lambda/pom.xml
index 956e28d..f18db4b 100644
--- a/components/camel-aws2-lambda/pom.xml
+++ b/components/camel-aws2-lambda/pom.xml
@@ -67,9 +67,29 @@
             <artifactId>log4j-slf4j-impl</artifactId>
             <scope>test</scope>
         </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-testcontainers-junit5</artifactId>
+            <artifactId>camel-test-infra-aws-v2</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/components/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/localstack/Aws2LambdaBaseTest.java b/components/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/localstack/Aws2LambdaBaseTest.java
index 5c810f0..9a0c37f 100644
--- a/components/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/localstack/Aws2LambdaBaseTest.java
+++ b/components/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/localstack/Aws2LambdaBaseTest.java
@@ -16,61 +16,25 @@
  */
 package org.apache.camel.component.aws2.lambda.localstack;
 
-import java.net.URI;
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.aws2.lambda.Lambda2Component;
-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.lambda.LambdaClient;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 @TestInstance(TestInstance.Lifecycle.PER_CLASS)
-public class Aws2LambdaBaseTest extends ContainerAwareTestSupport {
-
-    public static final String CONTAINER_IMAGE = "localstack/localstack:0.12.2";
-    public static final String CONTAINER_NAME = "lambda";
-
-    @Override
-    protected GenericContainer<?> createContainer() {
-        return localstackContainer();
-    }
-
-    public static GenericContainer localstackContainer() {
-        return new GenericContainer(CONTAINER_IMAGE)
-                .withNetworkAliases(CONTAINER_NAME)
-                .withEnv("SERVICES", "lambda")
-                .withExposedPorts(4566)
-                .waitingFor(Wait.forListeningPort())
-                .waitingFor(Wait.forLogMessageContaining("Ready.", 1));
-    }
-
-    public String getEventbridgeUrl() {
-        return String.format(
-                "%s:%d",
-                getContainerHost(CONTAINER_NAME),
-                getContainerPort(CONTAINER_NAME, 4566));
-    }
-
-    public LambdaClient getLambdaClient() {
-        LambdaClient lambdaClient = LambdaClient
-                .builder()
-                .endpointOverride(URI.create("http://" + getEventbridgeUrl()))
-                .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("xxx", "yyy")))
-                .region(Region.EU_WEST_1)
-                .build();
-        return lambdaClient;
-    }
+public class Aws2LambdaBaseTest extends CamelTestSupport {
+    @RegisterExtension
+    public static AWSService service = AWSServiceFactory.createLambdaService();
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
         Lambda2Component lambdaComponent = context.getComponent("aws2-lambda", Lambda2Component.class);
-        lambdaComponent.getConfiguration().setAwsLambdaClient(getLambdaClient());
+        lambdaComponent.getConfiguration().setAwsLambdaClient(AWSSDKClientUtils.newLambdaClient());
         return context;
     }
 }
diff --git a/test-infra/camel-test-infra-aws-v2/pom.xml b/test-infra/camel-test-infra-aws-v2/pom.xml
index 3ade9bf..ac8defe 100644
--- a/test-infra/camel-test-infra-aws-v2/pom.xml
+++ b/test-infra/camel-test-infra-aws-v2/pom.xml
@@ -108,6 +108,12 @@
 
         <dependency>
             <groupId>software.amazon.awssdk</groupId>
+            <artifactId>lambda</artifactId>
+            <version>${aws-java-sdk2-version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>software.amazon.awssdk</groupId>
             <artifactId>apache-client</artifactId>
             <version>${aws-java-sdk2-version}</version>
         </dependency>
diff --git a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/clients/AWSSDKClientUtils.java b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/clients/AWSSDKClientUtils.java
index 83902ce..cd3f3ee 100644
--- a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/clients/AWSSDKClientUtils.java
+++ b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/clients/AWSSDKClientUtils.java
@@ -35,6 +35,7 @@ import software.amazon.awssdk.services.eventbridge.EventBridgeClient;
 import software.amazon.awssdk.services.iam.IamClient;
 import software.amazon.awssdk.services.kinesis.KinesisClient;
 import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.lambda.LambdaClient;
 import software.amazon.awssdk.services.s3.S3Client;
 import software.amazon.awssdk.services.sns.SnsClient;
 import software.amazon.awssdk.services.sqs.SqsClient;
@@ -159,4 +160,8 @@ public final class AWSSDKClientUtils {
     public static KmsClient newKMSClient() {
         return newClient("KMS", KmsClient::builder, KmsClient.class);
     }
+
+    public static LambdaClient newLambdaClient() {
+        return newClient("Lambda", LambdaClient::builder, LambdaClient.class);
+    }
 }
diff --git a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/Service.java b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSLambdaLocalContainerService.java
similarity index 63%
copy from test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/Service.java
copy to test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSLambdaLocalContainerService.java
index dbe391f..c6bfcc0 100644
--- a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/Service.java
+++ b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSLambdaLocalContainerService.java
@@ -17,28 +17,9 @@
 
 package org.apache.camel.test.infra.aws2.services;
 
-public enum Service {
-    CLOUD_WATCH("cloudwatch"),
-    EC2("ec2"),
-    EVENT_BRIDGE("eventbridge"),
-    IAM("iam"),
-    KINESIS("kinesis"),
-    KMS("kms"),
-    S3("s3"),
-    SQS("sqs"),
-    SNS("sns");
-
-    private final String serviceName;
-
-    Service(String serviceName) {
-        this.serviceName = serviceName;
+public class AWSLambdaLocalContainerService extends AWSLocalContainerService {
+    public AWSLambdaLocalContainerService() {
+        super(Service.LAMBDA);
     }
 
-    public String getServiceName() {
-        return serviceName;
-    }
-
-    public static String serviceName(Service service) {
-        return service.serviceName;
-    }
 }
diff --git a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java
index cba1586..c428102 100644
--- a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java
+++ b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/AWSServiceFactory.java
@@ -92,4 +92,8 @@ public final class AWSServiceFactory {
     public static AWSService createKMSService() {
         return createService("AWS KMS", AWSKMSLocalContainerService::new);
     }
+
+    public static AWSService createLambdaService() {
+        return createService("AWS Lambda", AWSLambdaLocalContainerService::new);
+    }
 }
diff --git a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/Service.java b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/Service.java
index dbe391f..990ddc3 100644
--- a/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/Service.java
+++ b/test-infra/camel-test-infra-aws-v2/src/test/java/org/apache/camel/test/infra/aws2/services/Service.java
@@ -24,6 +24,7 @@ public enum Service {
     IAM("iam"),
     KINESIS("kinesis"),
     KMS("kms"),
+    LAMBDA("lambda"),
     S3("s3"),
     SQS("sqs"),
     SNS("sns");