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/10/01 07:19:49 UTC

[camel] 02/04: Camel-AWS2-Lambda: Added base test for localstack

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

acosentino pushed a commit to branch aws2-lambda-first-spike-test
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c76e810a49ceea63d9a734f64b47e740c1577475
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Oct 1 09:00:48 2020 +0200

    Camel-AWS2-Lambda: Added base test for localstack
---
 .../aws2/lambda/localstack/Aws2LambdaBaseTest.java | 76 ++++++++++++++++++++++
 1 file changed, 76 insertions(+)

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
new file mode 100644
index 0000000..93be03f
--- /dev/null
+++ b/components/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/localstack/Aws2LambdaBaseTest.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.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.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;
+
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+public class Aws2LambdaBaseTest extends ContainerAwareTestSupport {
+
+    public static final String CONTAINER_IMAGE = "localstack/localstack:0.11.5";
+    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", "kms")
+                .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;
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        Lambda2Component lambdaComponent = context.getComponent("aws2-lambda", Lambda2Component.class);
+        lambdaComponent.getConfiguration().setAwsLambdaClient(getLambdaClient());
+        return context;
+    }
+}