Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/core/src/test/java/org/apache/jmeter/util/XPathUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,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;
Expand Down Expand Up @@ -251,7 +254,27 @@ public void testPutValuesForXPathInList()
assertEquals("<page>two</page>", 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));
}

@Test
public void testSelectNodeList() throws ParserConfigurationException, SAXException, IOException, TidyException, TransformerException {
String responseData = "<book><page>one</page><page>two</page><empty></empty><a><b></b></a></book>";
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());
}
}