< prev index next >
test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathExpressionTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 21,60 ****
* questions.
*/
package javax.xml.xpath.ptests;
! import java.io.FilePermission;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
- import static javax.xml.xpath.XPathConstants.BOOLEAN;
- import static javax.xml.xpath.XPathConstants.NODE;
- import static javax.xml.xpath.XPathConstants.NODESET;
- import static javax.xml.xpath.XPathConstants.NUMBER;
- import static javax.xml.xpath.XPathConstants.STRING;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
! import static javax.xml.xpath.ptests.XPathTestConst.XML_DIR;
! import jaxp.library.JAXPFileReadOnlyBaseTest;
! import static org.testng.Assert.assertEquals;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/**
* Class containing the test cases for XPathExpression API.
*/
! public class XPathExpressionTest extends JAXPFileReadOnlyBaseTest {
/**
* Document object for testing XML file.
*/
private Document document;
--- 21,63 ----
* questions.
*/
package javax.xml.xpath.ptests;
! import static javax.xml.xpath.XPathConstants.BOOLEAN;
! import static javax.xml.xpath.XPathConstants.NODE;
! import static javax.xml.xpath.XPathConstants.NODESET;
! import static javax.xml.xpath.XPathConstants.NUMBER;
! import static javax.xml.xpath.XPathConstants.STRING;
! import static javax.xml.xpath.ptests.XPathTestConst.XML_DIR;
! import static org.testng.Assert.assertEquals;
!
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
!
import org.testng.annotations.BeforeTest;
+ import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/**
* Class containing the test cases for XPathExpression API.
*/
! @Listeners({jaxp.library.FilePolicy.class})
! public class XPathExpressionTest {
/**
* Document object for testing XML file.
*/
private Document document;
*** 87,97 ****
* Create Document object and XPath object for every time
* @throws Exception If any errors occur.
*/
@BeforeTest
public void setup() throws Exception {
- setPermissions(new FilePermission(XML_PATH.toFile().toString(), "read"));
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(XML_PATH.toFile());
xpath = XPathFactory.newInstance().newXPath();
}
/**
--- 90,99 ----
*** 262,272 ****
* valuate(InputSource source) return a string value if return type is
* String.
*
* @throws Exception If any errors occur.
*/
! @Test (groups = {"readLocalFiles"})
public void testCheckXPathExpression15() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is)), "6");
}
--- 264,274 ----
* valuate(InputSource source) return a string value if return type is
* String.
*
* @throws Exception If any errors occur.
*/
! @Test
public void testCheckXPathExpression15() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is)), "6");
}
*** 285,295 ****
/**
* evaluate(InputSource source) throws NPE if expression is null.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
public void testCheckXPathExpression17() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(null).evaluate(new InputSource(is));
}
}
--- 287,297 ----
/**
* evaluate(InputSource source) throws NPE if expression is null.
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = NullPointerException.class)
public void testCheckXPathExpression17() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(null).evaluate(new InputSource(is));
}
}
*** 298,308 ****
* evaluate(InputSource source) throws XPathExpressionException if
* returnType is String junk characters.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression18() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile("-*&").evaluate(new InputSource(is));
}
}
--- 300,310 ----
* evaluate(InputSource source) throws XPathExpressionException if
* returnType is String junk characters.
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression18() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile("-*&").evaluate(new InputSource(is));
}
}
*** 311,321 ****
* evaluate(InputSource source) throws XPathExpressionException if
* expression is a blank string " ".
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression19() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(" ").evaluate(new InputSource(is));
}
}
--- 313,323 ----
* evaluate(InputSource source) throws XPathExpressionException if
* expression is a blank string " ".
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression19() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(" ").evaluate(new InputSource(is));
}
}
*** 324,334 ****
* Test for evaluate(InputSource source,QName returnType) returns a string
* value if returnType is String.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"})
public void testCheckXPathExpression20() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), STRING), "6");
}
--- 326,336 ----
* Test for evaluate(InputSource source,QName returnType) returns a string
* value if returnType is String.
*
* @throws Exception If any errors occur.
*/
! @Test
public void testCheckXPathExpression20() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), STRING), "6");
}
*** 349,359 ****
* evaluate(InputSource source,QName returnType) throws NPE if expression is
* null.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
public void testCheckXPathExpression22() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(null).evaluate(new InputSource(is), STRING);
}
}
--- 351,361 ----
* evaluate(InputSource source,QName returnType) throws NPE if expression is
* null.
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = NullPointerException.class)
public void testCheckXPathExpression22() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(null).evaluate(new InputSource(is), STRING);
}
}
*** 362,372 ****
* evaluate(InputSource source,QName returnType) throws NPE if returnType is
* null.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
public void testCheckXPathExpression23() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), null);
}
}
--- 364,374 ----
* evaluate(InputSource source,QName returnType) throws NPE if returnType is
* null.
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = NullPointerException.class)
public void testCheckXPathExpression23() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), null);
}
}
*** 375,385 ****
* evaluate(InputSource source,QName returnType) throws
* XPathExpressionException if expression is junk characters.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression24() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile("-*&").evaluate(new InputSource(is), STRING);
}
}
--- 377,387 ----
* evaluate(InputSource source,QName returnType) throws
* XPathExpressionException if expression is junk characters.
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression24() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile("-*&").evaluate(new InputSource(is), STRING);
}
}
*** 388,398 ****
* evaluate(InputSource source,QName returnType) throws
* XPathExpressionException if expression is blank " ".
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression25() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(" ").evaluate(new InputSource(is), STRING);
}
}
--- 390,400 ----
* evaluate(InputSource source,QName returnType) throws
* XPathExpressionException if expression is blank " ".
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = XPathExpressionException.class)
public void testCheckXPathExpression25() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(" ").evaluate(new InputSource(is), STRING);
}
}
*** 402,412 ****
* IllegalArgumentException if returnType is not one of the types defined
* in XPathConstants.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = IllegalArgumentException.class)
public void testCheckXPathExpression26() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), TEST_QNAME);
}
}
--- 404,414 ----
* IllegalArgumentException if returnType is not one of the types defined
* in XPathConstants.
*
* @throws Exception If any errors occur.
*/
! @Test(expectedExceptions = IllegalArgumentException.class)
public void testCheckXPathExpression26() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), TEST_QNAME);
}
}
*** 415,425 ****
* evaluate(InputSource source,QName returnType) return a correct boolean
* value if returnType is Boolean.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"})
public void testCheckXPathExpression27() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), BOOLEAN), true);
}
--- 417,427 ----
* evaluate(InputSource source,QName returnType) return a correct boolean
* value if returnType is Boolean.
*
* @throws Exception If any errors occur.
*/
! @Test
public void testCheckXPathExpression27() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), BOOLEAN), true);
}
*** 429,439 ****
* evaluate(InputSource source,QName returnType) return a correct boolean
* value if returnType is Boolean.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"})
public void testCheckXPathExpression28() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_B).
evaluate(new InputSource(is), BOOLEAN), false);
}
--- 431,441 ----
* evaluate(InputSource source,QName returnType) return a correct boolean
* value if returnType is Boolean.
*
* @throws Exception If any errors occur.
*/
! @Test
public void testCheckXPathExpression28() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_B).
evaluate(new InputSource(is), BOOLEAN), false);
}
*** 443,453 ****
* evaluate(InputSource source,QName returnType) return a correct number
* value if returnType is Number.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"})
public void testCheckXPathExpression29() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), NUMBER), 6d);
}
--- 445,455 ----
* evaluate(InputSource source,QName returnType) return a correct number
* value if returnType is Number.
*
* @throws Exception If any errors occur.
*/
! @Test
public void testCheckXPathExpression29() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
assertEquals(xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), NUMBER), 6d);
}
*** 457,467 ****
* Test for evaluate(InputSource source,QName returnType) returns a node if
* returnType is Node.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"})
public void testCheckXPathExpression30() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
Attr attr = (Attr) xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), NODE);
assertEquals(attr.getValue(), "6");
--- 459,469 ----
* Test for evaluate(InputSource source,QName returnType) returns a node if
* returnType is Node.
*
* @throws Exception If any errors occur.
*/
! @Test
public void testCheckXPathExpression30() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
Attr attr = (Attr) xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), NODE);
assertEquals(attr.getValue(), "6");
*** 472,482 ****
* Test for evaluate(InputSource source,QName returnType) return a node list
* if returnType is NodeList.
*
* @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"})
public void testCheckXPathExpression31() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
NodeList nodeList = (NodeList) xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), NODESET);
assertEquals(((Attr) nodeList.item(0)).getValue(), "6");
--- 474,484 ----
* Test for evaluate(InputSource source,QName returnType) return a node list
* if returnType is NodeList.
*
* @throws Exception If any errors occur.
*/
! @Test
public void testCheckXPathExpression31() throws Exception {
try (InputStream is = Files.newInputStream(XML_PATH)) {
NodeList nodeList = (NodeList) xpath.compile(EXPRESSION_NAME_A).
evaluate(new InputSource(is), NODESET);
assertEquals(((Attr) nodeList.item(0)).getValue(), "6");
< prev index next >