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 2010/09/22 07:37:48 UTC

svn commit: r999763 - in /camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml: XPathTransformRouteTest.java XPathTransformTest.java

Author: davsclaus
Date: Wed Sep 22 05:37:48 2010
New Revision: 999763

URL: http://svn.apache.org/viewvc?rev=999763&view=rev
Log:
Added xpath transform unit test.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformRouteTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformTest.java

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformRouteTest.java?rev=999763&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformRouteTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformRouteTest.java Wed Sep 22 05:37:48 2010
@@ -0,0 +1,56 @@
+/**
+ * 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.builder.xml;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Revision$
+ */
+public class XPathTransformRouteTest extends ContextTestSupport {
+
+    public Document replaceMe(Document doc) throws Exception {
+        // replace firstname to contain Servicemix
+        NodeList list = doc.getElementsByTagName("firstname");
+        list.item(0).setTextContent("Servicemix");
+        // return the changed document
+        return doc;
+    }
+
+    public void testXPathTransform() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("<root><firstname>Servicemix</firstname><lastname>Camel</lastname></root>");
+
+        template.sendBody("direct:start", "<root><firstname>Apache</firstname><lastname>Camel</lastname></root>");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").bean(XPathTransformRouteTest.class, "replaceMe").to("log:result", "mock:result");
+            }
+        };
+    }
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformTest.java?rev=999763&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTransformTest.java Wed Sep 22 05:37:48 2010
@@ -0,0 +1,42 @@
+/**
+ * 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.builder.xml;
+
+import org.apache.camel.ContextTestSupport;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Revision$
+ */
+public class XPathTransformTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    public void testXPathTransform() throws Exception {
+        Document doc = context.getTypeConverter().convertTo(Document.class, "<root><firstname>Apache</firstname><lastname>Camel</lastname></root>");
+        NodeList list = XPathBuilder.xpath("/root/firstname", NodeList.class).evaluate(context, doc, NodeList.class);
+        assertNotNull(list);
+        list.item(0).setTextContent("Servicemix");
+
+        String out = context.getTypeConverter().convertTo(String.class, doc);
+        assertEquals("<root><firstname>Servicemix</firstname><lastname>Camel</lastname></root>", out);
+    }
+}