You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/11/13 06:19:36 UTC

[camel-quarkus] 02/03: Fixes #406 xslt extension

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

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

commit 517e311192d7a4f6ba5cf3e0004691dc928e1de7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Nov 13 07:13:54 2019 +0100

    Fixes #406 xslt extension
---
 integration-tests/xslt/pom.xml                     |  4 +++
 .../quarkus/component/xslt/it/XsltResource.java    | 25 ++-----------
 .../quarkus/component/xslt/it/XsltRoute.java}      | 35 ++++++------------
 .../xslt/src/main/resources/transform.xsl          | 41 ++++++++++++++++++++++
 .../camel/quarkus/component/xslt/it/XsltTest.java  | 16 ++-------
 5 files changed, 60 insertions(+), 61 deletions(-)

diff --git a/integration-tests/xslt/pom.xml b/integration-tests/xslt/pom.xml
index 3e8e8e6..423d142 100644
--- a/integration-tests/xslt/pom.xml
+++ b/integration-tests/xslt/pom.xml
@@ -38,6 +38,10 @@
         </dependency>
         <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>
diff --git a/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java
index 07feecd..0ea8144 100644
--- a/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java
+++ b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltResource.java
@@ -16,19 +16,13 @@
  */
 package org.apache.camel.quarkus.component.xslt.it;
 
-import java.net.URI;
-
 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.Produces;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
 
-import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.ProducerTemplate;
 import org.jboss.logging.Logger;
 
@@ -41,29 +35,14 @@ public class XsltResource {
     @Inject
     ProducerTemplate producerTemplate;
 
-    @Inject
-    ConsumerTemplate consumerTemplate;
-
     @Path("/get")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
     public String get() throws Exception {
-        final String message = consumerTemplate.receiveBodyNoWait("xslt:--fix-me--", String.class);
+        String body = "<mail><subject>Hey</subject><body>Hello world!</body></mail>";
+        String message = producerTemplate.requestBody("direct:start", body, String.class);
         LOG.infof("Received from xslt: %s", message);
         return message;
     }
 
-    @Path("/post")
-    @POST
-    @Consumes(MediaType.TEXT_PLAIN)
-    @Produces(MediaType.TEXT_PLAIN)
-    public Response post(String message) throws Exception {
-        LOG.infof("Sending to xslt: %s", message);
-        final String response = producerTemplate.requestBody("xslt:--fix-me--", message, String.class);
-        LOG.infof("Got response from xslt: %s", response);
-        return Response
-                .created(new URI("https://camel.apache.org/"))
-                .entity(response)
-                .build();
-    }
 }
diff --git a/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltRoute.java
similarity index 53%
copy from integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
copy to integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltRoute.java
index ff5621a..c844765 100644
--- a/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
+++ b/integration-tests/xslt/src/main/java/org/apache/camel/quarkus/component/xslt/it/XsltRoute.java
@@ -1,13 +1,13 @@
-/*
+/**
  * 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
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * 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.
@@ -16,28 +16,13 @@
  */
 package org.apache.camel.quarkus.component.xslt.it;
 
-import java.util.UUID;
+import org.apache.camel.builder.RouteBuilder;
 
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import io.restassured.http.ContentType;
+public class XsltRoute extends RouteBuilder {
 
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-@QuarkusTest
-class XsltTest {
-
-    @Test
-    public void test() {
-        final String msg = UUID.randomUUID().toString().replace("-", "");
-        RestAssured.given() //
-            .contentType(ContentType.TEXT).body(msg).post("/xslt/post") //
-            .then().statusCode(201);
-
-        Assertions.fail("Add some assertions to " + getClass().getName());
-
-        RestAssured.get("/xslt/get").then().statusCode(200);
+    @Override
+    public void configure() throws Exception {
+        from("direct:start")
+                .to("xslt:transform.xsl");
     }
-
 }
diff --git a/integration-tests/xslt/src/main/resources/transform.xsl b/integration-tests/xslt/src/main/resources/transform.xsl
new file mode 100644
index 0000000..30c5ab4
--- /dev/null
+++ b/integration-tests/xslt/src/main/resources/transform.xsl
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+    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.
+
+-->
+<xsl:stylesheet
+        xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+        version='1.0'>
+
+    <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+    <xsl:template match="/">
+        <transformed subject="{/mail/subject}">
+            <cheese>
+                <xsl:apply-templates select="*|@*"/>
+            </cheese>
+        </transformed>
+    </xsl:template>
+
+    <xsl:template match="*">
+        <xsl:copy>
+            <xsl:copy-of select="attribute::*"/>
+            <xsl:apply-templates/>
+        </xsl:copy>
+    </xsl:template>
+
+</xsl:stylesheet>
diff --git a/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java b/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
index ff5621a..bc1470e 100644
--- a/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
+++ b/integration-tests/xslt/src/test/java/org/apache/camel/quarkus/component/xslt/it/XsltTest.java
@@ -16,13 +16,9 @@
  */
 package org.apache.camel.quarkus.component.xslt.it;
 
-import java.util.UUID;
-
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
-import io.restassured.http.ContentType;
-
-import org.junit.jupiter.api.Assertions;
+import org.hamcrest.xml.HasXPath;
 import org.junit.jupiter.api.Test;
 
 @QuarkusTest
@@ -30,14 +26,8 @@ class XsltTest {
 
     @Test
     public void test() {
-        final String msg = UUID.randomUUID().toString().replace("-", "");
-        RestAssured.given() //
-            .contentType(ContentType.TEXT).body(msg).post("/xslt/post") //
-            .then().statusCode(201);
-
-        Assertions.fail("Add some assertions to " + getClass().getName());
-
-        RestAssured.get("/xslt/get").then().statusCode(200);
+        RestAssured.get("/xslt/get").then().statusCode(200)
+                .body(HasXPath.hasXPath("/transformed/cheese/mail/subject"));
     }
 
 }