< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * 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,44 +21,47 @@
  * questions.
  */
 
 package javax.xml.xpath.ptests;
 
-import java.io.FilePermission;
+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.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertNull;
+
 import java.io.InputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Iterator;
+
 import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
 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.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
+
 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 XPath API.
  */
-public class XPathTest extends JAXPFileReadOnlyBaseTest {
+@Listeners({jaxp.library.FilePolicy.class})
+public class XPathTest {
     /**
      * Document object for testing XML file.
      */
     private Document document;
 

@@ -91,11 +94,10 @@
      * 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_DIR + "-", "read"));
         document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(XML_PATH.toFile());
         xpath = XPathFactory.newInstance().newXPath();
     }
 
     /**

@@ -345,11 +347,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source) return
      * correct value by looking for Node.
      *
      * @throws Exception If any errors occur.
      */
-    @Test (groups = {"readLocalFiles"})
+    @Test 
     public void testCheckXPath22() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is)), "6");
         }
     }

@@ -369,11 +371,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source) throws
      * NPE if String expression is null.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
+    @Test(expectedExceptions = NullPointerException.class)
     public void testCheckXPath24() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate(null, new InputSource(is));
         }
     }

@@ -383,11 +385,11 @@
      * If expression is junk characters, expression cannot be evaluated, should
      * throw XPathExpressionException.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
+    @Test(expectedExceptions = XPathExpressionException.class)
     public void testCheckXPath25() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate("-*&", new InputSource(is));
         }
     }

@@ -396,11 +398,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source) throws
      * XPathExpressionException if expression is blank " ".
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
+    @Test(expectedExceptions = XPathExpressionException.class)
     public void testCheckXPath26() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate(" ", new InputSource(is));
         }
     }

@@ -409,11 +411,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source, QName
      * returnType) returns correct string value which return type is String.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath27() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is), STRING), "6");
         }
     }

@@ -433,11 +435,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source, QName
      * returnType) throws NPE if expression is null.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
+    @Test(expectedExceptions = NullPointerException.class)
     public void testCheckXPath29() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate(null, new InputSource(is), STRING);
         }
     }

@@ -446,11 +448,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source,
      * QName returnType) throws NPE if returnType is null.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
+    @Test(expectedExceptions = NullPointerException.class)
     public void testCheckXPath30() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is), null);
         }
     }

@@ -459,11 +461,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source, QName
      * returnType) throws XPathExpressionException if expression is junk characters.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
+    @Test(expectedExceptions = XPathExpressionException.class)
     public void testCheckXPath31() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate("-*&", new InputSource(is), STRING);
         }
     }

@@ -472,11 +474,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source, QName
      * returnType) throws XPathExpressionException if expression is blank " ".
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = XPathExpressionException.class)
+    @Test(expectedExceptions = XPathExpressionException.class)
     public void testCheckXPath32() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate(" ", new InputSource(is), STRING);
         }
     }

@@ -486,11 +488,11 @@
      * QName returnType) throws IllegalArgumentException if returnType is not
      * one of the types defined in XPathConstants.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = IllegalArgumentException.class)
+    @Test(expectedExceptions = IllegalArgumentException.class)
     public void testCheckXPath33() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is), TEST_QNAME);
         }
     }

@@ -499,11 +501,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source,
      * QName returnType) return correct boolean value if return type is Boolean.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath34() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is),
                 BOOLEAN), true);
         }

@@ -513,11 +515,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source,
      * QName returnType) return correct boolean value if return type is Boolean.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath35() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(xpath.evaluate(EXPRESSION_NAME_B, new InputSource(is),
                 BOOLEAN), false);
         }

@@ -527,11 +529,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source,
      * QName returnType) return correct number value if return type is Number.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath36() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is),
                 NUMBER), 6d);
         }

@@ -541,11 +543,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource source,
      * QName returnType) return correct string value if return type is Node.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath37() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(((Attr)xpath.evaluate(EXPRESSION_NAME_A,
                 new InputSource(is), NODE)).getValue(), "6");
         }

@@ -555,11 +557,11 @@
      * Test for XPath.evaluate(java.lang.String expression, InputSource source,
      * QName returnType) which return type is NodeList.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath38() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             NodeList nodeList = (NodeList)xpath.evaluate(EXPRESSION_NAME_A,
                 new InputSource(is), NODESET);
             assertEquals(((Attr) nodeList.item(0)).getValue(), "6");

@@ -571,11 +573,11 @@
      * QName returnType). If return type is Boolean, should return false as
      * expression is not successful in evaluating to any result.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath52() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(xpath.evaluate(EXPRESSION_NAME_B, new InputSource(is),
                 BOOLEAN), false);
         }

@@ -585,11 +587,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource iSource, QName
      * returnType) returns correct number value which return type is Number.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath53() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(xpath.evaluate(EXPRESSION_NAME_A, new InputSource(is),
                 NUMBER), 6d);
         }

@@ -599,11 +601,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource iSource, QName
      * returnType) returns a node value if returnType is Node.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath54() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             assertEquals(((Attr)xpath.evaluate(EXPRESSION_NAME_A,
                 new InputSource(is), NODE)).getValue(), "6");
         }

@@ -613,11 +615,11 @@
      * XPath.evaluate(java.lang.String expression, InputSource iSource, QName
      * returnType) returns a node list if returnType is NodeList.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testCheckXPath55() throws Exception {
         try (InputStream is = Files.newInputStream(XML_PATH)) {
             NodeList nodeList = (NodeList)xpath.evaluate(EXPRESSION_NAME_A,
                 new InputSource(is), NODESET);
             assertEquals(((Attr) nodeList.item(0)).getValue(), "6");
< prev index next >