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 2014/08/27 14:31:50 UTC

[5/5] git commit: CAMEL-7753: xslt component - Store warning/errors etc as exchange properties so end users can get hold of those. Now works with camel-saxon also.

CAMEL-7753: xslt component - Store warning/errors etc as exchange properties so end users can get hold of those. Now works with camel-saxon also.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/adeefbc2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/adeefbc2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/adeefbc2

Branch: refs/heads/master
Commit: adeefbc24c188cfe8c221a6ad457a15930622488
Parents: 6ecf83c
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 27 14:22:01 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 27 14:22:01 2014 +0200

----------------------------------------------------------------------
 .../osgi/saxon/SaxonXsltTerminateRouteTest.java | 103 +++++++++++++++++++
 .../camel/itest/osgi/core/xslt/terminate.xsl    |  34 ++++++
 2 files changed, 137 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/adeefbc2/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java
new file mode 100644
index 0000000..8521c73
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/saxon/SaxonXsltTerminateRouteTest.java
@@ -0,0 +1,103 @@
+/**
+ * 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.itest.osgi.saxon;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+import static org.ops4j.pax.exam.OptionUtils.combine;
+
+
+@RunWith(PaxExam.class)
+public class SaxonXsltTerminateRouteTest extends OSGiIntegrationTestSupport {
+
+    private String data = "<staff>\n"
+            + "\n"
+            + "  <programmer>\n"
+            + "    <name>Bugs Bunny</name>\n"
+            + "    <dob>03/21/1970</dob>\n"
+            + "    <age>31</age>\n"
+            + "    <address>4895 Wabbit Hole Road</address>\n"
+            + "    <phone>865-111-1111</phone>\n"
+            + "  </programmer>\n"
+            + "\n"
+            + "  <programmer>\n"
+            + "    <name>Daisy Duck</name>\n"
+            + "    <dob></dob>\n"
+            + "    <age></age>\n"
+            + "    <address>748 Golden Pond</address>\n"
+            + "    <phone>865-222-2222</phone>\n"
+            + "  </programmer>\n"
+            + "\n"
+            + "</staff>";
+
+    @Test
+    public void testXsltTerminate() throws Exception {
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+
+        template.sendBody("direct:start", data);
+
+        assertMockEndpointsSatisfied();
+
+        Exchange out = getMockEndpoint("mock:dead").getReceivedExchanges().get(0);
+        assertNotNull(out);
+        // this exception is just a generic xslt error
+        Exception cause = out.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
+        assertNotNull(cause);
+
+        // we have the xsl termination message as a error property on the exchange as we set terminate=true
+        Exception error = out.getProperty(Exchange.XSLT_ERROR, Exception.class);
+        assertNotNull(error);
+        assertEquals("Error: DOB is an empty string!", error.getMessage());
+    }
+
+    @Configuration
+    public static Option[] configure() {
+        Option[] options = combine(
+                getDefaultCamelKarafOptions(),
+                // using the features to install the other camel components
+                loadCamelFeatures("camel-saxon"));
+
+        return options;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dead"));
+
+                from("direct:start")
+                        .to("xslt:org/apache/camel/itest/osgi/core/xslt/terminate.xsl?saxon=true")
+                        .to("log:foo")
+                        .to("mock:result");
+
+            }
+        };
+    }
+    
+    
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/adeefbc2/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/core/xslt/terminate.xsl
----------------------------------------------------------------------
diff --git a/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/core/xslt/terminate.xsl b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/core/xslt/terminate.xsl
new file mode 100644
index 0000000..d4d9860
--- /dev/null
+++ b/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/core/xslt/terminate.xsl
@@ -0,0 +1,34 @@
+<?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.
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+  <xsl:template match="/">
+    <html>
+      <body>
+        <xsl:for-each select="staff/programmer">
+          <p>Name: <xsl:value-of select="name"/><br />
+            <xsl:if test="dob=''">
+              <xsl:message terminate="yes">Error: DOB is an empty string!</xsl:message>
+            </xsl:if>
+          </p>
+        </xsl:for-each>
+      </body>
+    </html>
+  </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file