< prev index next >

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

Print this page

        

*** 21,37 **** * questions. */ package org.xml.sax.ptests; import java.io.FileInputStream; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; ! import static jaxp.library.JAXPTestUtilities.failUnexpected; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import org.testng.annotations.Test; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; --- 21,40 ---- * 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 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.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException;
*** 45,55 **** /** * Unit test cases for ParserAdapter API. By default the only features recognized * are namespaces and namespace-prefixes. */ ! public class ParserAdapterTest { /** * namespaces feature name. */ private static final String NAMESPACES = "http://xml.org/sax/features/namespaces"; --- 48,58 ---- /** * Unit test cases for ParserAdapter API. By default the only features recognized * are namespaces and namespace-prefixes. */ ! public class ParserAdapterTest extends JAXPBaseTest { /** * namespaces feature name. */ private static final String NAMESPACES = "http://xml.org/sax/features/namespaces";
*** 149,279 **** parserAdapter.setErrorHandler(null); } /** * parserAdapter.getFeature(NAMESPACES) returns true be default. */ @Test ! public void getFeature01() { ! try { assertTrue(parserAdapter.getFeature(NAMESPACES)); - } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { - failUnexpected(ex); - } } /** * parserAdapter.getFeature(NAMESPACE_PREFIXES) returns true be default. */ @Test ! public void getFeature02() { ! try { assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES)); - } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { - failUnexpected(ex); - } } /** * SAXNotRecognizedException thrown when feature name is not known one. ! * @throws org.xml.sax.SAXNotRecognizedException expected Exception */ @Test(expectedExceptions = SAXNotRecognizedException.class) ! public void getFeature03() throws SAXNotRecognizedException { ! try { parserAdapter.getFeature("no-meaning-feature"); - } catch (SAXNotSupportedException ex) { - failUnexpected(ex); - } } /** * Obtain getFeature after it's set returns set value. */ @Test ! public void setFeature01() { ! try { parserAdapter.setFeature(NAMESPACES, false); assertFalse(parserAdapter.getFeature(NAMESPACES)); - } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { - failUnexpected(ex); - } } /** * Obtain getFeature after it's set returns set value. */ @Test ! public void setFeature02() { ! try { parserAdapter.setFeature(NAMESPACE_PREFIXES, false); assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES)); - } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { - failUnexpected(ex); - } } /** * Obtain getFeature after it's set returns set value. */ @Test ! public void setFeature03() { ! try { parserAdapter.setFeature(NAMESPACES, true); assertTrue(parserAdapter.getFeature(NAMESPACES)); - } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { - failUnexpected(ex); - } } /** * Obtain getFeature after it's set returns set value. */ @Test ! public void setFeature04() { ! try { parserAdapter.setFeature(NAMESPACE_PREFIXES, true); assertTrue(parserAdapter.getFeature(NAMESPACE_PREFIXES)); - } catch (SAXNotRecognizedException | SAXNotSupportedException ex) { - failUnexpected(ex); - } } /** * NPE expected when parsing a null object by ParserAdapter. */ @Test(expectedExceptions = NullPointerException.class) ! public void parse01() { ! try { parserAdapter.parse((InputSource)null); - } catch (IOException | SAXException ex) { - failUnexpected(ex); } } /** * SAXException expected when parsing a wrong-formatter XML with ParserAdapter. ! * @throws org.xml.sax.SAXException */ ! @Test(expectedExceptions = SAXException.class) ! public void parse02() throws SAXException { try(FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) { InputSource is = new InputSource(fis); parserAdapter.parse(is); - } catch (IOException ex) { - failUnexpected(ex); } } /** * Parse a well-formatter XML with ParserAdapter. */ ! @Test ! public void parse03() { try(FileInputStream fis = new FileInputStream(XML_DIR + "correct.xml")) { InputSource is = new InputSource(fis); parserAdapter.parse(is); - } catch (IOException | SAXException ex) { - failUnexpected(ex); } } } --- 152,311 ---- parserAdapter.setErrorHandler(null); } /** * parserAdapter.getFeature(NAMESPACES) returns true be default. + * + * @exception SAXNotRecognizedException If the feature + * value can't be assigned or retrieved. + * @exception SAXNotSupportedException If the + * feature is not currently readable. */ @Test ! public void getFeature01() throws SAXNotRecognizedException, SAXNotSupportedException { assertTrue(parserAdapter.getFeature(NAMESPACES)); } /** * parserAdapter.getFeature(NAMESPACE_PREFIXES) returns true be default. + * + * @exception SAXNotRecognizedException If the feature + * value can't be assigned or retrieved. + * @exception SAXNotSupportedException If the + * feature is not currently readable. */ @Test ! public void getFeature02() throws SAXNotRecognizedException, SAXNotSupportedException { assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES)); } /** * SAXNotRecognizedException thrown when feature name is not known one. ! * ! * @exception SAXNotRecognizedException If the feature ! * value can't be assigned or retrieved. ! * @exception SAXNotSupportedException If the ! * feature is not currently readable. */ @Test(expectedExceptions = SAXNotRecognizedException.class) ! public void getFeature03() throws SAXNotRecognizedException, SAXNotSupportedException { parserAdapter.getFeature("no-meaning-feature"); } /** * Obtain getFeature after it's set returns set value. + * + * @exception SAXNotRecognizedException If the feature + * value can't be assigned or retrieved. + * @exception SAXNotSupportedException If the + * feature is not currently readable. */ @Test ! public void setFeature01() throws SAXNotRecognizedException, SAXNotSupportedException { parserAdapter.setFeature(NAMESPACES, false); assertFalse(parserAdapter.getFeature(NAMESPACES)); } /** * Obtain getFeature after it's set returns set value. + * + * @exception SAXNotRecognizedException If the feature + * value can't be assigned or retrieved. + * @exception SAXNotSupportedException If the + * feature is not currently readable. */ @Test ! public void setFeature02() throws SAXNotRecognizedException, SAXNotSupportedException { parserAdapter.setFeature(NAMESPACE_PREFIXES, false); assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES)); } /** * Obtain getFeature after it's set returns set value. + * + * @exception SAXNotRecognizedException If the feature + * value can't be assigned or retrieved. + * @exception SAXNotSupportedException If the + * feature is not currently readable. */ @Test ! public void setFeature03() throws SAXNotRecognizedException, SAXNotSupportedException { parserAdapter.setFeature(NAMESPACES, true); assertTrue(parserAdapter.getFeature(NAMESPACES)); } /** * Obtain getFeature after it's set returns set value. + * + * @exception SAXNotRecognizedException If the feature + * value can't be assigned or retrieved. + * @exception SAXNotSupportedException If the + * feature is not currently readable. */ @Test ! public void setFeature04() throws SAXNotRecognizedException, ! SAXNotSupportedException { parserAdapter.setFeature(NAMESPACE_PREFIXES, true); assertTrue(parserAdapter.getFeature(NAMESPACE_PREFIXES)); } /** * NPE expected when parsing a null object by ParserAdapter. + * + * @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() throws IOException, SAXException { parserAdapter.parse((InputSource)null); } + + /** + * 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 expected when parsing a wrong-formatter XML with ParserAdapter. ! * ! * @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(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class) ! public void parse02() throws SAXException, IOException { try(FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) { InputSource is = new InputSource(fis); parserAdapter.parse(is); } } /** * Parse a well-formatter XML with ParserAdapter. + * + * @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(groups = {"readLocalFiles"}) ! public void parse03() throws SAXException, IOException { try(FileInputStream fis = new FileInputStream(XML_DIR + "correct.xml")) { InputSource is = new InputSource(fis); parserAdapter.parse(is); } } }
< prev index next >