This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 4baef5ceeb0880eb01c0289f29829a183c981030 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Tue Oct 31 09:42:07 2023 +0000 Add basic test coverage for transformer EIP --- integration-test-groups/foundation/pom.xml | 1 + .../foundation/transformer/pom.xml | 126 +++++++++++++++++++++ .../camel/quarkus/transformer/TransformerBean.java | 33 ++++++ .../transformer/TransformerBeanConverter.java | 34 ++++++ .../quarkus/transformer/TransformerResource.java | 65 +++++++++++ .../quarkus/transformer/TransformerRoutes.java | 36 ++++++ .../camel/quarkus/transformer/TransformerIT.java | 23 ++++ .../camel/quarkus/transformer/TransformerTest.java | 54 +++++++++ 8 files changed, 372 insertions(+) diff --git a/integration-test-groups/foundation/pom.xml b/integration-test-groups/foundation/pom.xml index 66b31115b8..b76122511b 100644 --- a/integration-test-groups/foundation/pom.xml +++ b/integration-test-groups/foundation/pom.xml @@ -55,6 +55,7 @@ <module>seda</module> <module>stream</module> <module>timer</module> + <module>transformer</module> <module>type-converter</module> </modules> diff --git a/integration-test-groups/foundation/transformer/pom.xml b/integration-test-groups/foundation/transformer/pom.xml new file mode 100644 index 0000000000..e7a40c1059 --- /dev/null +++ b/integration-test-groups/foundation/transformer/pom.xml @@ -0,0 +1,126 @@ +<?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.quarkus</groupId> + <artifactId>camel-quarkus-build-parent-it</artifactId> + <version>3.6.0-SNAPSHOT</version> + <relativePath>../../../poms/build-parent-it/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-transformer</artifactId> + <name>Camel Quarkus :: Integration Tests :: Transformer :: Tests</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</artifactId> + </dependency> + + <!-- test dependencies --> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-junit5</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>io.rest-assured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>native</id> + <activation> + <property> + <name>native</name> + </property> + </activation> + <properties> + <quarkus.package.type>native</quarkus.package.type> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>virtualDependencies</id> + <activation> + <property> + <name>!noVirtualDependencies</name> + </property> + </activation> + <dependencies> + <!-- 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 --> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-log-deployment</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + </profile> + </profiles> + +</project> diff --git a/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerBean.java b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerBean.java new file mode 100644 index 0000000000..9d59132b47 --- /dev/null +++ b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerBean.java @@ -0,0 +1,33 @@ +/* + * 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.quarkus.transformer; + +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection(fields = false, methods = false) +public class TransformerBean { + private final String message; + + public TransformerBean(String message) { + this.message = message; + } + + @Override + public String toString() { + return "Transformed " + message; + } +} diff --git a/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerBeanConverter.java b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerBeanConverter.java new file mode 100644 index 0000000000..c302febbc1 --- /dev/null +++ b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerBeanConverter.java @@ -0,0 +1,34 @@ +/* + * 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.quarkus.transformer; + +import java.nio.charset.StandardCharsets; + +import jakarta.inject.Singleton; +import org.apache.camel.Converter; + +/** + * Custom TypeConverter for use with the application-octet-stream transformer + */ +@Singleton +@Converter +public class TransformerBeanConverter { + @Converter + public byte[] convertTransformerBeanToBytes(TransformerBean bean) { + return bean.toString().getBytes(StandardCharsets.UTF_8); + } +} diff --git a/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerResource.java b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerResource.java new file mode 100644 index 0000000000..b0042d1b4d --- /dev/null +++ b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerResource.java @@ -0,0 +1,65 @@ +/* + * 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.quarkus.transformer; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.spi.TransformerRegistry; + +@Path("/transformer") +@ApplicationScoped +public class TransformerResource { + @Inject + CamelContext context; + + @Inject + ProducerTemplate producerTemplate; + + @Path("/registry") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String transformerRegistry() { + TransformerRegistry transformerRegistry = context.getTransformerRegistry(); + if (transformerRegistry != null) { + return transformerRegistry.getClass().getName(); + } + return null; + } + + @Path("/toString") + @POST + @Produces(MediaType.TEXT_PLAIN) + public String transformBeanToString(String message) { + TransformerBean bean = new TransformerBean(message); + return (String) producerTemplate.requestBody("direct:transformBeanToString", bean); + } + + @Path("/toBytes") + @POST + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public byte[] transformBeanToBytes(String message) { + TransformerBean bean = new TransformerBean(message); + return (byte[]) producerTemplate.requestBody("direct:transformBeanToBytes", bean); + } +} diff --git a/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerRoutes.java b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerRoutes.java new file mode 100644 index 0000000000..2dedac8df7 --- /dev/null +++ b/integration-test-groups/foundation/transformer/src/main/java/org/apache/camel/quarkus/transformer/TransformerRoutes.java @@ -0,0 +1,36 @@ +/* + * 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.quarkus.transformer; + +import org.apache.camel.builder.RouteBuilder; + +public class TransformerRoutes extends RouteBuilder { + @Override + public void configure() throws Exception { + transformer().withDefaults(); + + from("direct:transformBeanToString") + .inputType(TransformerBean.class) + .outputType("text-plain") + .log("Transformed TransformerBean to String"); + + from("direct:transformBeanToBytes") + .inputType(TransformerBean.class) + .outputType("application-octet-stream") + .log("Transformed TransformerBean to byte[]"); + } +} diff --git a/integration-test-groups/foundation/transformer/src/test/java/org/apache/camel/quarkus/transformer/TransformerIT.java b/integration-test-groups/foundation/transformer/src/test/java/org/apache/camel/quarkus/transformer/TransformerIT.java new file mode 100644 index 0000000000..e981f6c72a --- /dev/null +++ b/integration-test-groups/foundation/transformer/src/test/java/org/apache/camel/quarkus/transformer/TransformerIT.java @@ -0,0 +1,23 @@ +/* + * 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.quarkus.transformer; + +import io.quarkus.test.junit.QuarkusIntegrationTest; + +@QuarkusIntegrationTest +public class TransformerIT extends TransformerTest { +} diff --git a/integration-test-groups/foundation/transformer/src/test/java/org/apache/camel/quarkus/transformer/TransformerTest.java b/integration-test-groups/foundation/transformer/src/test/java/org/apache/camel/quarkus/transformer/TransformerTest.java new file mode 100644 index 0000000000..91c9f506b4 --- /dev/null +++ b/integration-test-groups/foundation/transformer/src/test/java/org/apache/camel/quarkus/transformer/TransformerTest.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.quarkus.transformer; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.apache.camel.impl.engine.DefaultTransformerRegistry; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.is; + +@QuarkusTest +public class TransformerTest { + @Test + void testTransformerRegistryImpl() { + RestAssured.get("/transformer/registry") + .then() + .body(is(DefaultTransformerRegistry.class.getName())); + } + + @Test + void testTransformBeanToString() { + RestAssured.given() + .body("To String") + .when() + .post("/transformer/toString") + .then() + .body(is("Transformed To String")); + } + + @Test + void testTransformBeanToBytes() { + RestAssured.given() + .body("To Bytes") + .when() + .post("/transformer/toBytes") + .then() + .body(is("Transformed To Bytes")); + } +}