9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package javax.xml.parsers.ptests; 25 26 import static org.testng.Assert.assertEquals; 27 import static org.testng.Assert.assertNotNull; 28 import static org.testng.Assert.assertNull; 29 import java.io.BufferedReader; 30 import java.io.File; 31 import java.io.FileInputStream; 32 import java.io.FilePermission; 33 import java.io.FileReader; 34 import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; 35 import javax.xml.parsers.DocumentBuilder; 36 import javax.xml.parsers.DocumentBuilderFactory; 37 import javax.xml.parsers.SAXParser; 38 import javax.xml.parsers.SAXParserFactory; 39 import static javax.xml.parsers.ptests.ParserTestConst.GOLDEN_DIR; 40 import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR; 41 import javax.xml.transform.Transformer; 42 import javax.xml.transform.TransformerFactory; 43 import javax.xml.transform.dom.DOMSource; 44 import javax.xml.transform.sax.SAXResult; 45 import jaxp.library.JAXPFileBaseTest; 46 import static jaxp.library.JAXPTestUtilities.USER_DIR; 47 import static jaxp.library.JAXPTestUtilities.compareWithGold; 48 import static org.testng.Assert.assertFalse; 49 import static org.testng.Assert.assertTrue; 50 import org.testng.annotations.Test; 51 import org.w3c.dom.Document; 52 import org.w3c.dom.Element; 53 import org.w3c.dom.NodeList; 54 import org.xml.sax.InputSource; 55 import org.xml.sax.SAXException; 56 import org.xml.sax.helpers.DefaultHandler; 57 58 /** 59 * This checks the methods of DocumentBuilderFactoryImpl. 60 */ 61 public class DocumentBuilderFactoryTest extends JAXPFileBaseTest { 62 /** 63 * Test the default functionality of schema support method. 64 * @throws Exception If any errors occur. 65 */ 66 @Test 67 public void testCheckSchemaSupport1() throws Exception { 68 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 69 dbf.setValidating(true); 70 dbf.setNamespaceAware(true); 71 dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", 72 W3C_XML_SCHEMA_NS_URI); 73 MyErrorHandler eh = MyErrorHandler.newInstance(); 74 DocumentBuilder db = dbf.newDocumentBuilder(); 75 db.setErrorHandler(eh); 76 db.parse(new File(XML_DIR, "test.xml")); 77 assertFalse(eh.isErrorOccured()); 78 } 79 80 /** 81 * Test the default functionality of schema support method. In | 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package javax.xml.parsers.ptests; 25 26 import static org.testng.Assert.assertEquals; 27 import static org.testng.Assert.assertNotNull; 28 import static org.testng.Assert.assertNull; 29 30 import java.io.BufferedReader; 31 import java.io.File; 32 import java.io.FileInputStream; 33 import java.io.FilePermission; 34 import java.io.FileReader; 35 36 import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; 37 38 import javax.xml.parsers.DocumentBuilder; 39 import javax.xml.parsers.DocumentBuilderFactory; 40 import javax.xml.parsers.FactoryConfigurationError; 41 import javax.xml.parsers.ParserConfigurationException; 42 import javax.xml.parsers.SAXParser; 43 import javax.xml.parsers.SAXParserFactory; 44 45 import static javax.xml.parsers.ptests.ParserTestConst.GOLDEN_DIR; 46 import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR; 47 48 import javax.xml.transform.Transformer; 49 import javax.xml.transform.TransformerFactory; 50 import javax.xml.transform.dom.DOMSource; 51 import javax.xml.transform.sax.SAXResult; 52 53 import jaxp.library.JAXPFileBaseTest; 54 import static jaxp.library.JAXPTestUtilities.USER_DIR; 55 import static jaxp.library.JAXPTestUtilities.compareWithGold; 56 import static org.testng.Assert.assertFalse; 57 import static org.testng.Assert.assertTrue; 58 59 import org.testng.annotations.DataProvider; 60 import org.testng.annotations.Test; 61 import org.w3c.dom.Document; 62 import org.w3c.dom.Element; 63 import org.w3c.dom.NodeList; 64 import org.xml.sax.InputSource; 65 import org.xml.sax.SAXException; 66 import org.xml.sax.helpers.DefaultHandler; 67 68 /** 69 * This checks the methods of DocumentBuilderFactoryImpl. 70 */ 71 public class DocumentBuilderFactoryTest extends JAXPFileBaseTest { 72 private static final String DOCUMENT_BUILDER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"; 73 74 @DataProvider(name = "parameters") 75 public Object[][] getValidateParameters() { 76 return new Object[][] { { DOCUMENT_BUILDER_FACTORY_CLASSNAME, null }, { DOCUMENT_BUILDER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } }; 77 } 78 79 /* 80 * test for DocumentBuilderFactory.newInstance(java.lang.String 81 * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName 82 * points to correct implementation of 83 * javax.xml.parsers.DocumentBuilderFactory , should return newInstance of 84 * DocumentBuilderFactory 85 */ 86 @Test(dataProvider = "parameters") 87 public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws ParserConfigurationException { 88 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(factoryClassName, classLoader); 89 DocumentBuilder builder = dbf.newDocumentBuilder(); 90 assertNotNull(builder); 91 } 92 93 @DataProvider(name = "invalid-parameters") 94 public Object[][] getInvalidateParameters() { 95 return new Object[][] { { null, null }, { null, this.getClass().getClassLoader() } }; 96 } 97 98 /* 99 * test for DocumentBuilderFactory.newInstance(java.lang.String 100 * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is 101 * null , should throw FactoryConfigurationError 102 */ 103 @Test(expectedExceptions = FactoryConfigurationError.class, dataProvider = "invalid-parameters") 104 public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) { 105 DocumentBuilderFactory.newInstance(factoryClassName, classLoader); 106 } 107 108 /** 109 * Test the default functionality of schema support method. 110 * @throws Exception If any errors occur. 111 */ 112 @Test 113 public void testCheckSchemaSupport1() throws Exception { 114 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 115 dbf.setValidating(true); 116 dbf.setNamespaceAware(true); 117 dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", 118 W3C_XML_SCHEMA_NS_URI); 119 MyErrorHandler eh = MyErrorHandler.newInstance(); 120 DocumentBuilder db = dbf.newDocumentBuilder(); 121 db.setErrorHandler(eh); 122 db.parse(new File(XML_DIR, "test.xml")); 123 assertFalse(eh.isErrorOccured()); 124 } 125 126 /** 127 * Test the default functionality of schema support method. In |