< prev index next >

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

Print this page

        

@@ -21,37 +21,41 @@
  * questions.
  */
 
 package javax.xml.parsers.ptests;
 
-import static jaxp.library.JAXPTestUtilities.failUnexpected;
-
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FilePermission;
 import java.io.IOException;
-
+import java.util.PropertyPermission;
 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.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 {
-
+public class SAXParserTest extends JAXPBaseTest {
     /**
      * Provide SAXParser.
      *
-     * @throws SAXException
-     * @throws ParserConfigurationException
+     * @return a data provider contains a SAXParser instance.
+     * @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.
      */
     @DataProvider(name = "parser-provider")
     public Object[][] getParser() throws ParserConfigurationException, SAXException {
         SAXParserFactory spf = SAXParserFactory.newInstance();
         SAXParser saxparser = spf.newSAXParser();

@@ -60,500 +64,509 @@
 
     /**
      * Test case with FileInputStream null, parsing should fail and throw
      * IllegalArgumentException.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse01(SAXParser saxparser) throws IllegalArgumentException {
-        try {
+    public void testParse01(SAXParser saxparser) throws SAXException, IOException {
             FileInputStream instream = null;
-            HandlerBase handler = new HandlerBase();
-            saxparser.parse(instream, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+        saxparser.parse(instream, new HandlerBase());
     }
 
     /**
-     * Testcase with an error in xml file, parsing should fail and throw
-     * SAXException.
+     * Test with by setting URI as null, parsing should fail and throw
+     * IllegalArgumentException.
      *
-     * @throws SAXException
-     */
-    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse02(SAXParser saxparser) throws SAXException {
-        try {
-            HandlerBase handler = new HandlerBase();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
-            saxparser.parse(instream, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
-        }
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
+     */
+    @Test(expectedExceptions = IllegalArgumentException.class,
+            dataProvider = "parser-provider")
+    public void testParse02(SAXParser saxparser) throws SAXException, IOException {
+        String uri = null;
+        saxparser.parse(uri, new HandlerBase());
     }
 
     /**
-     * Testcase with a valid in xml file, parser should parse the xml document.
+     * Test with non-existence URI, parsing should fail and throw IOException.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse03(SAXParser saxparser) {
-        try {
-            HandlerBase handler = new HandlerBase();
-            saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
-        } catch (IOException | SAXException e) {
-            failUnexpected(e);
-        }
+    @Test(expectedExceptions = { SAXException.class, IOException.class }, 
+            dataProvider = "parser-provider")
+    public void testParse03(SAXParser saxparser) throws SAXException, IOException {
+        String workingDir = System.getProperty("test.classes") + "../../../../../../..";
+        setPermissions(new PropertyPermission("user.dir", "read"),
+                new FilePermission(workingDir + "/-", "read"));
+        saxparser.parse("", new HandlerBase());
+        setPermissions();
     }
 
     /**
-     * Testcase with valid input stream, parser should parse the xml document
-     * successfully.
+     * Test with File null, parsing should fail and throw
+     * IllegalArgumentException.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse04(SAXParser saxparser) {
-        try {
-            HandlerBase handler = new HandlerBase();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
-            saxparser.parse(instream, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
+    public void testParse04(SAXParser saxparser) throws SAXException, IOException {
+        File file = null;
+        saxparser.parse(file, new HandlerBase());
     }
 
     /**
-     * Testcase with valid input source, parser should parse the xml document
-     * successfully.
+     * Test with empty string as File, parsing should fail and throw
+     * SAXException.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse05(SAXParser saxparser) {
-        try {
-            HandlerBase handler = new HandlerBase();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "parsertest.xml"));
-            saxparser.parse(instream, handler, new File(TestUtils.XML_DIR).toURI().toASCIIString());
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
+    public void testParse05(SAXParser saxparser) throws SAXException, IOException {
+        String workingDir = System.getProperty("test.classes") + "../../../../../../..";
+        setPermissions(new PropertyPermission("user.dir", "read"),
+                new FilePermission(workingDir + "/-", "read"));
+        saxparser.parse(new File(""), new HandlerBase());
     }
 
     /**
-     * Testcase with uri null, parsing should fail and throw
+     * Test with input source null, parsing should fail and throw
      * IllegalArgumentException.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse07(SAXParser saxparser) throws IllegalArgumentException {
-        try {
-            String uri = null;
-            HandlerBase handler = new HandlerBase();
-            saxparser.parse(uri, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    public void testParse06(SAXParser saxparser) throws SAXException, IOException {
+        InputSource is = null;
+        saxparser.parse(is, new HandlerBase());
     }
 
     /**
-     * Testcase with non-existant uri, parsing should fail and throw
-     * IOException.
+     * Test with FileInputStream null, parsing should fail and throw
+     * IllegalArgumentException.
      *
-     * @throws SAXException
-     * @throws IOException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
-    public void testParse08(SAXParser saxparser) throws SAXException, IOException {
-        String uri = " ";
-
-        HandlerBase handler = new HandlerBase();
-        saxparser.parse(uri, handler);
-
-    }
-
-    /**
-     * Testcase with proper uri, parser should parse successfully.
-     */
-    @Test(dataProvider = "parser-provider")
-    public void testParse09(SAXParser saxparser) {
-        try {
-            File file = new File(TestUtils.XML_DIR, "correct.xml");
-            HandlerBase handler = new HandlerBase();
-            saxparser.parse(file.toURI().toASCIIString(), handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
+    public void testParse07(SAXParser saxparser) throws SAXException, IOException {
+        FileInputStream instream = null;
+        saxparser.parse(instream, new DefaultHandler());
     }
 
     /**
-     * Testcase with File null, parsing should fail and throw
+     * Test with URI null, parsing should fail and throw
      * IllegalArgumentException.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse10(SAXParser saxparser) throws IllegalArgumentException {
-        try {
-            File file = null;
-            HandlerBase handler = new HandlerBase();
-            saxparser.parse(file, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    public void testParse08(SAXParser saxparser) throws SAXException, IOException {
+        String uri = null;
+        saxparser.parse(uri, new DefaultHandler());
     }
 
     /**
-     * Testcase with empty string as File, parsing should fail and throw
-     * SAXException.
+     * Test with non-existence URI, parsing should fail and throw
+     * SAXException or IOException.
      *
-     * @throws SAXException
-     */
-    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse11(SAXParser saxparser) throws SAXException {
-        try {
-            HandlerBase handler = new HandlerBase();
-            File file = new File("");
-            saxparser.parse(file, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
-        }
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
+     */
+    @Test(expectedExceptions = { SAXException.class, IOException.class }, 
+            dataProvider = "parser-provider")
+    public void testParse09(SAXParser saxparser) throws SAXException, IOException {
+        String workingDir = System.getProperty("test.classes") + "../../../../../../..";
+        setPermissions(new PropertyPermission("user.dir", "read"),
+                new FilePermission(workingDir + "/-", "read"));
+        String uri = " ";
+        saxparser.parse(uri, new DefaultHandler());
+        setPermissions();
     }
 
     /**
-     * Testcase with xml file that has errors parsing should fail and throw
+     * Test with empty string as File, parsing should fail and throw
      * SAXException.
      *
-     * @throws SAXException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
     @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse12(SAXParser saxparser) throws SAXException {
-        try {
-            HandlerBase handler = new HandlerBase();
-            File file = new File(TestUtils.XML_DIR, "valid.xml");
-            saxparser.parse(file, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
-        }
+    public void testParse10(SAXParser saxparser) throws SAXException, IOException {
+        String workingDir = System.getProperty("test.classes") + "../../../../../../..";
+        setPermissions(new PropertyPermission("user.dir", "read"),
+                new FilePermission(workingDir + "/-", "read"));
+        File file = new File("");
+        saxparser.parse(file, new DefaultHandler());
     }
 
     /**
-     * Testcase with xml file that has no errors Parser should successfully
-     * parse the xml document.
+     * Test with File null, parsing should fail and throw
+     * IllegalArgumentException.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse13(SAXParser saxparser) {
-        try {
-            HandlerBase handler = new HandlerBase();
-            File file = new File(TestUtils.XML_DIR, "correct.xml");
-            saxparser.parse(file, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
-
+    @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
+    public void testParse11(SAXParser saxparser) throws SAXException, IOException {
+        saxparser.parse((File) null, new DefaultHandler());
     }
 
     /**
-     * Testcase with input source null, parsing should fail and throw
+     * Test with input source null, parsing should fail and throw
      * IllegalArgumentException.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
     @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse14(SAXParser saxparser) throws IllegalArgumentException {
-        try {
+    public void testParse12(SAXParser saxparser) throws SAXException, IOException {
             InputSource is = null;
-            HandlerBase handler = new HandlerBase();
-            saxparser.parse(is, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+        saxparser.parse(is, new DefaultHandler());
     }
 
     /**
-     * Testcase with input source attached an invaild xml, parsing should fail
-     * and throw SAXException.
-     *
-     * @throws SAXException
+     * Save system property for restoring.
      */
-    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse15(SAXParser saxparser) throws SAXException {
-        try {
-            HandlerBase handler = new HandlerBase();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
-            InputSource is = new InputSource(instream);
-            saxparser.parse(is, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
-        }
+    @BeforeGroups (groups = {"readLocalFiles"})
+    public void setFilePermissions() {
+        setPermissions(new FilePermission(XML_DIR  + "../-", "read"));
     }
 
     /**
-     * Testcase with input source attached an vaild xml, parser should
-     * successfully parse the xml document.
+     * Restore the system property.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse16(SAXParser saxparser) {
-        try {
-            HandlerBase handler = new HandlerBase();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
-            InputSource is = new InputSource(instream);
-            saxparser.parse(is, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    @AfterGroups (groups = {"readLocalFiles"})
+    public void restoreFilePermissions() {
+        setPermissions();
     }
 
     /**
-     * Testcase with FileInputStream null, parsing should fail and throw
-     * IllegalArgumentException.
+     * Test with an error in XML file, parsing should fail and throw
+     * SAXException.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse17(SAXParser saxparser) throws IllegalArgumentException {
-        try {
-            FileInputStream instream = null;
-            DefaultHandler handler = new DefaultHandler();
-            saxparser.parse(instream, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class,
+            dataProvider = "parser-provider")
+    public void testParse13(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(
+                XML_DIR, "invalid.xml"))) {
+            saxparser.parse(instream, new HandlerBase());
         }
     }
 
     /**
-     * Testcase with an error in xml file, parsing should fail and throw
-     * SAXException.
+     * Test with a valid in XML file, parser should parse the XML document.
      *
-     * @throws SAXException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse18(SAXParser saxparser) throws SAXException {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
-            saxparser.parse(instream, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
-        }
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse14(SAXParser saxparser) throws SAXException, IOException {
+        saxparser.parse(new File(XML_DIR, "parsertest.xml"), 
+                new HandlerBase());
     }
 
     /**
-     * Testcase with valid input stream, parser should parse the xml document
+     * Test with valid input stream, parser should parse the XML document
      * successfully.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse19(SAXParser saxparser) {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            saxparser.parse(new File(TestUtils.XML_DIR, "parsertest.xml"), handler);
-        } catch (IOException | SAXException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse15(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, 
+                "correct.xml"))) {
+            saxparser.parse(instream, new HandlerBase());
         }
     }
 
     /**
-     * Testcase with valid input stream, parser should parse the xml document
+     * Test with valid input source, parser should parse the XML document
      * successfully.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse20(SAXParser saxparser) {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
-            saxparser.parse(instream, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse16(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "parsertest.xml"))) {
+            saxparser.parse(instream, new HandlerBase(), 
+                    new File(XML_DIR).toURI().toASCIIString());
         }
     }
 
     /**
-     * Testcase with valid input source, parser should parse the xml document
-     * successfully.
+     * Test with proper URI, parser should parse successfully.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse21(SAXParser saxparser) {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "parsertest.xml"));
-            saxparser.parse(instream, handler, new File(TestUtils.XML_DIR).toURI().toASCIIString());
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse17(SAXParser saxparser) throws SAXException, IOException {
+        File file = new File(XML_DIR, "correct.xml");
+        saxparser.parse(file.toURI().toASCIIString(), new HandlerBase());
         }
 
+    /**
+     * Test with XML file that has errors parsing should fail and throw
+     * SAXException.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
+     */
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
+    public void testParse18(SAXParser saxparser) throws SAXException, IOException {
+        saxparser.parse(new File(XML_DIR, "valid.xml"), new HandlerBase());
     }
 
     /**
-     * Testcase with uri null, parsing should fail and throw
-     * IllegalArgumentException.
+     * Test with XML file that has no errors Parser should successfully
+     * parse the XML document.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse23(SAXParser saxparser) throws IllegalArgumentException {
-        try {
-            String uri = null;
-            DefaultHandler handler = new DefaultHandler();
-            saxparser.parse(uri, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
-        }
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse19(SAXParser saxparser) throws SAXException, IOException {
+        saxparser.parse(new File(XML_DIR, "correct.xml"), new HandlerBase());
     }
 
     /**
-     * Testcase with non-existant uri, parsing should fail and throw
-     * SAXException or IOException.
+     * Test with input source attached an invalid XML, parsing should fail
+     * and throw SAXException.
      *
-     * @throws SAXException
-     * @throws IOException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
-    public void testParse24(SAXParser saxparser) throws SAXException, IOException {
-        String uri = " ";
-        DefaultHandler handler = new DefaultHandler();
-        saxparser.parse(uri, handler);
-
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
+    public void testParse20(SAXParser saxparser) throws SAXException, IOException {
+        try(FileInputStream instream = new FileInputStream(new File(XML_DIR, 
+                "invalid.xml"))) {
+            saxparser.parse(new InputSource(instream), new HandlerBase());
+        }
     }
 
     /**
-     * Testcase with proper uri, parser should parse successfully.
+     * Test with input source attached an valid XML, parser should
+     * successfully parse the XML document.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse25(SAXParser saxparser) {
-        try {
-            File file = new File(TestUtils.XML_DIR, "correct.xml");
-
-            DefaultHandler handler = new DefaultHandler();
-            saxparser.parse(file.toURI().toASCIIString(), handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse21(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, 
+                "correct.xml"))) {
+            saxparser.parse(new InputSource(instream), new HandlerBase());
         }
     }
 
     /**
-     * Testcase with File null, parsing should fail and throw
-     * IllegalArgumentException.
+     * Test with an error in xml file, parsing should fail and throw
+     * SAXException.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse26(SAXParser saxparser) throws IllegalArgumentException {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            saxparser.parse((File) null, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
+    public void testParse22(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "invalid.xml"))) {
+            saxparser.parse(instream, new DefaultHandler());
         }
     }
 
     /**
-     * Testcase with empty string as File, parsing should fail and throw
-     * SAXException.
+     * Test with valid input stream, parser should parse the XML document
+     * successfully.
      *
-     * @throws SAXException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse27(SAXParser saxparser) throws SAXException {
-        try {
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse23(SAXParser saxparser) throws SAXException, IOException {
             DefaultHandler handler = new DefaultHandler();
-            File file = new File("");
-            saxparser.parse(file, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
-        }
+        saxparser.parse(new File(XML_DIR, "parsertest.xml"), handler);
     }
 
     /**
-     * Testcase with xml file that has errors, parsing should fail and throw
-     * SAXException.
+     * Test with valid input stream, parser should parse the XML document
+     * successfully.
      *
-     * @throws SAXException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse28(SAXParser saxparser) throws SAXException {
-        try {
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse24(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, 
+                "correct.xml"))) {
             DefaultHandler handler = new DefaultHandler();
-            File file = new File(TestUtils.XML_DIR, "valid.xml");
-            saxparser.parse(file, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
+            saxparser.parse(instream, handler);
         }
     }
 
     /**
-     * Testcase with xml file that has no errors, parser should successfully
-     * parse the xml document.
+     * Test with valid input source, parser should parse the XML document
+     * successfully.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse29(SAXParser saxparser) {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            File file = new File(TestUtils.XML_DIR, "correct.xml");
-            saxparser.parse(file, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse25(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "parsertest.xml"))) {
+            saxparser.parse(instream, new DefaultHandler(), 
+                new File(XML_DIR).toURI().toASCIIString());
         }
     }
 
     /**
-     * Testcase with input source null, parsing should fail and throw
-     * IllegalArgumentException.
+     * Test with proper URI, parser should parse successfully.
      *
-     * @throws IllegalArgumentException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
-    public void testParse30(SAXParser saxparser) throws IllegalArgumentException {
-        try {
-            InputSource is = null;
-            DefaultHandler handler = new DefaultHandler();
-            saxparser.parse(is, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse26(SAXParser saxparser) throws SAXException, IOException {
+        File file = new File(XML_DIR, "correct.xml");
+        saxparser.parse(file.toURI().toASCIIString(), new DefaultHandler());
         }
+
+    /**
+     * Test with XML file that has errors, parsing should fail and throw
+     * SAXException.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
+     */
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, dataProvider = "parser-provider")
+    public void testParse27(SAXParser saxparser) throws SAXException, IOException {
+        saxparser.parse(new File(XML_DIR, "valid.xml"), new DefaultHandler());
     }
 
     /**
-     * Testcase with an invalid xml file, parser should throw SAXException.
+     * Test with XML file that has no errors, parser should successfully
+     * parse the XML document.
      *
-     * @throws SAXException
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
-    public void testParse31(SAXParser saxparser) throws SAXException {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "invalid.xml"));
-            InputSource is = new InputSource(instream);
-            saxparser.parse(is, handler);
-        } catch (IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse28(SAXParser saxparser) throws SAXException, IOException {
+        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 SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
+     */
+    @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class, 
+            dataProvider = "parser-provider")
+    public void testParse29(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "invalid.xml"))) {
+            saxparser.parse(new InputSource(instream), new DefaultHandler());
         }
     }
 
     /**
-     * Test case to parse an xml file that not use namespaces.
+     * Test case to parse an XML file that not use namespaces.
+     *
+     * @param saxparser a SAXParser instance.
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
      */
-    @Test(dataProvider = "parser-provider")
-    public void testParse32(SAXParser saxparser) {
-        try {
-            DefaultHandler handler = new DefaultHandler();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "correct.xml"));
-            InputSource is = new InputSource(instream);
-            saxparser.parse(is, handler);
-        } catch (SAXException | IOException e) {
-            failUnexpected(e);
+    @Test(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
+    public void testParse30(SAXParser saxparser) throws SAXException, IOException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "correct.xml"))) {
+            saxparser.parse(new InputSource(instream), new DefaultHandler());
         }
     }
 
     /**
-     * Test case to parse an xml file that uses namespaces.
+     * Test case to parse an XML file that uses namespaces.
+     * 
+     * @throws SAXException If any parse errors occur.
+     * @throws IOException If an IO error occurs interacting with the 
+     *         InputStream.
+     * @throws ParserConfigurationException if a DocumentBuilder cannot be 
+     *         created which satisfies the configuration requested.
      */
-    @Test
-    public void testParse33() {
-        try {
+    @Test(groups = {"readLocalFiles"})
+    public void testParse31() throws SAXException, IOException, ParserConfigurationException {
+        try (FileInputStream instream = new FileInputStream(new File(XML_DIR, "ns4.xml"))) {
             SAXParserFactory spf = SAXParserFactory.newInstance();
             spf.setNamespaceAware(true);
-            SAXParser saxparser = spf.newSAXParser();
-            HandlerBase handler = new HandlerBase();
-            FileInputStream instream = new FileInputStream(new File(TestUtils.XML_DIR, "ns4.xml"));
-            saxparser.parse(instream, handler);
-        } catch (ParserConfigurationException | SAXException | IOException e) {
-            failUnexpected(e);
+            spf.newSAXParser().parse(instream, new HandlerBase());
         }
     }
 }
< prev index next >