jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1802078 - in /jmeter/trunk: bin/testfiles/XPathTest2.xml src/core/org/apache/jmeter/util/XPathUtil.java src/functions/org/apache/jmeter/functions/XPathFileContainer.java test/src/org/apache/jmeter/functions/PackageTest.java xdocs/changes.xml
Date Sun, 16 Jul 2017 18:08:47 GMT
Author: pmouawad
Date: Sun Jul 16 18:08:47 2017
New Revision: 1802078

URL: http://svn.apache.org/viewvc?rev=1802078&view=rev
Log:
Bug 61260 - __XPath function returns null despite xpath checker founds matches
Bugzilla Id: 61260

Added:
    jmeter/trunk/bin/testfiles/XPathTest2.xml   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java
    jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java
    jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java
    jmeter/trunk/xdocs/changes.xml

Added: jmeter/trunk/bin/testfiles/XPathTest2.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/testfiles/XPathTest2.xml?rev=1802078&view=auto
==============================================================================
--- jmeter/trunk/bin/testfiles/XPathTest2.xml (added)
+++ jmeter/trunk/bin/testfiles/XPathTest2.xml Sun Jul 16 18:08:47 2017
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<note>
+  <to>Tove</to>
+  <from>Jani</from>
+  <heading>Reminder</heading>
+  <body>Don't forget me this weekend!</body>
+</note>
\ No newline at end of file

Propchange: jmeter/trunk/bin/testfiles/XPathTest2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/bin/testfiles/XPathTest2.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java?rev=1802078&r1=1802077&r2=1802078&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/XPathUtil.java Sun Jul 16 18:08:47 2017
@@ -274,11 +274,11 @@ public class XPathUtil {
     }
     
     /**
-     * Return value for node
+     * Return value for node including node element
      * @param node Node
      * @return String
      */
-    private static String getValueForNode(Node node) {
+    private static String getNodeContent(Node node) {
         StringWriter sw = new StringWriter();
         try {
             Transformer t = TransformerFactory.newInstance().newTransformer();
@@ -289,6 +289,20 @@ public class XPathUtil {
         }
         return sw.toString();
     }
+    
+    /**
+     * @param node {@link Node}
+     * @return String content of node
+     */
+    public static String getValueForNode(Node node) {
+        // elements have empty nodeValue, but we are usually interested in their content
+        final Node firstChild = node.getFirstChild();
+        if (firstChild != null) {
+            return firstChild.getNodeValue();
+        } else {
+            return node.getNodeValue();
+        }
+    }
 
     /**
      * Extract NodeList using expression
@@ -347,15 +361,9 @@ public class XPathUtil {
                 }
                 if ( match instanceof Element ){
                     if (fragment){
-                        val = getValueForNode(match);
+                        val = getNodeContent(match);
                     } else {
-                        // elements have empty nodeValue, but we are usually interested in
their content
-                        final Node firstChild = match.getFirstChild();
-                        if (firstChild != null) {
-                            val = firstChild.getNodeValue();
-                        } else {
-                            val = match.getNodeValue(); // TODO is this correct?
-                        }
+                        val = getValueForNode(match);
                     }
                 } else {
                    val = match.getNodeValue();

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java?rev=1802078&r1=1802077&r2=1802078&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathFileContainer.java Sun Jul
16 18:08:47 2017
@@ -83,7 +83,7 @@ public class XPathFileContainer {
     }
 
     public String getXPathString(int num) {
-        return nodeList.item(num).getNodeValue();
+        return XPathUtil.getValueForNode(nodeList.item(num));
     }
 
     /**

Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java?rev=1802078&r1=1802077&r2=1802078&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/PackageTest.java Sun Jul 16 18:08:47
2017
@@ -97,6 +97,7 @@ public class PackageTest extends JMeterT
         xpath.addTest(new PackageTest("XPathtestNull"));
         xpath.addTest(new PackageTest("XPathtestrowNum"));
         xpath.addTest(new PackageTest("XPathEmpty"));
+        xpath.addTest(new PackageTest("XPathFile"));
         xpath.addTest(new PackageTest("XPathFile1"));
         xpath.addTest(new PackageTest("XPathFile2"));
         xpath.addTest(new PackageTest("XPathNoFile"));
@@ -348,6 +349,17 @@ public class PackageTest extends JMeterT
         String val=xp.execute();
         assertEquals("",val); // TODO - should check that error has been logged...
     }
+
+    public void XPathFile() throws Exception{
+        XPath xp = setupXPath("testfiles/XPathTest2.xml","note/body");
+        assertEquals("Don't forget me this weekend!",xp.execute());
+        
+        xp = setupXPath("testfiles/XPathTest2.xml","//note2");
+        assertEquals("", xp.execute());
+        
+        xp = setupXPath("testfiles/XPathTest2.xml","//note/to");
+        assertEquals("Tove", xp.execute());
+    }
     
     public void XPathFile1() throws Exception{
         XPath xp = setupXPath("testfiles/XPathTest.xml","//user/@username");

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1802078&r1=1802077&r2=1802078&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Sun Jul 16 18:08:47 2017
@@ -182,6 +182,7 @@ Summary
 <h3>Functions</h3>
 <ul>
     <li><bug>61258</bug>StringFromFile function is mentioned twice in the
Function helper dialog</li>
+    <li><bug>61260</bug><code>__XPath</code> function returns
null despite xpath checker founds matches</li>
 </ul>
 
 <h3>I18N</h3>



Mime
View raw message