You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2023/02/16 08:32:37 UTC

[camel-quarkus] branch main updated: create itest project for xml-io + bean #4579

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 05feb33bfd create itest project for xml-io + bean #4579
05feb33bfd is described below

commit 05feb33bfd7324d44b7f099a7c8dfa6d1661c161
Author: aldettinger <al...@gmail.com>
AuthorDate: Wed Feb 15 18:07:02 2023 +0100

    create itest project for xml-io + bean #4579
---
 .../pages/user-guide/defining-camel-routes.adoc    |   7 +
 integration-tests/main-xml-io-with-beans/pom.xml   | 152 +++++++++++++++++++++
 .../main/CoreMainXmlIoWithBeansResource.java       |  52 +++++++
 .../java/org/apache/camel/quarkus/main/MyBean.java |  30 ++++
 .../src/main/resources/application.properties      |  29 ++++
 .../resources/routes/my-route-with-beanType.xml    |  32 +++++
 .../quarkus/main/CoreMainXmlIoWithBeansIT.java     |  23 ++++
 .../quarkus/main/CoreMainXmlIoWithBeansTest.java   |  39 ++++++
 integration-tests/pom.xml                          |   1 +
 tooling/scripts/test-categories.yaml               |   1 +
 10 files changed, 366 insertions(+)

diff --git a/docs/modules/ROOT/pages/user-guide/defining-camel-routes.adoc b/docs/modules/ROOT/pages/user-guide/defining-camel-routes.adoc
index 4d82d6e409..3fdad3ad95 100644
--- a/docs/modules/ROOT/pages/user-guide/defining-camel-routes.adoc
+++ b/docs/modules/ROOT/pages/user-guide/defining-camel-routes.adoc
@@ -84,6 +84,13 @@ Path globbing like `camel.main.routes-include-pattern = *./routes.xml` currently
 </routes>
 ----
 
+[WARNING]
+====
+When using XML routes with beans, it is sometime needed to refer to class name, for instance `beanType=org.apache.SomeClass`.
+In such cases, it might be needed to register the class for reflection in native mode.
+Refer to the xref:user-guide/native-mode.adoc#reflection[Native mode] user guide for more information.
+====
+
 [WARNING]
 ====
 Spring XML with `<beans>` or Blueprint XML with `<blueprint>` elements are not supported.
diff --git a/integration-tests/main-xml-io-with-beans/pom.xml b/integration-tests/main-xml-io-with-beans/pom.xml
new file mode 100644
index 0000000000..3cd8ef0f3f
--- /dev/null
+++ b/integration-tests/main-xml-io-with-beans/pom.xml
@@ -0,0 +1,152 @@
+<?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.0.0-SNAPSHOT</version>
+        <relativePath>../../poms/build-parent-it/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>camel-quarkus-integration-test-main-xml-io-with-beans</artifactId>
+    <name>Camel Quarkus :: Integration Tests :: Main XML Io With Beans :: Tests</name>
+    <description>The camel integration tests</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-xml-io-dsl</artifactId>
+       </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-bean</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>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</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-xml-io-dsl-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-bean-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-direct-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-tests/main-xml-io-with-beans/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansResource.java b/integration-tests/main-xml-io-with-beans/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansResource.java
new file mode 100644
index 0000000000..2cb837359e
--- /dev/null
+++ b/integration-tests/main-xml-io-with-beans/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansResource.java
@@ -0,0 +1,52 @@
+/*
+ * 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.main;
+
+import java.util.AbstractMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.UriInfo;
+import org.apache.camel.ProducerTemplate;
+
+@Path("/xml-io-with-beans")
+@ApplicationScoped
+public class CoreMainXmlIoWithBeansResource {
+    @Inject
+    ProducerTemplate producerTemplate;
+
+    @Path("/route/{route}")
+    @POST
+    @Consumes(MediaType.TEXT_PLAIN)
+    @Produces(MediaType.TEXT_PLAIN)
+    public String route(String body, @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, body, headers, String.class);
+    }
+}
diff --git a/integration-tests/main-xml-io-with-beans/src/main/java/org/apache/camel/quarkus/main/MyBean.java b/integration-tests/main-xml-io-with-beans/src/main/java/org/apache/camel/quarkus/main/MyBean.java
new file mode 100644
index 0000000000..4a92a6d086
--- /dev/null
+++ b/integration-tests/main-xml-io-with-beans/src/main/java/org/apache/camel/quarkus/main/MyBean.java
@@ -0,0 +1,30 @@
+/*
+ * 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.main;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.Handler;
+
+@RegisterForReflection
+public class MyBean {
+
+    @Handler
+    public String handler(String in) {
+        return in + "-handled-by-MyBean";
+    }
+
+}
diff --git a/integration-tests/main-xml-io-with-beans/src/main/resources/application.properties b/integration-tests/main-xml-io-with-beans/src/main/resources/application.properties
new file mode 100644
index 0000000000..ba1ed3554e
--- /dev/null
+++ b/integration-tests/main-xml-io-with-beans/src/main/resources/application.properties
@@ -0,0 +1,29 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# Quarkus
+#
+
+#
+# Camel
+#
+
+#
+# Main
+#
+camel.main.routes-include-pattern = routes/my-route-with-beanType.xml
diff --git a/integration-tests/main-xml-io-with-beans/src/main/resources/routes/my-route-with-beanType.xml b/integration-tests/main-xml-io-with-beans/src/main/resources/routes/my-route-with-beanType.xml
new file mode 100644
index 0000000000..3582a5b3fa
--- /dev/null
+++ b/integration-tests/main-xml-io-with-beans/src/main/resources/routes/my-route-with-beanType.xml
@@ -0,0 +1,32 @@
+<?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.
+
+-->
+<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xmlns="http://camel.apache.org/schema/spring"
+        xmlns:foo="http://camel.apache.org/foo"
+        xsi:schemaLocation="
+            http://camel.apache.org/schema/spring
+            http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <route id="my-route-with-beanType">
+        <from uri="direct:withBeanType"/>
+        <bean beanType="org.apache.camel.quarkus.main.MyBean"/>
+    </route>
+
+</routes>
\ No newline at end of file
diff --git a/integration-tests/main-xml-io-with-beans/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansIT.java b/integration-tests/main-xml-io-with-beans/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansIT.java
new file mode 100644
index 0000000000..cb6c749be6
--- /dev/null
+++ b/integration-tests/main-xml-io-with-beans/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansIT.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.main;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+public class CoreMainXmlIoWithBeansIT extends CoreMainXmlIoWithBeansTest {
+}
diff --git a/integration-tests/main-xml-io-with-beans/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansTest.java b/integration-tests/main-xml-io-with-beans/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansTest.java
new file mode 100644
index 0000000000..3f195efb88
--- /dev/null
+++ b/integration-tests/main-xml-io-with-beans/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoWithBeansTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.main;
+
+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
+public class CoreMainXmlIoWithBeansTest {
+
+    @Test
+    public void beanTypeShouldSucceed() {
+        RestAssured.given()
+                .contentType(ContentType.TEXT)
+                .body("beanTypeShouldSucceed")
+                .post("/xml-io-with-beans/route/withBeanType")
+                .then()
+                .statusCode(200)
+                .body(Matchers.is("beanTypeShouldSucceed-handled-by-MyBean"));
+    }
+
+}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index e6e7e9d38d..c34d2c1585 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -45,6 +45,7 @@
         <module>main-discovery-disabled</module>
         <module>main-xml-jaxb</module>
         <module>main-xml-io</module>
+        <module>main-xml-io-with-beans</module>
         <module>main-collector</module>
         <!--<module>main-caffeine-lrucache</module>-->
         <module>main-command-mode</module>
diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml
index 1fcdb99960..335fbb6aac 100644
--- a/tooling/scripts/test-categories.yaml
+++ b/tooling/scripts/test-categories.yaml
@@ -51,6 +51,7 @@ group-03:
   - main-devmode
   - main-discovery-disabled
   - main-xml-io
+  - main-xml-io-with-beans
   - main-xml-jaxb
   - main-yaml
   - shiro