You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2024/06/27 07:22:02 UTC
(camel-karaf) branch main updated: Added missing bundle and integration test for camel-aws2-s3 (#392)
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push:
new ec1c4971 Added missing bundle and integration test for camel-aws2-s3 (#392)
ec1c4971 is described below
commit ec1c49714c4bb52f9c91c285f1443003cdee625e
Author: lopushen <lo...@gmail.com>
AuthorDate: Thu Jun 27 10:21:58 2024 +0300
Added missing bundle and integration test for camel-aws2-s3 (#392)
---
features/src/main/feature/camel-features.xml | 1 +
tests/features/camel-aws2-s3/pom.xml | 46 +++++++++++++
.../karaf/camel/test/CamelAws2S3RouteSupplier.java | 66 ++++++++++++++++++
.../apache/karaf/camel/itest/CamelAws2S3ITest.java | 78 ++++++++++++++++++++++
tests/features/pom.xml | 1 +
5 files changed, 192 insertions(+)
diff --git a/features/src/main/feature/camel-features.xml b/features/src/main/feature/camel-features.xml
index 24672337..e0b037ae 100644
--- a/features/src/main/feature/camel-features.xml
+++ b/features/src/main/feature/camel-features.xml
@@ -528,6 +528,7 @@
<feature version='${camel-osgi-version-range}'>camel-cloudevents</feature>
<feature version="${aws-java-sdk2-version}">awssdk</feature>
<bundle dependency='true'>wrap:mvn:software.amazon.awssdk/s3/${aws-java-sdk2-version}</bundle>
+ <bundle dependency='true'>wrap:mvn:software.amazon.awssdk/aws-xml-protocol/${aws-java-sdk2-version}</bundle>
<bundle>mvn:org.apache.camel.karaf/camel-aws2-s3/${project.version}</bundle>
</feature>
<feature name='camel-aws2-ses' version='${project.version}' start-level='50'>
diff --git a/tests/features/camel-aws2-s3/pom.xml b/tests/features/camel-aws2-s3/pom.xml
new file mode 100644
index 00000000..79c054bf
--- /dev/null
+++ b/tests/features/camel-aws2-s3/pom.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.karaf</groupId>
+ <artifactId>camel-karaf-features-test</artifactId>
+ <version>4.6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-aws2-s3-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: AWS2 S3</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-aws2-s3</artifactId>
+ <version>${camel-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>localstack</artifactId>
+ <version>${testcontainers-version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/tests/features/camel-aws2-s3/src/main/java/org/apache/karaf/camel/test/CamelAws2S3RouteSupplier.java b/tests/features/camel-aws2-s3/src/main/java/org/apache/karaf/camel/test/CamelAws2S3RouteSupplier.java
new file mode 100644
index 00000000..1ac57567
--- /dev/null
+++ b/tests/features/camel-aws2-s3/src/main/java/org/apache/karaf/camel/test/CamelAws2S3RouteSupplier.java
@@ -0,0 +1,66 @@
+/*
+ * 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.karaf.camel.test;
+
+import java.util.function.Function;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.aws2.s3.AWS2S3Component;
+import org.apache.camel.component.aws2.s3.AWS2S3Configuration;
+import org.apache.camel.component.aws2.s3.AWS2S3Constants;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(name = "karaf-camel-aws2-s3-test", immediate = true, service = CamelRouteSupplier.class)
+public class CamelAws2S3RouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ private static final String HOST = System.getProperty("localstack.s3.host");
+ private static final String PORT = System.getProperty("localstack.s3.port");
+ private static final String REGION = System.getProperty("localstack.s3.region");
+ private static final String ACCESS_KEY = System.getProperty("localstack.s3.accessKey");
+ private static final String SECRET_KEY = System.getProperty("localstack.s3.secretKey");
+ private static final String COMPONENT_NAME = "aws2-s3";
+ private static final String BUCKET_NAME = "test-bucket";
+
+ @Override
+ public void configure(CamelContext camelContext) {
+ final AWS2S3Component aws2S3Component = new AWS2S3Component();
+ final AWS2S3Configuration configuration = new AWS2S3Configuration();
+ configuration.setAccessKey(ACCESS_KEY);
+ configuration.setSecretKey(SECRET_KEY);
+ configuration.setRegion(REGION);
+ configuration.setOverrideEndpoint(true);
+ configuration.setUriEndpointOverride(String.format("http://%s:%s", HOST, PORT));
+ aws2S3Component.setConfiguration(configuration);
+ camelContext.addComponent(COMPONENT_NAME, aws2S3Component);
+ }
+
+ @Override
+ protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+ return builder -> builder.fromF("%s://%s", COMPONENT_NAME, BUCKET_NAME).log("Received successfully: ${body}");
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) {
+ producerRoute.setHeader(AWS2S3Constants.KEY, builder.constant("hello.txt"))
+ .setBody(builder.constant("Hello AWS2S3!"))
+ .toF("%s://%s?autoCreateBucket=true", COMPONENT_NAME, BUCKET_NAME)
+ .log("Sent successfully: ${body}");
+ }
+}
\ No newline at end of file
diff --git a/tests/features/camel-aws2-s3/src/test/java/org/apache/karaf/camel/itest/CamelAws2S3ITest.java b/tests/features/camel-aws2-s3/src/test/java/org/apache/karaf/camel/itest/CamelAws2S3ITest.java
new file mode 100644
index 00000000..43095799
--- /dev/null
+++ b/tests/features/camel-aws2-s3/src/test/java/org/apache/karaf/camel/itest/CamelAws2S3ITest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed 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.karaf.camel.itest;
+
+import org.apache.camel.component.mock.MockEndpoint;
+
+import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.apache.karaf.camel.itests.CamelKarafTestHint;
+import org.apache.karaf.camel.itests.GenericContainerResource;
+import org.apache.karaf.camel.itests.PaxExamWithExternalResource;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.testcontainers.containers.localstack.LocalStackContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.utility.DockerImageName;
+
+@CamelKarafTestHint(externalResourceProvider = CamelAws2S3ITest.ExternalResourceProviders.class)
+@RunWith(PaxExamWithExternalResource.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelAws2S3ITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived("Hello AWS2S3!");
+ }
+
+ @Test
+ public void testResultMock() throws Exception {
+ MockEndpoint.assertIsSatisfied(getContext());
+ }
+
+ public static final class ExternalResourceProviders {
+
+ private static final int LOCALSTACK_ORIGINAL_PORT = 4566;
+ private static final String ACCESS_KEY = "test";
+ private static final String SECRET_KEY = "test";
+ private static final String REGION = "us-east-1";
+
+ public static GenericContainerResource<LocalStackContainer> createAws2S3Container() {
+
+ final LocalStackContainer localStackContainer =
+ new LocalStackContainer(DockerImageName.parse("localstack/localstack:3.4.0")).withServices(
+ LocalStackContainer.Service.S3).waitingFor(Wait.forLogMessage(".*Ready\\.\n", 1));
+
+ return new GenericContainerResource<>(localStackContainer, resource -> {
+ try {
+ localStackContainer.execInContainer("aws", "configure", "set", "aws_access_key_id", ACCESS_KEY, "--profile",
+ "localstack");
+ localStackContainer.execInContainer("aws", "configure", "set", "aws_secret_access_key", SECRET_KEY,
+ "--profile", "localstack");
+ localStackContainer.execInContainer("aws", "configure", "set", "region", REGION, "--profile", "localstack");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ // the localStackContainer.getHost() returns 'localhost' and AWS SDK throws UnknownHostException, hardcoding 127.0.0.1 for now
+ resource.setProperty("localstack.s3.host", "127.0.0.1");
+ resource.setProperty("localstack.s3.port",
+ Integer.toString(localStackContainer.getMappedPort(LOCALSTACK_ORIGINAL_PORT)));
+ resource.setProperty("localstack.s3.accessKey", ACCESS_KEY);
+ resource.setProperty("localstack.s3.secretKey", SECRET_KEY);
+ resource.setProperty("localstack.s3.region", REGION);
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 7bf1c0a8..18861ab6 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -40,6 +40,7 @@
<module>camel-activemq</module>
<module>camel-amqp</module>
<module>camel-arangodb</module>
+ <module>camel-aws2-s3</module>
<module>camel-aws2-ses</module>
<module>camel-aws2-sns</module>
<module>camel-aws2-sqs</module>