Java Code Examples for javax.xml.xpath.XPath#evaluateExpression()

The following examples show how to use javax.xml.xpath.XPath#evaluateExpression() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "document")
public void test05(XPath xpath, Document doc) throws XPathExpressionException {
    double result1 = xpath.evaluateExpression("count(/Customers/Customer)", doc, Double.class);
    assertTrue(result1 == 3.0);
    int result2 = xpath.evaluateExpression("count(/Customers/Customer)", doc, Integer.class);
    assertTrue(result2 == 3);
    long result3 = xpath.evaluateExpression("count(/Customers/Customer)", doc, Long.class);
    assertTrue(result3 == 3);
}
 
Example 2
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "document")
public void test08(XPath xpath, Document doc) throws XPathExpressionException {
    XPathNodes nodes = xpath.evaluateExpression("/Customers/Customer", doc, XPathNodes.class);
    assertTrue(nodes.size() == 3);
    for (Node n : nodes) {
        assertEquals(n.getLocalName(), "Customer");
    }
}
 
Example 3
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test09(XPath xpath, Document doc) throws XPathExpressionException {
    Node n = xpath.evaluateExpression("/Customers/Customer[@id=3]", doc, Node.class);
    assertEquals(n.getLocalName(), "Customer");
}
 
Example 4
Source File: XPathTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "hasContextDependency", expectedExceptions = XPathExpressionException.class)
public void testHasContextDependency2(String expression, Object item) throws XPathExpressionException {
    XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.evaluateExpression(expression, item, String.class);
}
 
Example 5
Source File: XPathTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "noContextDependency")
public void testNoContextDependency2(String expression, Object item) throws XPathExpressionException {
    XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.evaluateExpression(expression, item, String.class);
}
 
Example 6
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test15(XPath xpath, Document doc) throws XPathExpressionException {
    XPathEvaluationResult<?> result = xpath.evaluateExpression("/Customers/Customer[@id=3]", doc);
    verifyResult(result, "Customer");
}
 
Example 7
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test14(XPath xpath, Document doc) throws XPathExpressionException {
    XPathEvaluationResult<?> result = xpath.evaluateExpression("/Customers/Customer", doc);
    verifyResult(result, "Customer");
}
 
Example 8
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test13(XPath xpath, Document doc) throws XPathExpressionException {
    XPathEvaluationResult<?> result = xpath.evaluateExpression(
            "string(/Customers/Customer[@id=3]/Phone/text())", doc, XPathEvaluationResult.class);
    verifyResult(result, "3333333333");
}
 
Example 9
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test12(XPath xpath, Document doc) throws XPathExpressionException {
    XPathEvaluationResult<?> result = xpath.evaluateExpression("count(/Customers/Customer)", doc);
    verifyResult(result, 3.0);
}
 
Example 10
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test11(XPath xpath, Document doc) throws XPathExpressionException {
    XPathEvaluationResult<?> result = xpath.evaluateExpression("boolean(/Customers/Customer[@id=3])", doc);
    verifyResult(result, true);
}
 
Example 11
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document", expectedExceptions = IllegalArgumentException.class)
public void test10(XPath xpath, Document doc) throws XPathExpressionException {
    File n = xpath.evaluateExpression("/Customers/Customer[@id=3]", doc, File.class);
}
 
Example 12
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
public void test01(XPath xpath) throws XPathExpressionException {
    double result = xpath.evaluateExpression(null, (Object) null, Double.class);
}
 
Example 13
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test07(XPath xpath, Document doc) throws XPathExpressionException {
    String result1 = xpath.evaluateExpression("string(/Customers/Customer[@id=3]/Phone/text())", doc, String.class);
    assertTrue(result1.equals("3333333333"));
}
 
Example 14
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "invalidNumericTypes", expectedExceptions = IllegalArgumentException.class)
public void test06(XPath xpath, Class<Number> type) throws XPathExpressionException {
    xpath.evaluateExpression("1+1", (Object) null, type);
}
 
Example 15
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "document")
public void test04(XPath xpath, Document doc) throws XPathExpressionException {
    boolean result1 = xpath.evaluateExpression("boolean(/Customers/Customer[@id=3])", doc, Boolean.class);
    assertTrue(result1);
}
 
Example 16
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "xpath")
public void test03(XPath xpath) throws XPathExpressionException {
    int result = xpath.evaluateExpression("1+1", (Object) null, Integer.class);
    assertTrue(result == 2);
}
 
Example 17
Source File: XPathAnyTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
public void test02(XPath xpath) throws XPathExpressionException {
    double result = xpath.evaluateExpression("1+1", (Object) null, null);
}