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/05/12 06:24:48 UTC

svn commit: r943369 - in /camel/trunk: camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java

Author: davsclaus
Date: Wed May 12 04:24:47 2010
New Revision: 943369

URL: http://svn.apache.org/viewvc?rev=943369&view=rev
Log:
CAMEL-2669: Improved NodeList to String convertion. So it include the XML tags etc as you would expect.

Modified:
    camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java
    camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java?rev=943369&r1=943368&r2=943369&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java Wed May 12 04:24:47 2010
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
 import javax.xml.xpath.XPathFunctionResolver;
 
 import org.w3c.dom.Document;
@@ -410,4 +411,17 @@ public class XPathTest extends ContextTe
         assertEquals("Claus", s);
     }
 
+    public void testXPathString() throws Exception {
+        XPathBuilder builder = XPathBuilder.xpath("foo/bar");
+
+        // will evaluate as XPathConstants.NODESET and have Camel convert that to String
+        // this should return the String incl. xml tags
+        String name = builder.evaluate(context, "<foo><bar id=\"1\">cheese</bar></foo>", String.class);
+        assertEquals("<bar id=\"1\">cheese</bar>", name);
+
+        // will evaluate using XPathConstants.STRING which just return the text content (eg like text())
+        name = builder.evaluate(context, "<foo><bar id=\"1\">cheese</bar></foo>");
+        assertEquals("cheese", name);
+    }
+
 }

Modified: camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java?rev=943369&r1=943368&r2=943369&view=diff
==============================================================================
--- camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java (original)
+++ camel/trunk/components/camel-saxon/src/test/java/org/apache/camel/builder/saxon/XPathTest.java Wed May 12 04:24:47 2010
@@ -33,10 +33,13 @@ public class XPathTest extends CamelTest
         XPathFactory fac = new XPathFactoryImpl();
         XPathBuilder builder = XPathBuilder.xpath("foo/bar").factory(fac);
 
-        String name = builder.evaluate(context, "<foo><bar>cheese</bar></foo>", String.class);
-        assertEquals("cheese", name);
+        // will evaluate as XPathConstants.NODESET and have Camel convert that to String
+        // this should return the String incl. xml tags
+        String name = builder.evaluate(context, "<foo><bar id=\"1\">cheese</bar></foo>", String.class);
+        assertEquals("<bar id=\"1\">cheese</bar>", name);
 
-        name = builder.evaluate(context, "<foo><bar>cheese</bar></foo>");
+        // will evaluate using XPathConstants.STRING which just return the text content (eg like text())
+        name = builder.evaluate(context, "<foo><bar id=\"1\">cheese</bar></foo>");
         assertEquals("cheese", name);
     }