< prev index next >

test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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,29 +21,35 @@
  * questions.
  */
 
 package javax.xml.parsers.ptests;
 
+import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FilePermission;
 import java.io.IOException;
+
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
-import jaxp.library.JAXPFileReadOnlyBaseTest;
+
+import jaxp.library.JAXPTestUtilities;
+
 import org.testng.annotations.DataProvider;
+import org.testng.annotations.Listeners;
 import org.testng.annotations.Test;
 import org.xml.sax.HandlerBase;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * Class contains the test cases for SAXParser API
  */
-public class SAXParserTest extends JAXPFileReadOnlyBaseTest {
+@Listeners({jaxp.library.FilePolicy.class})
+public class SAXParserTest {
     /**
      * Provide SAXParser.
      *
      * @return a data provider contains a SAXParser instance.
      * @throws Exception If any errors occur.

@@ -90,17 +96,11 @@
      * @throws Exception If any errors occur.
      */
     @Test(expectedExceptions = { SAXException.class },
             dataProvider = "parser-provider")
     public void testParse03(SAXParser saxparser) throws Exception {
-        String workingDir = getSystemProperty("user.dir");
-        setPermissions(new FilePermission(workingDir, "read"));
-        try {
             saxparser.parse("", new HandlerBase());
-        } finally {
-            setPermissions();
-        }
     }
 
     /**
      * Test with File null, parsing should fail and throw
      * IllegalArgumentException.

@@ -122,17 +122,11 @@
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
     public void testParse05(SAXParser saxparser) throws Exception {
-        String workingDir = getSystemProperty("user.dir");
-        setPermissions(new FilePermission(workingDir, "read"));
-        try {
             saxparser.parse(new File(""), new HandlerBase());
-        } finally {
-            setPermissions();
-        }
     }
 
     /**
      * Test with input source null, parsing should fail and throw
      * IllegalArgumentException.

@@ -174,27 +168,22 @@
         String uri = null;
         saxparser.parse(uri, new DefaultHandler());
     }
 
     /**
-     * Test with non-existence URI, parsing should fail and throw
-     * SAXException or IOException.
+     * Test with non-existence URI, parsing should fail and throw SAXException
+     * or IOException.
      *
-     * @param saxparser a SAXParser instance.
-     * @throws Exception If any errors occur.
+     * @param saxparser
+     *            a SAXParser instance.
+     * @throws Exception
+     *             If any errors occur.
      */
-    @Test(expectedExceptions = { SAXException.class, IOException.class },
-            dataProvider = "parser-provider")
+    @Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
     public void testParse09(SAXParser saxparser) throws Exception {
-        String workingDir = getSystemProperty("user.dir");
-        setPermissions(new FilePermission(workingDir + "/../-", "read"));
-        String uri = " ";
-        try {
-            saxparser.parse(uri, new DefaultHandler());
-        } finally {
-            setPermissions();
-        }
+        JAXPTestUtilities.tryRunWithTmpPermission(() -> saxparser.parse(" ", new DefaultHandler()),
+                new FilePermission(System.getProperty("user.dir") + "/ ", "read"));
     }
 
     /**
      * Test with empty string as File, parsing should fail and throw
      * SAXException.

@@ -202,18 +191,12 @@
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
     public void testParse10(SAXParser saxparser) throws Exception {
-        String workingDir = getSystemProperty("user.dir");
-        setPermissions(new FilePermission(workingDir, "read"));
         File file = new File("");
-        try {
             saxparser.parse(file, new DefaultHandler());
-        } finally {
-            setPermissions();
-        }
     }
 
     /**
      * Test with File null, parsing should fail and throw
      * IllegalArgumentException.

@@ -246,11 +229,11 @@
      * SAXException.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
+    @Test(expectedExceptions = SAXException.class,
             dataProvider = "parser-provider")
     public void testParse13(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(new File(
                 XML_DIR, "invalid.xml"))) {
             saxparser.parse(instream, new HandlerBase());

@@ -261,11 +244,11 @@
      * Test with a valid in XML file, parser should parse the XML document.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse14(SAXParser saxparser) throws Exception {
         saxparser.parse(new File(XML_DIR, "parsertest.xml"),
                 new HandlerBase());
     }
 

@@ -274,11 +257,11 @@
      * successfully.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse15(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(new File(XML_DIR,
                 "correct.xml"))) {
             saxparser.parse(instream, new HandlerBase());
         }

@@ -289,11 +272,11 @@
      * successfully.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse16(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(
                 new File(XML_DIR, "parsertest.xml"))) {
             saxparser.parse(instream, new HandlerBase(),
                     new File(XML_DIR).toURI().toASCIIString());

@@ -304,11 +287,11 @@
      * Test with proper URI, parser should parse successfully.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse17(SAXParser saxparser) throws Exception {
         File file = new File(XML_DIR, "correct.xml");
         saxparser.parse(file.toURI().toASCIIString(), new HandlerBase());
     }
 

@@ -317,11 +300,11 @@
      * SAXException.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
+    @Test(expectedExceptions = SAXException.class,
             dataProvider = "parser-provider")
     public void testParse18(SAXParser saxparser) throws Exception {
         saxparser.parse(new File(XML_DIR, "valid.xml"), new HandlerBase());
     }
 

@@ -330,11 +313,11 @@
      * parse the XML document.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse19(SAXParser saxparser) throws Exception {
         saxparser.parse(new File(XML_DIR, "correct.xml"), new HandlerBase());
     }
 
     /**

@@ -342,11 +325,11 @@
      * and throw SAXException.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
+    @Test(expectedExceptions = SAXException.class,
             dataProvider = "parser-provider")
     public void testParse20(SAXParser saxparser) throws Exception {
         try(FileInputStream instream = new FileInputStream(new File(XML_DIR,
                 "invalid.xml"))) {
             saxparser.parse(new InputSource(instream), new HandlerBase());

@@ -358,11 +341,11 @@
      * successfully parse the XML document.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse21(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(new File(XML_DIR,
                 "correct.xml"))) {
             saxparser.parse(new InputSource(instream), new HandlerBase());
         }

@@ -373,11 +356,11 @@
      * SAXException.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
+    @Test(expectedExceptions = SAXException.class,
             dataProvider = "parser-provider")
     public void testParse22(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(
                 new File(XML_DIR, "invalid.xml"))) {
             saxparser.parse(instream, new DefaultHandler());

@@ -389,11 +372,11 @@
      * successfully.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse23(SAXParser saxparser) throws Exception {
         DefaultHandler handler = new DefaultHandler();
         saxparser.parse(new File(XML_DIR, "parsertest.xml"), handler);
     }
 

@@ -402,11 +385,11 @@
      * successfully.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse24(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(new File(XML_DIR,
                 "correct.xml"))) {
             DefaultHandler handler = new DefaultHandler();
             saxparser.parse(instream, handler);

@@ -418,11 +401,11 @@
      * successfully.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse25(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(
                 new File(XML_DIR, "parsertest.xml"))) {
             saxparser.parse(instream, new DefaultHandler(),
                 new File(XML_DIR).toURI().toASCIIString());

@@ -433,11 +416,11 @@
      * Test with proper URI, parser should parse successfully.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse26(SAXParser saxparser) throws Exception {
         File file = new File(XML_DIR, "correct.xml");
         saxparser.parse(file.toURI().toASCIIString(), new DefaultHandler());
     }
 

@@ -446,11 +429,11 @@
      * SAXException.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
+    @Test(expectedExceptions = SAXException.class,
             dataProvider = "parser-provider")
     public void testParse27(SAXParser saxparser) throws Exception {
         saxparser.parse(new File(XML_DIR, "valid.xml"), new DefaultHandler());
     }
 

@@ -459,22 +442,22 @@
      * parse the XML document.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse28(SAXParser saxparser) throws Exception {
         saxparser.parse(new File(XML_DIR, "correct.xml"), new DefaultHandler());
     }
 
     /**
      * Test with an invalid XML file, parser should throw SAXException.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
+    @Test(expectedExceptions = SAXException.class,
             dataProvider = "parser-provider")
     public void testParse29(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(
                 new File(XML_DIR, "invalid.xml"))) {
             saxparser.parse(new InputSource(instream), new DefaultHandler());

@@ -485,11 +468,11 @@
      * Test case to parse an XML file that not use namespaces.
      *
      * @param saxparser a SAXParser instance.
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    @Test(dataProvider = "parser-provider")
     public void testParse30(SAXParser saxparser) throws Exception {
         try (FileInputStream instream = new FileInputStream(
                 new File(XML_DIR, "correct.xml"))) {
             saxparser.parse(new InputSource(instream), new DefaultHandler());
         }

@@ -498,11 +481,11 @@
     /**
      * Test case to parse an XML file that uses namespaces.
      *
      * @throws Exception If any errors occur.
      */
-    @Test(groups = {"readLocalFiles"})
+    @Test
     public void testParse31() throws Exception {
         try (FileInputStream instream = new FileInputStream(
                 new File(XML_DIR, "ns4.xml"))) {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setNamespaceAware(true);
< prev index next >