< prev index next >
test/javax/xml/jaxp/functional/org/xml/sax/ptests/ParserAdapterTest.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.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
@@ -45,11 +48,11 @@
/**
* Unit test cases for ParserAdapter API. By default the only features recognized
* are namespaces and namespace-prefixes.
*/
-public class ParserAdapterTest {
+public class ParserAdapterTest extends JAXPBaseTest {
/**
* namespaces feature name.
*/
private static final String NAMESPACES =
"http://xml.org/sax/features/namespaces";
@@ -149,131 +152,160 @@
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() {
- try {
+ public void getFeature01() throws SAXNotRecognizedException, SAXNotSupportedException {
assertTrue(parserAdapter.getFeature(NAMESPACES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* 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() {
- try {
+ public void getFeature02() throws SAXNotRecognizedException, SAXNotSupportedException {
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
+ *
+ * @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 {
- try {
+ public void getFeature03() throws SAXNotRecognizedException, SAXNotSupportedException {
parserAdapter.getFeature("no-meaning-feature");
- } catch (SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* 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() {
- try {
+ public void setFeature01() throws SAXNotRecognizedException, SAXNotSupportedException {
parserAdapter.setFeature(NAMESPACES, false);
assertFalse(parserAdapter.getFeature(NAMESPACES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* 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() {
- try {
+ public void setFeature02() throws SAXNotRecognizedException, SAXNotSupportedException {
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.
+ *
+ * @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() {
- try {
+ public void setFeature03() throws SAXNotRecognizedException, SAXNotSupportedException {
parserAdapter.setFeature(NAMESPACES, true);
assertTrue(parserAdapter.getFeature(NAMESPACES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* 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() {
- try {
+ public void setFeature04() throws SAXNotRecognizedException,
+ SAXNotSupportedException {
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.
+ *
+ * @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 IOException, SAXException {
parserAdapter.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 expected when parsing a wrong-formatter XML with ParserAdapter.
- * @throws org.xml.sax.SAXException
+ *
+ * @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 = SAXException.class)
- public void parse02() throws SAXException {
+ @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);
- } catch (IOException ex) {
- failUnexpected(ex);
}
}
/**
* 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
- public void parse03() {
+ @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);
- } catch (IOException | SAXException ex) {
- failUnexpected(ex);
}
}
}
< prev index next >