< prev index next >

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

Print this page

        

@@ -26,84 +26,116 @@
 import static jaxp.library.JAXPTestUtilities.failUnexpected;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
 import java.io.File;
+import java.io.FilePermission;
 import java.io.IOException;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import static javax.xml.parsers.ptests.TestUtils.XML_DIR;
+import jaxp.library.JAXPBaseTest;
+import org.testng.annotations.AfterGroups;
+import org.testng.annotations.BeforeGroups;
 
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 import org.xml.sax.SAXException;
 
 /**
  * Class contains the test cases for SAXParser API
  */
-public class SAXParserTest03 {
+public class SAXParserTest03 extends JAXPBaseTest {
 
     /**
      * Provide SAXParserFactory.
      *
-     * @throws Exception
+     * @return a dimensional contains.
      */
     @DataProvider(name = "input-provider")
     public Object[][] getFactory() {
         SAXParserFactory spf = SAXParserFactory.newInstance();
         spf.setValidating(true);
-        MyErrorHandler handler = MyErrorHandler.newInstance();
-        return new Object[][] { { spf, handler } };
+        return new Object[][] { { spf, MyErrorHandler.newInstance() } };
+    }
+    
+    /**
+     * 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();
     }
 
     /**
      * parsertest.xml holds a valid document. This method tests the validating
      * parser.
+     * 
+     * @param spf a Parser factory.
+     * @param handler an error handler for capturing events.
+     * @throws SAXException If any parse errors occur.
+     * @throws ParserConfigurationException in case of ServiceConfigurationError
+     * service configuration error or if the implementation is not available or
+     * cannot be instantiated.
+     * @throws IOException if any I/O operation error.
      */
-    @Test(dataProvider = "input-provider")
-    public void testParseValidate01(SAXParserFactory spf, MyErrorHandler handler) {
-        try {
-            SAXParser saxparser = spf.newSAXParser();
-            saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
-            assertFalse(handler.errorOccured);
-        } catch (ParserConfigurationException | SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
+    public void testParseValidate01(SAXParserFactory spf, MyErrorHandler handler) 
+            throws ParserConfigurationException, SAXException, IOException {
+            spf.newSAXParser().parse(new File(XML_DIR, "parsertest.xml"), handler);
+            assertFalse(handler.isErrorOccured());
     }
 
     /**
      * validns.xml holds a valid document with XML namespaces in it. This method
      * tests the Validating parser with namespace processing on.
+     * 
+     * @param spf a Parser factory.
+     * @param handler an error handler for capturing events.
+     * @throws SAXException If any parse errors occur.
+     * @throws ParserConfigurationException in case of ServiceConfigurationError
+     * service configuration error or if the implementation is not available or
+     * cannot be instantiated.
+     * @throws IOException if any I/O operation error.
      */
-    @Test(dataProvider = "input-provider")
-    public void testParseValidate02(SAXParserFactory spf, MyErrorHandler handler) {
-        try {
+    @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
+    public void testParseValidate02(SAXParserFactory spf, MyErrorHandler handler) 
+            throws ParserConfigurationException, SAXException, IOException {
             spf.setNamespaceAware(true);
-            SAXParser saxparser = spf.newSAXParser();
-            saxparser.parse(new File(TestUtils.XML_DIR, "validns.xml"), handler);
-            assertFalse(handler.errorOccured);
-        } catch (ParserConfigurationException | SAXException | IOException e) {
-            failUnexpected(e);
-        }
+            spf.newSAXParser().parse(new File(XML_DIR, "validns.xml"), handler);
+            assertFalse(handler.isErrorOccured());
     }
 
     /**
      * invalidns.xml holds an invalid document with XML namespaces in it. This
      * method tests the validating parser with namespace processing on. It
      * should throw validation error.
+     * 
+     * @param spf a Parser factory.
+     * @param handler an error handler for capturing events.
      */
-    @Test(dataProvider = "input-provider")
+    @Test(groups = {"readLocalFiles"}, dataProvider = "input-provider")
     public void testParseValidate03(SAXParserFactory spf, MyErrorHandler handler) {
         try {
             spf.setNamespaceAware(true);
             SAXParser saxparser = spf.newSAXParser();
-            saxparser.parse(new File(TestUtils.XML_DIR, "invalidns.xml"), handler);
+            saxparser.parse(new File(XML_DIR, "invalidns.xml"), handler);
             failUnexpected(new RuntimeException());
         } catch (ParserConfigurationException | SAXException | IOException e) {
             if (e instanceof SAXException) {
-                assertTrue(handler.errorOccured);
+                assertTrue(handler.isErrorOccured());
             }
         }
     }
 
 }
< prev index next >