You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pp...@apache.org on 2021/07/14 14:55:48 UTC

[camel-quarkus] 02/13: Test claimCheck() EIP DSL method #2628

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

ppalaga pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 782f8240a7c7ef4f0a27f85a704d74d31513ba34
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Wed May 19 17:42:57 2021 +0200

    Test claimCheck() EIP DSL method #2628
---
 integration-test-groups/foundation/eip/pom.xml     | 132 +++++++++++++++++++++
 .../apache/camel/quarkus/eip/it/EipResource.java   |  74 ++++++++++++
 .../org/apache/camel/quarkus/eip/it/EipRoutes.java |  37 ++++++
 .../org/apache/camel/quarkus/eip/it/EipIT.java     |  24 ++++
 .../org/apache/camel/quarkus/eip/it/EipTest.java   |  45 +++++++
 integration-test-groups/foundation/pom.xml         |   1 +
 6 files changed, 313 insertions(+)

diff --git a/integration-test-groups/foundation/eip/pom.xml b/integration-test-groups/foundation/eip/pom.xml
new file mode 100644
index 0000000..431c324
--- /dev/null
+++ b/integration-test-groups/foundation/eip/pom.xml
@@ -0,0 +1,132 @@
+<?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-integration-tests-foundation</artifactId>
+        <version>2.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-integration-test-eip</artifactId>
+    <name>Camel Quarkus :: Integration Tests :: EIP</name>
+    <description>Integration tests for Camel Enterprise Integration Patterns</description>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.camel.quarkus</groupId>
+                <artifactId>camel-quarkus-bom-test</artifactId>
+                <version>${project.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-mock</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</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>
+
+        <!-- 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-mock-deployment</artifactId>
+            <version>${project.version}</version>
+            <type>pom</type>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>*</groupId>
+                    <artifactId>*</artifactId>
+                </exclusion>
+            </exclusions>
+        </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>
+    </profiles>
+
+</project>
diff --git a/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipResource.java b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipResource.java
new file mode 100644
index 0000000..ce54bca
--- /dev/null
+++ b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipResource.java
@@ -0,0 +1,74 @@
+/*
+ * 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.eip.it;
+
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+
+@Path("/eip")
+@ApplicationScoped
+public class EipResource {
+
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Inject
+    CamelContext context;
+
+    @Path("/route/{route}")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String route(String statement, @PathParam("route") String route, @Context UriInfo uriInfo) {
+        final Map<String, Object> headers = uriInfo.getQueryParameters().entrySet().stream()
+                .map(e -> new AbstractMap.SimpleImmutableEntry<String, Object>(e.getKey(), e.getValue().get(0)))
+                .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
+        return producerTemplate.requestBodyAndHeaders("direct:" + route, statement, headers, String.class);
+    }
+
+    @Path("/mock/{name}/{count}/{timeout}")
+    @Produces(MediaType.TEXT_PLAIN)
+    @GET
+    public String mock(@PathParam("name") String name, @PathParam("count") int count, @PathParam("timeout") int timeout) {
+        MockEndpoint mock = context.getEndpoint("mock:" + name, MockEndpoint.class);
+        mock.setExpectedMessageCount(count);
+        try {
+            mock.assertIsSatisfied(timeout);
+        } catch (InterruptedException e1) {
+            Thread.currentThread().interrupt();
+        }
+        return mock.getExchanges().stream().map(e -> e.getMessage().getBody(String.class)).collect(Collectors.joining(","));
+    }
+}
diff --git a/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipRoutes.java b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipRoutes.java
new file mode 100644
index 0000000..7c1b078
--- /dev/null
+++ b/integration-test-groups/foundation/eip/src/main/java/org/apache/camel/quarkus/eip/it/EipRoutes.java
@@ -0,0 +1,37 @@
+/*
+ * 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.eip.it;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ClaimCheckOperation;
+
+public class EipRoutes extends RouteBuilder {
+
+    @Override
+    public void configure() {
+        from("direct:claimCheckByHeader")
+                .claimCheck(ClaimCheckOperation.Set, "${header.claimCheckId}")
+                .transform().constant("Bye World")
+                .to("mock:claimCheckByHeader")
+                .claimCheck(ClaimCheckOperation.Get, "${header.claimCheckId}")
+                .to("mock:claimCheckByHeader")
+                .transform().constant("Hi World")
+                .to("mock:claimCheckByHeader")
+                .claimCheck(ClaimCheckOperation.Get, "${header.claimCheckId}")
+                .to("mock:claimCheckByHeader");
+    }
+}
diff --git a/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipIT.java b/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipIT.java
new file mode 100644
index 0000000..9a8956e
--- /dev/null
+++ b/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipIT.java
@@ -0,0 +1,24 @@
+/*
+ * 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.eip.it;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+class EipIT extends EipTest {
+
+}
diff --git a/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipTest.java b/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipTest.java
new file mode 100644
index 0000000..bfa129c
--- /dev/null
+++ b/integration-test-groups/foundation/eip/src/test/java/org/apache/camel/quarkus/eip/it/EipTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.eip.it;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+
+@QuarkusTest
+class EipTest {
+
+    @Test
+    public void claimCheckByHeader() {
+        RestAssured.given()
+                .contentType(ContentType.TEXT)
+                .body("Secret")
+                .queryParam("claimCheckId", "foo")
+                .post("/eip/route/claimCheckByHeader")
+                .then()
+                .statusCode(200);
+
+        RestAssured.get("/eip/mock/claimCheckByHeader/4/10000")
+                .then()
+                .statusCode(200)
+                .body(Matchers.is("Bye World,Secret,Hi World,Secret"));
+
+    }
+
+}
diff --git a/integration-test-groups/foundation/pom.xml b/integration-test-groups/foundation/pom.xml
index 6d9c895..74b97fe 100644
--- a/integration-test-groups/foundation/pom.xml
+++ b/integration-test-groups/foundation/pom.xml
@@ -43,6 +43,7 @@
         <module>core-thread-pools</module>
         <module>customized-log-component</module>
         <module>direct</module>
+        <module>eip</module>
         <module>log</module>
         <module>mock</module>
         <module>ref</module>