Skip to content

Commit 2b29db5

Browse files
Add integration tests for AWS2 Translate component
This commit adds integration tests for the AWS2 Translate component, using WireMock to mock the AWS service as it is not supported by LocalStack Community Edition. It also improves core AWS test support to handle mock backends more robustly when LocalStack is skipped. - Added integration tests for aws2-translate - Introduced WireMock to mock TranslateText operation - Improved Aws2TestResource to bypass LocalStack for unsupported services - Exported credentials in Aws2TestEnvContext for mock backends - Registered AWS SDK Translate execution interceptors for runtime reflection
1 parent 84b0f88 commit 2b29db5

16 files changed

Lines changed: 486 additions & 28 deletions

File tree

extensions/aws2-translate/deployment/src/main/java/org/apache/camel/quarkus/component/aws2/translate/deployment/Aws2TranslateProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.camel.quarkus.component.aws2.translate.deployment;
1818

1919
import java.util.List;
20+
import java.util.stream.Collectors;
2021

2122
import io.quarkus.deployment.annotations.BuildProducer;
2223
import io.quarkus.deployment.annotations.BuildStep;
@@ -34,7 +35,8 @@ class Aws2TranslateProcessor {
3435
public static final String AWS_SDK_APPLICATION_ARCHIVE_MARKERS = "software/amazon/awssdk";
3536

3637
private static final List<String> INTERCEPTOR_PATHS = List.of(
37-
"software/amazon/awssdk/global/handlers/execution.interceptors");
38+
"software/amazon/awssdk/global/handlers/execution.interceptors",
39+
"software/amazon/awssdk/services/translate/execution.interceptors");
3840

3941
private static final DotName EXECUTION_INTERCEPTOR_NAME = DotName.createSimple(ExecutionInterceptor.class.getName());
4042

@@ -53,7 +55,7 @@ void process(CombinedIndexBuildItem combinedIndexBuildItem,
5355
List<String> knownInterceptorImpls = combinedIndexBuildItem.getIndex()
5456
.getAllKnownImplementations(EXECUTION_INTERCEPTOR_NAME)
5557
.stream()
56-
.map(c -> c.name().toString()).toList();
58+
.map(c -> c.name().toString()).collect(Collectors.toList());
5759

5860
reflectiveClasses.produce(
5961
ReflectiveClassBuildItem.builder(knownInterceptorImpls.toArray(new String[knownInterceptorImpls.size()]))
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<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">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.camel.quarkus</groupId>
24+
<artifactId>camel-quarkus-build-parent-it</artifactId>
25+
<version>3.33.0-SNAPSHOT</version>
26+
<relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
27+
</parent>
28+
29+
<artifactId>camel-quarkus-integration-test-aws2-translate</artifactId>
30+
<name>Camel Quarkus :: Integration Tests :: AWS2 Translate</name>
31+
<description>The camel integration tests</description>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.apache.camel.quarkus</groupId>
36+
<artifactId>camel-quarkus-aws2-translate</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>io.quarkus</groupId>
40+
<artifactId>quarkus-resteasy</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>io.quarkus</groupId>
44+
<artifactId>quarkus-resteasy-jackson</artifactId>
45+
</dependency>
46+
47+
<!-- test dependencies -->
48+
<dependency>
49+
<groupId>io.quarkus</groupId>
50+
<artifactId>quarkus-junit</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>io.rest-assured</groupId>
55+
<artifactId>rest-assured</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.camel.quarkus</groupId>
60+
<artifactId>camel-quarkus-integration-tests-support-aws2</artifactId>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.apache.camel.quarkus</groupId>
64+
<artifactId>camel-quarkus-integration-tests-support-aws2</artifactId>
65+
<type>test-jar</type>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.camel.quarkus</groupId>
70+
<artifactId>camel-quarkus-integration-wiremock-support</artifactId>
71+
<version>${project.version}</version>
72+
<scope>test</scope>
73+
</dependency>
74+
</dependencies>
75+
76+
<profiles>
77+
<profile>
78+
<id>native</id>
79+
<activation>
80+
<property>
81+
<name>native</name>
82+
</property>
83+
</activation>
84+
<properties>
85+
<quarkus.native.enabled>true</quarkus.native.enabled>
86+
</properties>
87+
<build>
88+
<plugins>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-failsafe-plugin</artifactId>
92+
<executions>
93+
<execution>
94+
<goals>
95+
<goal>integration-test</goal>
96+
<goal>verify</goal>
97+
</goals>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
</plugins>
102+
</build>
103+
</profile>
104+
<profile>
105+
<id>virtualDependencies</id>
106+
<activation>
107+
<property>
108+
<name>!noVirtualDependencies</name>
109+
</property>
110+
</activation>
111+
<dependencies>
112+
<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
113+
<dependency>
114+
<groupId>org.apache.camel.quarkus</groupId>
115+
<artifactId>camel-quarkus-aws2-translate-deployment</artifactId>
116+
<version>${project.version}</version>
117+
<type>pom</type>
118+
<scope>test</scope>
119+
<exclusions>
120+
<exclusion>
121+
<groupId>*</groupId>
122+
<artifactId>*</artifactId>
123+
</exclusion>
124+
</exclusions>
125+
</dependency>
126+
</dependencies>
127+
</profile>
128+
<profile>
129+
<id>skip-testcontainers-tests</id>
130+
<activation>
131+
<property>
132+
<name>skip-testcontainers-tests</name>
133+
</property>
134+
</activation>
135+
<properties>
136+
<skipTests>true</skipTests>
137+
</properties>
138+
</profile>
139+
</profiles>
140+
141+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.quarkus.component.aws2.translate.it;
18+
19+
import jakarta.enterprise.context.ApplicationScoped;
20+
import jakarta.inject.Inject;
21+
import jakarta.ws.rs.Consumes;
22+
import jakarta.ws.rs.POST;
23+
import jakarta.ws.rs.Path;
24+
import jakarta.ws.rs.Produces;
25+
import jakarta.ws.rs.QueryParam;
26+
import jakarta.ws.rs.core.MediaType;
27+
import org.apache.camel.ProducerTemplate;
28+
import org.apache.camel.component.aws2.translate.Translate2Constants;
29+
import org.apache.camel.quarkus.test.support.aws2.BaseAws2Resource;
30+
31+
@Path("/aws2-translate")
32+
@ApplicationScoped
33+
public class Aws2TranslateResource extends BaseAws2Resource {
34+
35+
@Inject
36+
ProducerTemplate producerTemplate;
37+
38+
public Aws2TranslateResource() {
39+
super("translate");
40+
}
41+
42+
@Path("/translate")
43+
@POST
44+
@Consumes(MediaType.TEXT_PLAIN)
45+
@Produces(MediaType.TEXT_PLAIN)
46+
public String translate(
47+
String text,
48+
@QueryParam("sourceLanguage") String sourceLanguage,
49+
@QueryParam("targetLanguage") String targetLanguage) throws Exception {
50+
return producerTemplate.requestBodyAndHeaders(
51+
"aws2-translate://test?operation=translateText",
52+
text,
53+
java.util.Map.of(
54+
Translate2Constants.SOURCE_LANGUAGE, sourceLanguage,
55+
Translate2Constants.TARGET_LANGUAGE, targetLanguage),
56+
String.class);
57+
}
58+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## ---------------------------------------------------------------------------
2+
## Licensed to the Apache Software Foundation (ASF) under one or more
3+
## contributor license agreements. See the NOTICE file distributed with
4+
## this work for additional information regarding copyright ownership.
5+
## The ASF licenses this file to You under the Apache License, Version 2.0
6+
## (the "License"); you may not use this file except in compliance with
7+
## the License. You may obtain a copy of the License at
8+
##
9+
## http://www.apache.org/licenses/LICENSE-2.0
10+
##
11+
## Unless required by applicable law or agreed to in writing, software
12+
## distributed under the License is distributed on an "AS IS" BASIS,
13+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
## See the License for the specific language governing permissions and
15+
## limitations under the License.
16+
## ---------------------------------------------------------------------------
17+
#
18+
# Camel :: AWS2 options
19+
#
20+
camel.component.aws2-translate.access-key=${AWS_ACCESS_KEY}
21+
camel.component.aws2-translate.secret-key=${AWS_SECRET_KEY}
22+
camel.component.aws2-translate.useDefaultCredentialsProvider=${AWS_USE_DEFAULT_CREDENTIALS_PROVIDER}
23+
camel.component.aws2-translate.region=${AWS_REGION:us-east-1}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.quarkus.component.aws2.translate.it;
18+
19+
import io.quarkus.test.junit.QuarkusIntegrationTest;
20+
21+
@QuarkusIntegrationTest
22+
class Aws2TranslateIT extends Aws2TranslateTest {
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.quarkus.component.aws2.translate.it;
18+
19+
import io.quarkus.test.common.QuarkusTestResource;
20+
import io.quarkus.test.junit.QuarkusTest;
21+
import io.restassured.RestAssured;
22+
import org.apache.camel.quarkus.test.support.aws2.Aws2TestResource;
23+
import org.apache.camel.quarkus.test.support.aws2.BaseAWs2TestSupport;
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.hamcrest.core.Is.is;
27+
28+
@QuarkusTest
29+
@QuarkusTestResource(Aws2TestResource.class)
30+
@QuarkusTestResource(Aws2TranslateTestResource.class)
31+
class Aws2TranslateTest extends BaseAWs2TestSupport {
32+
33+
public Aws2TranslateTest() {
34+
super("/aws2-translate");
35+
}
36+
37+
@Test
38+
public void translate() {
39+
RestAssured.given()
40+
.queryParam("sourceLanguage", "en")
41+
.queryParam("targetLanguage", "fr")
42+
.body("Hello")
43+
.post("/aws2-translate/translate")
44+
.then()
45+
.statusCode(200)
46+
.body(is("Bonjour"));
47+
}
48+
49+
@Override
50+
@org.junit.jupiter.api.Disabled("LocalStack not supported for Translate, skipping credential tests")
51+
public void successfulDefaultCredentialsProviderTest() {
52+
super.successfulDefaultCredentialsProviderTest();
53+
}
54+
55+
@Override
56+
@org.junit.jupiter.api.Disabled("LocalStack not supported for Translate, skipping credential tests")
57+
public void failingDefaultCredentialsProviderTest() {
58+
super.failingDefaultCredentialsProviderTest();
59+
}
60+
61+
@Override
62+
public void testMethodForDefaultCredentialsProvider() {
63+
RestAssured.given()
64+
.queryParam("sourceLanguage", "en")
65+
.queryParam("targetLanguage", "fr")
66+
.body("Hello")
67+
.post("/aws2-translate/translate")
68+
.then()
69+
.statusCode(200);
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.quarkus.component.aws2.translate.it;
18+
19+
import org.apache.camel.quarkus.test.support.aws2.Aws2TestEnvContext;
20+
import org.apache.camel.quarkus.test.support.aws2.Aws2TestEnvCustomizer;
21+
import org.apache.camel.quarkus.test.support.aws2.Service;
22+
23+
public class Aws2TranslateTestEnvCustomizer implements Aws2TestEnvCustomizer {
24+
25+
@Override
26+
public Service[] localstackServices() {
27+
return new Service[] {};
28+
}
29+
30+
@Override
31+
public Service[] exportCredentialsForLocalstackServices() {
32+
return new Service[] { Service.TRANSLATE };
33+
}
34+
35+
@Override
36+
public void customize(Aws2TestEnvContext envContext) {
37+
// No specific customization needed for Translate service beyond enabling it
38+
}
39+
40+
}

0 commit comments

Comments
 (0)