From 134ee780479c544697e871f21a4a96996b95d64e Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 23 Jul 2022 15:32:28 +0100 Subject: [PATCH 1/2] Update XPathUtilTest.java --- .../src/test/java/org/apache/jmeter/util/XPathUtilTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java b/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java index c258cba5d31..89f1f4dc765 100644 --- a/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java +++ b/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java @@ -19,6 +19,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -251,7 +252,12 @@ public void testPutValuesForXPathInList() assertEquals("two", matchs.get(1)); matchs=new ArrayList<>(); XPathUtil.putValuesForXPathInList(testDoc, xpathquery, matchs, false); + assertEquals(2, matchs.size()); assertEquals("one", matchs.get(0)); assertEquals("two", matchs.get(1)); + matchs=new ArrayList<>(); + XPathUtil.putValuesForXPathInList(testDoc, "/book/a", matchs, false); + assertEquals(1, matchs.size()); + assertNull(matchs.get(0)); } } From d84e7fdf91d887d51c40933029bdd771e8221d45 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 23 Jul 2022 16:13:11 +0100 Subject: [PATCH 2/2] Update XPathUtilTest.java --- .../org/apache/jmeter/util/XPathUtilTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java b/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java index 89f1f4dc765..dd02987a6f5 100644 --- a/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java +++ b/src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java @@ -45,6 +45,8 @@ import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import net.sf.saxon.s9api.Processor; @@ -260,4 +262,19 @@ public void testPutValuesForXPathInList() assertEquals(1, matchs.size()); assertNull(matchs.get(0)); } + + @Test + public void testSelectNodeList() throws ParserConfigurationException, SAXException, IOException, TidyException, TransformerException { + String responseData = "onetwo"; + Document testDoc = XPathUtil.makeDocument( + new ByteArrayInputStream(responseData.getBytes(StandardCharsets.UTF_8)), false, false, false, false, + false, false, false, false, false); + String xpathquery = "/book/page"; + NodeList nodeList = XPathUtil.selectNodeList(testDoc, xpathquery); + assertEquals(2, nodeList.getLength()); + Element e0 = (Element) nodeList.item(0); + Element e1 = (Element) nodeList.item(1); + assertEquals("one", e0.getTextContent()); + assertEquals("two", e1.getTextContent()); + } }