< prev index next >

test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathExpressionTest.java

Print this page

        

*** 21,30 **** --- 21,31 ---- * questions. */ package javax.xml.xpath.ptests; + import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths;
*** 39,50 **** 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 static jaxp.library.JAXPTestUtilities.failUnexpected; 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; --- 40,53 ---- 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.JAXPBaseTest; import static org.testng.Assert.assertEquals; + import org.testng.annotations.AfterGroups; + import org.testng.annotations.BeforeGroups; 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;
*** 52,62 **** import org.xml.sax.SAXException; /** * Class containing the test cases for XPathExpression API. */ ! public class XPathExpressionTest { /** * Document object for testing XML file. */ private Document document; --- 55,65 ---- import org.xml.sax.SAXException; /** * Class containing the test cases for XPathExpression API. */ ! public class XPathExpressionTest extends JAXPBaseTest { /** * Document object for testing XML file. */ private Document document;
*** 92,529 **** * @throws SAXException If any parse errors occur. * @throws IOException If operation on xml file failed. */ @BeforeTest public void setup() throws ParserConfigurationException, SAXException, IOException { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(XML_PATH.toFile()); xpath = XPathFactory.newInstance().newXPath(); } /** * Test for evaluate(java.lang.Object item,QName returnType)throws * XPathExpressionException. */ @Test ! public void testCheckXPathExpression01() { ! try { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(document, STRING), "6"); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) throws NPE if input * source is null. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression02() { ! try { xpath.compile(EXPRESSION_NAME_A).evaluate(null, STRING); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) throws NPE if returnType * is null. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression03() { ! try { xpath.compile(EXPRESSION_NAME_A).evaluate(document, null); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * Test for method evaluate(java.lang.Object item,QName returnType).If a * request is made to evaluate the expression in the absence of a context * item, simple expressions, such as "1+1", can be evaluated. */ @Test ! public void testCheckXPathExpression04() { ! try { assertEquals(xpath.compile("1+1").evaluate(document, STRING), "2"); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) throws IAE If returnType * is not one of the types defined in XPathConstants. */ @Test(expectedExceptions = IllegalArgumentException.class) ! public void testCheckXPathExpression05() { ! try { xpath.compile(EXPRESSION_NAME_A).evaluate(document, TEST_QNAME); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) return correct boolean * value if returnType is Boolean. */ @Test ! public void testCheckXPathExpression06() { ! try { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(document, BOOLEAN), true); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) return correct boolean * value if returnType is Boolean. */ @Test ! public void testCheckXPathExpression07() { ! try { assertEquals(xpath.compile(EXPRESSION_NAME_B). evaluate(document, BOOLEAN), false); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) return correct number * value when return type is Double. */ @Test ! public void testCheckXPathExpression08() { ! try { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(document, NUMBER), 6d); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) evaluate an attribute * value which returnType is Node. */ @Test ! public void testCheckXPathExpression09() { ! try { Attr attr = (Attr) xpath.compile(EXPRESSION_NAME_A). evaluate(document, NODE); assertEquals(attr.getValue(), "6"); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item,QName returnType) evaluate an attribute * value which returnType is NodeList. */ @Test ! public void testCheckXPathExpression10() { ! try { NodeList nodeList = (NodeList) xpath.compile(EXPRESSION_NAME_A). evaluate(document, NODESET); Attr attr = (Attr) nodeList.item(0); assertEquals(attr.getValue(), "6"); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * Test for evaluate(java.lang.Object item) when returnType is left off of * the XPath.evaluate method, all expressions are evaluated to a String * value. */ @Test ! public void testCheckXPathExpression11() { ! try { assertEquals(xpath.compile(EXPRESSION_NAME_A).evaluate(document), "6"); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item) throws NPE if expression is null. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression12() { ! try { xpath.compile(null).evaluate(document); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item) when a request is made to evaluate the * expression in the absence of a context item, simple expressions, such as * "1+1", can be evaluated. */ @Test ! public void testCheckXPathExpression13() { ! try { assertEquals(xpath.compile("1+1").evaluate(document), "2"); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(java.lang.Object item) throws NPE if document is null. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression14() { ! try { xpath.compile(EXPRESSION_NAME_A).evaluate(null); - } catch (XPathExpressionException ex) { - failUnexpected(ex); } } /** * valuate(InputSource source) return a string value if return type is * String. ! */ ! @Test ! public void testCheckXPathExpression15() { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is)), "6"); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source) throws NPE if input source is null. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression16() { ! try { xpath.compile(EXPRESSION_NAME_A).evaluate(null); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** ! * evaluate(InputSource source) throws NPE if expression is null ! */ ! @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression17() { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(null).evaluate(new InputSource(is)); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source) throws XPathExpressionException if * returnType is String junk characters. * ! * @throws XPathExpressionException ! */ ! @Test(expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression18() throws XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile("-*&").evaluate(new InputSource(is)); - } catch (IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source) throws XPathExpressionException if * expression is a blank string " ". * ! * @throws XPathExpressionException ! */ ! @Test(expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression19() throws XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(" ").evaluate(new InputSource(is)); - } catch (IOException ex) { - failUnexpected(ex); } } /** * Test for evaluate(InputSource source,QName returnType) returns a string * value if returnType is String. ! */ ! @Test ! public void testCheckXPathExpression20() { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), STRING), "6"); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) throws NPE if source is * null. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression21() { ! try { xpath.compile(EXPRESSION_NAME_A).evaluate(null, STRING); - } catch (XPathExpressionException ex) { - failUnexpected(ex); - } } /** * evaluate(InputSource source,QName returnType) throws NPE if expression is * null. ! */ ! @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression22() { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(null).evaluate(new InputSource(is), STRING); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) throws NPE if returnType is * null. ! */ ! @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression23() { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), null); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) throws * XPathExpressionException if expression is junk characters. * ! * @throws XPathExpressionException ! */ ! @Test(expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression24() throws XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile("-*&").evaluate(new InputSource(is), STRING); - } catch (IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) throws * XPathExpressionException if expression is blank " ". * ! * @throws XPathExpressionException ! */ ! @Test(expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression25() throws XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(" ").evaluate(new InputSource(is), STRING); - } catch (IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) throws * IllegalArgumentException if returnType is not one of the types defined * in XPathConstants. ! */ ! @Test(expectedExceptions = IllegalArgumentException.class) ! public void testCheckXPathExpression26() { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), TEST_QNAME); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) return a correct boolean * value if returnType is Boolean. ! */ ! @Test ! public void testCheckXPathExpression27() { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), BOOLEAN), true); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) return a correct boolean * value if returnType is Boolean. ! */ ! @Test ! public void testCheckXPathExpression28() { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_B). evaluate(new InputSource(is), BOOLEAN), false); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * evaluate(InputSource source,QName returnType) return a correct number * value if returnType is Number. ! */ ! @Test ! public void testCheckXPathExpression29() { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), NUMBER), 6d); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * Test for evaluate(InputSource source,QName returnType) returns a node if * returnType is Node. ! */ ! @Test ! public void testCheckXPathExpression30() { try (InputStream is = Files.newInputStream(XML_PATH)) { Attr attr = (Attr) xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), NODE); assertEquals(attr.getValue(), "6"); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } /** * Test for evaluate(InputSource source,QName returnType) return a node list * if returnType is NodeList. ! */ ! @Test ! public void testCheckXPathExpression31() { 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"); - } catch (XPathExpressionException | IOException ex) { - failUnexpected(ex); } } } --- 95,571 ---- * @throws SAXException If any parse errors occur. * @throws IOException If operation on xml file failed. */ @BeforeTest public void setup() throws ParserConfigurationException, SAXException, IOException { + setPermissions(new FilePermission(XML_PATH.toFile().toString(), "read")); document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(XML_PATH.toFile()); xpath = XPathFactory.newInstance().newXPath(); } /** * Test for evaluate(java.lang.Object item,QName returnType)throws * XPathExpressionException. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression01() throws XPathExpressionException { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(document, STRING), "6"); } /** * evaluate(java.lang.Object item,QName returnType) throws NPE if input * source is null. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression02() throws XPathExpressionException { xpath.compile(EXPRESSION_NAME_A).evaluate(null, STRING); } /** * evaluate(java.lang.Object item,QName returnType) throws NPE if returnType * is null. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression03() throws XPathExpressionException { xpath.compile(EXPRESSION_NAME_A).evaluate(document, null); } /** * Test for method evaluate(java.lang.Object item,QName returnType).If a * request is made to evaluate the expression in the absence of a context * item, simple expressions, such as "1+1", can be evaluated. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression04() throws XPathExpressionException { assertEquals(xpath.compile("1+1").evaluate(document, STRING), "2"); } /** * evaluate(java.lang.Object item,QName returnType) throws IAE If returnType * is not one of the types defined in XPathConstants. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test(expectedExceptions = IllegalArgumentException.class) ! public void testCheckXPathExpression05() throws XPathExpressionException { xpath.compile(EXPRESSION_NAME_A).evaluate(document, TEST_QNAME); } /** * evaluate(java.lang.Object item,QName returnType) return correct boolean * value if returnType is Boolean. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression06() throws XPathExpressionException { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(document, BOOLEAN), true); } /** * evaluate(java.lang.Object item,QName returnType) return correct boolean * value if returnType is Boolean. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression07() throws XPathExpressionException { assertEquals(xpath.compile(EXPRESSION_NAME_B). evaluate(document, BOOLEAN), false); } /** * evaluate(java.lang.Object item,QName returnType) return correct number * value when return type is Double. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression08() throws XPathExpressionException { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(document, NUMBER), 6d); } /** * evaluate(java.lang.Object item,QName returnType) evaluate an attribute * value which returnType is Node. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression09() throws XPathExpressionException { Attr attr = (Attr) xpath.compile(EXPRESSION_NAME_A). evaluate(document, NODE); assertEquals(attr.getValue(), "6"); } /** * evaluate(java.lang.Object item,QName returnType) evaluate an attribute * value which returnType is NodeList. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression10() throws XPathExpressionException { NodeList nodeList = (NodeList) xpath.compile(EXPRESSION_NAME_A). evaluate(document, NODESET); Attr attr = (Attr) nodeList.item(0); assertEquals(attr.getValue(), "6"); } /** * Test for evaluate(java.lang.Object item) when returnType is left off of * the XPath.evaluate method, all expressions are evaluated to a String * value. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression11() throws XPathExpressionException { assertEquals(xpath.compile(EXPRESSION_NAME_A).evaluate(document), "6"); } /** * evaluate(java.lang.Object item) throws NPE if expression is null. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression12() throws XPathExpressionException { xpath.compile(null).evaluate(document); } /** * evaluate(java.lang.Object item) when a request is made to evaluate the * expression in the absence of a context item, simple expressions, such as * "1+1", can be evaluated. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test ! public void testCheckXPathExpression13() throws XPathExpressionException { assertEquals(xpath.compile("1+1").evaluate(document), "2"); } /** * evaluate(java.lang.Object item) throws NPE if document is null. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression14() throws XPathExpressionException { xpath.compile(EXPRESSION_NAME_A).evaluate(null); } + + + /** + * Save system property for restoring. + */ + @BeforeGroups (groups = {"readLocalFiles"}) + public void setFilePermissions() { + setPermissions(new FilePermission(XML_DIR + "/-", + "read")); + } + + /** + * Restore the system property. + */ + @AfterGroups (groups = {"readLocalFiles"}) + public void restoreFilePermissions() { + setPermissions(); } /** * valuate(InputSource source) return a string value if return type is * String. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test (groups = {"readLocalFiles"}) ! public void testCheckXPathExpression15() throws XPathExpressionException, ! IOException { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is)), "6"); } } /** * evaluate(InputSource source) throws NPE if input source is null. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression16() throws XPathExpressionException { xpath.compile(EXPRESSION_NAME_A).evaluate(null); } /** ! * evaluate(InputSource source) throws NPE if expression is null. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression17() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(null).evaluate(new InputSource(is)); } } /** * evaluate(InputSource source) throws XPathExpressionException if * returnType is String junk characters. * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression18() throws XPathExpressionException, ! IOException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile("-*&").evaluate(new InputSource(is)); } } /** * evaluate(InputSource source) throws XPathExpressionException if * expression is a blank string " ". * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression19() throws XPathExpressionException, ! IOException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(" ").evaluate(new InputSource(is)); } } /** * Test for evaluate(InputSource source,QName returnType) returns a string * value if returnType is String. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckXPathExpression20() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), STRING), "6"); } } /** * evaluate(InputSource source,QName returnType) throws NPE if source is * null. + * + * @throws XPathExpressionException If the expression cannot be evaluated. */ @Test(expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression21() throws XPathExpressionException { xpath.compile(EXPRESSION_NAME_A).evaluate(null, STRING); } /** * evaluate(InputSource source,QName returnType) throws NPE if expression is * null. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression22() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(null).evaluate(new InputSource(is), STRING); } } /** * evaluate(InputSource source,QName returnType) throws NPE if returnType is * null. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class) ! public void testCheckXPathExpression23() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), null); } } /** * evaluate(InputSource source,QName returnType) throws * XPathExpressionException if expression is junk characters. * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression24() throws XPathExpressionException, ! IOException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile("-*&").evaluate(new InputSource(is), STRING); } } /** * evaluate(InputSource source,QName returnType) throws * XPathExpressionException if expression is blank " ". * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class) ! public void testCheckXPathExpression25() throws XPathExpressionException, ! IOException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(" ").evaluate(new InputSource(is), STRING); } } /** * evaluate(InputSource source,QName returnType) throws * IllegalArgumentException if returnType is not one of the types defined * in XPathConstants. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}, expectedExceptions = IllegalArgumentException.class) ! public void testCheckXPathExpression26() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { xpath.compile(EXPRESSION_NAME_A).evaluate(new InputSource(is), TEST_QNAME); } } /** * evaluate(InputSource source,QName returnType) return a correct boolean * value if returnType is Boolean. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckXPathExpression27() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), BOOLEAN), true); } } /** * evaluate(InputSource source,QName returnType) return a correct boolean * value if returnType is Boolean. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckXPathExpression28() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_B). evaluate(new InputSource(is), BOOLEAN), false); } } /** * evaluate(InputSource source,QName returnType) return a correct number * value if returnType is Number. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckXPathExpression29() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { assertEquals(xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), NUMBER), 6d); } } /** * Test for evaluate(InputSource source,QName returnType) returns a node if * returnType is Node. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckXPathExpression30() throws IOException, ! XPathExpressionException { try (InputStream is = Files.newInputStream(XML_PATH)) { Attr attr = (Attr) xpath.compile(EXPRESSION_NAME_A). evaluate(new InputSource(is), NODE); assertEquals(attr.getValue(), "6"); } } /** * Test for evaluate(InputSource source,QName returnType) return a node list * if returnType is NodeList. ! * ! * @throws XPathExpressionException If the expression cannot be evaluated. ! * @throws IOException if the file exists but is a directory rather than ! * a regular file, does not exist but cannot be created, or cannot ! * be opened for any other reason. ! */ ! @Test(groups = {"readLocalFiles"}) ! public void testCheckXPathExpression31() throws IOException, ! XPathExpressionException { 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 >