< prev index next >

test/javax/xml/jaxp/functional/org/xml/sax/ptests/XMLFilterTest.java

Print this page

        

@@ -21,17 +21,20 @@
  * questions.
  */
 package org.xml.sax.ptests;
 
 import java.io.FileInputStream;
+import java.io.FilePermission;
 import java.io.IOException;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
-import static jaxp.library.JAXPTestUtilities.failUnexpected;
+import jaxp.library.JAXPBaseTest;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
+import org.testng.annotations.AfterGroups;
+import org.testng.annotations.BeforeGroups;
 import org.testng.annotations.Test;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.SAXNotSupportedException;

@@ -40,11 +43,11 @@
 import static org.xml.sax.ptests.SAXTestConst.XML_DIR;
 
 /**
  * Unit test for XMLFilter.
  */
-public class XMLFilterTest {
+public class XMLFilterTest extends JAXPBaseTest {
     /**
      * name spaces constant.
      */
     private static final String NAMESPACES =
                 "http://xml.org/sax/features/namespaces";

@@ -127,43 +130,40 @@
         new XMLFilterImpl().setErrorHandler(null);
     }
 
     /**
      * By default true is expected get namespaces feature.
-     * @throws SAXException
+     * 
+     * @throws SAXException If there is a problem processing the document.
+     * @throws ParserConfigurationException if a DocumentBuilder cannot be 
+     *         created which satisfies the configuration requested.
      */
     @Test
-    public void getFeature01() throws SAXException {
-        try {
+    public void getFeature01() throws SAXException, ParserConfigurationException {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setNamespaceAware(true);
             XMLReader xmlReader = spf.newSAXParser().getXMLReader();
 
             XMLFilterImpl xmlFilter = new XMLFilterImpl();
             xmlFilter.setParent(xmlReader);
             assertTrue(xmlFilter.getFeature(NAMESPACES));
-        } catch (SAXException | ParserConfigurationException ex) {
-            failUnexpected(ex);
-        }
     }
 
     /**
      * By default false is expected get namespaces-prefix feature.
+     * 
+     * @throws SAXException If there is a problem processing the document.
+     * @throws ParserConfigurationException if a DocumentBuilder cannot be 
+     *         created which satisfies the configuration requested.
      */
     @Test
-    public void getFeature02() {
-        try {
+    public void getFeature02() throws ParserConfigurationException, SAXException {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setNamespaceAware(true);
-            XMLReader xmlReader = spf.newSAXParser().getXMLReader();
-
             XMLFilterImpl xmlFilter = new XMLFilterImpl();
-            xmlFilter.setParent(xmlReader);
+        xmlFilter.setParent(spf.newSAXParser().getXMLReader());
             assertFalse(xmlFilter.getFeature(NAMESPACE_PREFIXES));
-        } catch (SAXException | ParserConfigurationException ex) {
-            failUnexpected(ex);
-        }
     }
 
     /**
      * SAXNotRecognizedException is expected when get a feature by an invalid
      * feature name.

@@ -180,88 +180,103 @@
     }
 
     /**
      * Set namespaces feature to a value to XMLFilter. it's expected same when
      * obtain it again.
+     * 
+     * @throws SAXException If there is a problem processing the document.
+     * @throws ParserConfigurationException if a DocumentBuilder cannot be 
+     *         created which satisfies the configuration requested.
      */
     @Test
-    public void setFeature01() {
-        try {
+    public void setFeature01() throws ParserConfigurationException, SAXException {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setNamespaceAware(true);
-            XMLReader xmlReader = spf.newSAXParser().getXMLReader();
 
             XMLFilterImpl xmlFilter = new XMLFilterImpl();
-            xmlFilter.setParent(xmlReader);
+        xmlFilter.setParent(spf.newSAXParser().getXMLReader());
             xmlFilter.setFeature(NAMESPACES, false);
             assertFalse(xmlFilter.getFeature(NAMESPACES));
             xmlFilter.setFeature(NAMESPACES, true);
             assertTrue(xmlFilter.getFeature(NAMESPACES));
-        } catch (SAXException | ParserConfigurationException ex) {
-            failUnexpected(ex);
-        }
     }
 
     /**
      * Set namespaces-prefix feature to a value to XMLFilter. it's expected same
      * when obtain it again.
+     * 
+     * @throws SAXException If there is a problem processing the document.
+     * @throws ParserConfigurationException if a DocumentBuilder cannot be 
+     *         created which satisfies the configuration requested.
      */
     @Test
-    public void setFeature02() {
-        try {
+    public void setFeature02() throws ParserConfigurationException, SAXException {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setNamespaceAware(true);
-            XMLReader xmlReader = spf.newSAXParser().getXMLReader();
 
             XMLFilterImpl xmlFilter = new XMLFilterImpl();
-            xmlFilter.setParent(xmlReader);
+        xmlFilter.setParent(spf.newSAXParser().getXMLReader());
             xmlFilter.setFeature(NAMESPACE_PREFIXES, false);
             assertFalse(xmlFilter.getFeature(NAMESPACE_PREFIXES));
             xmlFilter.setFeature(NAMESPACE_PREFIXES, true);
             assertTrue(xmlFilter.getFeature(NAMESPACE_PREFIXES));
-        } catch (SAXException | ParserConfigurationException ex) {
-            failUnexpected(ex);
-        }
     }
 
     /**
      * NullPointerException is expected when parse a null InputSource.
+     * 
+     * @throws SAXException If there is a problem processing the document.
+     * @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(expectedExceptions = NullPointerException.class)
-    public void parse01() {
-        try {
+    public void parse01() throws SAXException, IOException {
             new XMLFilterImpl().parse((InputSource)null);
-        } catch (IOException | SAXException ex) {
-            failUnexpected(ex);
         }
+  
+    /**
+     * 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();
     }
 
     /**
      * SAXException is expected when parsing a invalid formatted XML file.
-     * @throws org.xml.sax.SAXException when parse a incorrect formatted XML
-     * file.
+     * 
+     * @throws SAXException when parse a incorrect formatted XML file.
+     * @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(expectedExceptions = NullPointerException.class)
-    public void parse02() throws SAXException {
-        XMLFilterImpl xmlFilter = new XMLFilterImpl();
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
+    public void parse02() throws SAXException, IOException {
         try(FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) {
-            InputSource is = new InputSource(fis);
-            xmlFilter.parse(is);
-        } catch (IOException ex) {
-            failUnexpected(ex);
+            new XMLFilterImpl().parse(new InputSource(fis));
         }
     }
 
     /**
      * No exception when parse a normal XML file.
+     * 
+     * @throws SAXException when parse a incorrect formatted XML file.
+     * @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(expectedExceptions = NullPointerException.class)
-    public void parse03() {
-        XMLFilterImpl xmlFilter = new XMLFilterImpl();
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = NullPointerException.class)
+    public void parse03() throws SAXException, IOException {
         try(FileInputStream fis = new FileInputStream(XML_DIR + "correct2.xml")) {
-            InputSource is = new InputSource(fis);
-            xmlFilter.parse(is);
-        } catch (IOException | SAXException ex) {
-            failUnexpected(ex);
+            new XMLFilterImpl().parse(new InputSource(fis));
         }
     }
 }
< prev index next >