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 2020/09/09 09:20:14 UTC

[camel-quarkus] 02/02: Test for #1497 xml-io should pass namespace info to NamespaceAware elements

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

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

commit 39d404d5acd5b894c93977950fb6bb1d77760922
Author: Peter Palaga <pp...@redhat.com>
AuthorDate: Wed Sep 9 09:46:35 2020 +0200

    Test for #1497 xml-io should pass namespace info to NamespaceAware
    elements
---
 integration-tests/main-xml-io/pom.xml                   | 17 +++++++++++++++++
 .../camel/quarkus/main/CoreMainXmlIoResource.java       | 14 ++++++++++++++
 .../main-xml-io/src/main/resources/routes/my-routes.xml | 10 ++++++++++
 .../apache/camel/quarkus/main/CoreMainXmlIoTest.java    | 17 +++++++++++++++++
 4 files changed, 58 insertions(+)

diff --git a/integration-tests/main-xml-io/pom.xml b/integration-tests/main-xml-io/pom.xml
index 1071ff1..bba1792 100644
--- a/integration-tests/main-xml-io/pom.xml
+++ b/integration-tests/main-xml-io/pom.xml
@@ -59,6 +59,10 @@
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-resteasy-jsonb</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-xpath</artifactId>
+        </dependency>
 
         <!-- test dependencies -->
         <dependency>
@@ -143,6 +147,19 @@
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-xpath-deployment</artifactId>
+            <version>${project.version}</version>
+            <type>pom</type>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>*</groupId>
+                    <artifactId>*</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
 
     </dependencies>
 
diff --git a/integration-tests/main-xml-io/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlIoResource.java b/integration-tests/main-xml-io/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlIoResource.java
index e1e0bf9..52d8574 100644
--- a/integration-tests/main-xml-io/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlIoResource.java
+++ b/integration-tests/main-xml-io/src/main/java/org/apache/camel/quarkus/main/CoreMainXmlIoResource.java
@@ -22,12 +22,15 @@ import javax.json.Json;
 import javax.json.JsonArrayBuilder;
 import javax.json.JsonObject;
 import javax.json.JsonObjectBuilder;
+import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.ProducerTemplate;
 
 @Path("/test")
 @ApplicationScoped
@@ -35,6 +38,9 @@ public class CoreMainXmlIoResource {
     @Inject
     CamelMain main;
 
+    @Inject
+    ProducerTemplate template;
+
     @Path("/main/describe")
     @GET
     @Produces(MediaType.APPLICATION_JSON)
@@ -69,4 +75,12 @@ public class CoreMainXmlIoResource {
                 .add("autoConfigurationLogSummary", main.getMainConfigurationProperties().isAutoConfigurationLogSummary())
                 .build();
     }
+
+    @Path("/xml-io/namespace-aware")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    @Consumes(MediaType.APPLICATION_XML)
+    public String namespaceAware(String body) {
+        return template.requestBody("direct:namespace-aware", body, String.class);
+    }
 }
diff --git a/integration-tests/main-xml-io/src/main/resources/routes/my-routes.xml b/integration-tests/main-xml-io/src/main/resources/routes/my-routes.xml
index e491c29..48feb17 100644
--- a/integration-tests/main-xml-io/src/main/resources/routes/my-routes.xml
+++ b/integration-tests/main-xml-io/src/main/resources/routes/my-routes.xml
@@ -19,6 +19,7 @@
 -->
 <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">
@@ -31,4 +32,13 @@
         <to uri="log:from-xml"/>
     </route>
 
+    <route id="namespace-aware-route">
+        <from uri="direct:namespace-aware"/>
+        <setBody>
+           <xpath resultType="java.lang.String">
+              /foo:foo-text/text()
+           </xpath>
+        </setBody>
+    </route>
+
 </routes>
\ No newline at end of file
diff --git a/integration-tests/main-xml-io/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoTest.java b/integration-tests/main-xml-io/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoTest.java
index 47af09c..e773e6c 100644
--- a/integration-tests/main-xml-io/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoTest.java
+++ b/integration-tests/main-xml-io/src/test/java/org/apache/camel/quarkus/main/CoreMainXmlIoTest.java
@@ -20,6 +20,7 @@ import javax.ws.rs.core.MediaType;
 
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
+import io.restassured.http.ContentType;
 import io.restassured.path.json.JsonPath;
 import org.apache.camel.quarkus.core.DisabledModelJAXBContextFactory;
 import org.apache.camel.quarkus.core.DisabledModelToXMLDumper;
@@ -27,6 +28,7 @@ import org.apache.camel.xml.in.ModelParserXMLRoutesDefinitionLoader;
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.core.Is.is;
 
 @QuarkusTest
 public class CoreMainXmlIoTest {
@@ -50,4 +52,19 @@ public class CoreMainXmlIoTest {
         assertThat(p.getList("routes", String.class))
                 .contains("my-xml-route");
     }
+
+    @Test
+    public void namespaceAware() {
+        String message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                + "<foo:foo-text xmlns:foo=\"http://camel.apache.org/foo\">bar</foo:foo-text>";
+
+        RestAssured.given()
+                .contentType(ContentType.XML)
+                .body(message)
+                .post("/test/xml-io/namespace-aware")
+                .then()
+                .statusCode(200)
+                .body(is("bar"));
+
+    }
 }