< prev index next >
test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java
Print this page
*** 21,57 ****
* questions.
*/
package javax.xml.parsers.ptests;
- import static jaxp.library.JAXPTestUtilities.failUnexpected;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
!
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
!
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 {
!
/**
* Provide SAXParser.
*
! * @throws SAXException
! * @throws ParserConfigurationException
*/
@DataProvider(name = "parser-provider")
public Object[][] getParser() throws ParserConfigurationException, SAXException {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxparser = spf.newSAXParser();
--- 21,61 ----
* questions.
*/
package javax.xml.parsers.ptests;
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 extends JAXPBaseTest {
/**
* Provide SAXParser.
*
! * @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,559 ****
/**
* Test case with FileInputStream null, parsing should fail and throw
* IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse01(SAXParser saxparser) throws IllegalArgumentException {
! try {
FileInputStream instream = null;
! HandlerBase handler = new HandlerBase();
! saxparser.parse(instream, handler);
! } catch (SAXException | IOException e) {
! failUnexpected(e);
! }
}
/**
! * Testcase with an error in xml file, parsing should fail and throw
! * SAXException.
*
! * @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);
! }
}
/**
! * Testcase with a valid in xml file, parser should parse the xml document.
*/
! @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);
! }
}
/**
! * Testcase with valid input stream, parser should parse the xml document
! * successfully.
*/
! @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);
! }
}
/**
! * Testcase with valid input source, parser should parse the xml document
! * successfully.
*/
! @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);
! }
}
/**
! * Testcase with uri null, parsing should fail and throw
* IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
@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);
! }
}
/**
! * Testcase with non-existant uri, parsing should fail and throw
! * IOException.
*
! * @throws SAXException
! * @throws IOException
*/
! @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);
! }
}
/**
! * Testcase with File null, parsing should fail and throw
* IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
@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);
! }
}
/**
! * Testcase with empty string as File, parsing should fail and throw
! * SAXException.
*
! * @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);
! }
}
/**
! * Testcase with xml file that has errors parsing should fail and throw
* SAXException.
*
! * @throws SAXException
*/
@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);
! }
}
/**
! * Testcase with xml file that has no errors Parser should successfully
! * parse the xml document.
*/
! @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);
! }
!
}
/**
! * Testcase with input source null, parsing should fail and throw
* IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse14(SAXParser saxparser) throws IllegalArgumentException {
! try {
InputSource is = null;
! HandlerBase handler = new HandlerBase();
! saxparser.parse(is, handler);
! } catch (SAXException | IOException e) {
! failUnexpected(e);
! }
}
/**
! * Testcase with input source attached an invaild xml, parsing should fail
! * and throw SAXException.
! *
! * @throws SAXException
*/
! @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);
! }
}
/**
! * Testcase with input source attached an vaild xml, parser should
! * successfully parse the xml document.
*/
! @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);
! }
}
/**
! * Testcase with FileInputStream null, parsing should fail and throw
! * IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
! @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);
}
}
/**
! * Testcase with an error in xml file, parsing should fail and throw
! * SAXException.
*
! * @throws SAXException
*/
! @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);
! }
}
/**
! * Testcase with valid input stream, parser should parse the xml document
* successfully.
*/
! @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);
}
}
/**
! * Testcase with valid input stream, parser should parse the xml document
* successfully.
*/
! @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);
}
}
/**
! * Testcase with valid input source, parser should parse the xml document
! * successfully.
*/
! @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);
}
}
/**
! * Testcase with uri null, parsing should fail and throw
! * IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
! @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);
! }
}
/**
! * Testcase with non-existant uri, parsing should fail and throw
! * SAXException or IOException.
*
! * @throws SAXException
! * @throws IOException
*/
! @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);
!
}
/**
! * Testcase with proper uri, parser should parse successfully.
*/
! @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);
}
}
/**
! * Testcase with File null, parsing should fail and throw
! * IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
! @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);
}
}
/**
! * Testcase with empty string as File, parsing should fail and throw
! * SAXException.
*
! * @throws SAXException
*/
! @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
! public void testParse27(SAXParser saxparser) throws SAXException {
! try {
DefaultHandler handler = new DefaultHandler();
! File file = new File("");
! saxparser.parse(file, handler);
! } catch (IOException e) {
! failUnexpected(e);
! }
}
/**
! * Testcase with xml file that has errors, parsing should fail and throw
! * SAXException.
*
! * @throws SAXException
*/
! @Test(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
! public void testParse28(SAXParser saxparser) throws SAXException {
! try {
DefaultHandler handler = new DefaultHandler();
! File file = new File(TestUtils.XML_DIR, "valid.xml");
! saxparser.parse(file, handler);
! } catch (IOException e) {
! failUnexpected(e);
}
}
/**
! * Testcase with xml file that has no errors, parser should successfully
! * parse the xml document.
*/
! @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);
}
}
/**
! * Testcase with input source null, parsing should fail and throw
! * IllegalArgumentException.
*
! * @throws IllegalArgumentException
*/
! @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);
}
}
/**
! * Testcase with an invalid xml file, parser should throw SAXException.
*
! * @throws SAXException
*/
! @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 case to parse an xml file that not use namespaces.
*/
! @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 case to parse an xml file that uses namespaces.
*/
! @Test
! public void testParse33() {
! try {
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);
}
}
}
--- 64,572 ----
/**
* Test case with FileInputStream 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(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse01(SAXParser saxparser) throws SAXException, IOException {
FileInputStream instream = null;
! saxparser.parse(instream, new HandlerBase());
}
/**
! * Test with by setting URI as 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(expectedExceptions = IllegalArgumentException.class,
! dataProvider = "parser-provider")
! public void testParse02(SAXParser saxparser) throws SAXException, IOException {
! String uri = null;
! saxparser.parse(uri, new HandlerBase());
}
/**
! * 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(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();
}
/**
! * 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(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse04(SAXParser saxparser) throws SAXException, IOException {
! File file = null;
! saxparser.parse(file, new HandlerBase());
}
/**
! * 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(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());
}
/**
! * Test with input source 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(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse06(SAXParser saxparser) throws SAXException, IOException {
! InputSource is = null;
! saxparser.parse(is, new HandlerBase());
}
/**
! * Test with FileInputStream 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(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse07(SAXParser saxparser) throws SAXException, IOException {
! FileInputStream instream = null;
! saxparser.parse(instream, new DefaultHandler());
}
/**
! * Test with URI 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(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse08(SAXParser saxparser) throws SAXException, IOException {
! String uri = null;
! saxparser.parse(uri, new DefaultHandler());
}
/**
! * Test with non-existence URI, parsing should fail and throw
! * SAXException or 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 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();
}
/**
! * 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(expectedExceptions = SAXException.class, dataProvider = "parser-provider")
! 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());
}
/**
! * 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(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse11(SAXParser saxparser) throws SAXException, IOException {
! saxparser.parse((File) null, new DefaultHandler());
}
/**
! * Test with input source 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(expectedExceptions = IllegalArgumentException.class, dataProvider = "parser-provider")
! public void testParse12(SAXParser saxparser) throws SAXException, IOException {
InputSource is = null;
! saxparser.parse(is, new DefaultHandler());
}
/**
! * 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();
}
/**
! * Test with an error in XML 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(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());
}
}
/**
! * Test with a valid in XML file, parser should 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(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
! public void testParse14(SAXParser saxparser) throws SAXException, IOException {
! saxparser.parse(new File(XML_DIR, "parsertest.xml"),
! new HandlerBase());
}
/**
! * 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(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());
}
}
/**
! * 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(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());
}
}
/**
! * 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(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());
}
/**
! * Test with XML file that has no errors 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(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
! public void testParse19(SAXParser saxparser) throws SAXException, IOException {
! saxparser.parse(new File(XML_DIR, "correct.xml"), new HandlerBase());
}
/**
! * Test with input source attached an invalid XML, 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 testParse20(SAXParser saxparser) throws SAXException, IOException {
! try(FileInputStream instream = new FileInputStream(new File(XML_DIR,
! "invalid.xml"))) {
! saxparser.parse(new InputSource(instream), new HandlerBase());
! }
}
/**
! * 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(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());
}
}
/**
! * Test with an error in xml 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(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());
}
}
/**
! * 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(groups = {"readLocalFiles"}, dataProvider = "parser-provider")
! public void testParse23(SAXParser saxparser) throws SAXException, IOException {
DefaultHandler handler = new DefaultHandler();
! saxparser.parse(new File(XML_DIR, "parsertest.xml"), handler);
}
/**
! * 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(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();
! saxparser.parse(instream, handler);
}
}
/**
! * 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(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());
}
}
/**
! * 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(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());
}
/**
! * Test with XML file that has no errors, 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(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.
! *
! * @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"}, 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.
! *
! * @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(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);
! spf.newSAXParser().parse(instream, new HandlerBase());
}
}
}
< prev index next >