< prev index next >

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

Print this page

        

*** 21,34 **** * 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.assertNotNull; import static org.testng.Assert.assertTrue; import org.testng.annotations.Test; import org.xml.sax.HandlerBase; import org.xml.sax.InputSource; --- 21,35 ---- * 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.assertNotNull; import static org.testng.Assert.assertTrue; import org.testng.annotations.Test; import org.xml.sax.HandlerBase; import org.xml.sax.InputSource;
*** 38,48 **** import static org.xml.sax.ptests.SAXTestConst.XML_DIR; /** * Class containing the test cases for XMLReaderAdapter API */ ! public class XMLReaderAdapterTest { /** * http://xml.org/sax/features/namespace-prefixes property name. */ private final static String NM_PREFIXES_PROPERTY = "http://xml.org/sax/features/namespace-prefixes"; --- 39,49 ---- import static org.xml.sax.ptests.SAXTestConst.XML_DIR; /** * Class containing the test cases for XMLReaderAdapter API */ ! public class XMLReaderAdapterTest extends JAXPBaseTest { /** * http://xml.org/sax/features/namespace-prefixes property name. */ private final static String NM_PREFIXES_PROPERTY = "http://xml.org/sax/features/namespace-prefixes";
*** 56,117 **** public void constructor01() throws SAXException { assertNotNull(new XMLReaderAdapter()); } /** ! * To test the constructor that uses XMLReader */ @Test ! public void constructor02() { ! try { ! SAXParserFactory spf = SAXParserFactory.newInstance(); ! XMLReader xmlReader = spf.newSAXParser().getXMLReader(); ! assertNotNull(new XMLReaderAdapter(xmlReader)); - } catch (ParserConfigurationException | SAXException ex) { - failUnexpected(ex); - } } /** * To test the parse method. The specification says that this method * will throw an exception if the embedded XMLReader does not support * the http://xml.org/sax/features/namespace-prefixes property. */ @Test ! public void nsfeature01() { ! try { ! SAXParserFactory spf = SAXParserFactory.newInstance(); ! XMLReader xmlReader = spf.newSAXParser().getXMLReader(); if (!xmlReader.getFeature(NM_PREFIXES_PROPERTY)) { xmlReader.setFeature(NM_PREFIXES_PROPERTY, true); } - assertTrue(xmlReader.getFeature(NM_PREFIXES_PROPERTY)); - } catch (SAXException | ParserConfigurationException ex) { - failUnexpected(ex); - } } /** * To test the parse method. The specification says that this method * will throw an exception if the embedded XMLReader does not support * the http://xml.org/sax/features/namespace-prefixes property. */ @Test ! public void parse01() { try (FileInputStream fis = new FileInputStream(XML_DIR + "namespace1.xml")) { ! SAXParserFactory spf = SAXParserFactory.newInstance(); ! XMLReader xmlReader = spf.newSAXParser().getXMLReader(); if (!xmlReader.getFeature(NM_PREFIXES_PROPERTY)) { xmlReader.setFeature(NM_PREFIXES_PROPERTY, true); } XMLReaderAdapter xmlRA = new XMLReaderAdapter(xmlReader); - - InputSource is = new InputSource(fis); xmlRA.setDocumentHandler(new HandlerBase()); ! xmlRA.parse(is); ! } catch (IOException | SAXException | ParserConfigurationException ex) { ! failUnexpected(ex); } } } --- 57,119 ---- public void constructor01() throws SAXException { assertNotNull(new XMLReaderAdapter()); } /** ! * To test the constructor that uses XMLReader. ! * ! * @throws SAXException If there is a problem processing the document. ! * @throws ParserConfigurationException if a DocumentBuilder cannot be ! * created which satisfies the configuration requested. */ @Test ! public void constructor02() throws ParserConfigurationException, SAXException { ! XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); assertNotNull(new XMLReaderAdapter(xmlReader)); } /** * To test the parse method. The specification says that this method * will throw an exception if the embedded XMLReader does not support * the http://xml.org/sax/features/namespace-prefixes property. + * + * @throws SAXException If there is a problem processing the document. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. */ @Test ! public void nsfeature01() throws ParserConfigurationException, SAXException { ! XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); if (!xmlReader.getFeature(NM_PREFIXES_PROPERTY)) { xmlReader.setFeature(NM_PREFIXES_PROPERTY, true); } assertTrue(xmlReader.getFeature(NM_PREFIXES_PROPERTY)); } /** * To test the parse method. The specification says that this method * will throw an exception if the embedded XMLReader does not support * the http://xml.org/sax/features/namespace-prefixes property. + * + * @throws SAXException If there is a problem processing the document. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + * @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 parse01() throws IOException, SAXException, ! ParserConfigurationException { ! setPermissions(new FilePermission(XML_DIR + "/-", "read")); try (FileInputStream fis = new FileInputStream(XML_DIR + "namespace1.xml")) { ! XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); if (!xmlReader.getFeature(NM_PREFIXES_PROPERTY)) { xmlReader.setFeature(NM_PREFIXES_PROPERTY, true); } XMLReaderAdapter xmlRA = new XMLReaderAdapter(xmlReader); xmlRA.setDocumentHandler(new HandlerBase()); ! xmlRA.parse(new InputSource(fis)); } + setPermissions(); } }
< prev index next >