1 /* 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 package org.w3c.dom.ptests; 24 25 import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; 26 import static org.testng.Assert.assertEquals; 27 28 import java.io.StringReader; 29 30 import javax.xml.parsers.DocumentBuilder; 31 import javax.xml.parsers.DocumentBuilderFactory; 32 33 import jaxp.library.JAXPBaseTest; 34 35 import org.testng.annotations.Test; 36 import org.w3c.dom.Document; 37 import org.w3c.dom.Element; 38 import org.w3c.dom.TypeInfo; 39 import org.xml.sax.InputSource; 40 41 /* 42 * @summary Test getTypeName and getTypeNamespace methods of TypeInfo interface 43 */ 44 public class TypeInfoTest extends JAXPBaseTest { 45 /* 46 * Get the TypeInfo of the root element, and verify it. 47 */ 48 @Test 49 public void test() throws Exception { 50 TypeInfo typeInfo = getTypeOfRoot(SCHEMA_INSTANCE, "<?xml version='1.0'?>\n" + "<test1 xmlns=\"testNS\"><code/></test1>\n"); 51 52 assertEquals(typeInfo.getTypeName(), "Test"); 53 assertEquals(typeInfo.getTypeNamespace(), "testNS"); 54 55 } 56 57 private TypeInfo getTypeOfRoot(String schemaText, String docText) throws Exception { 58 Element root = getRoot(schemaText, docText); 59 return root.getSchemaTypeInfo(); 60 } 61 62 private Element getRoot(String schemaText, String docText) throws Exception { 63 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 64 | 1 /* 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 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 package org.w3c.dom.ptests; 24 25 import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; 26 import static org.testng.Assert.assertEquals; 27 28 import java.io.StringReader; 29 30 import javax.xml.parsers.DocumentBuilder; 31 import javax.xml.parsers.DocumentBuilderFactory; 32 33 import org.testng.annotations.Listeners; 34 import org.testng.annotations.Test; 35 import org.w3c.dom.Document; 36 import org.w3c.dom.Element; 37 import org.w3c.dom.TypeInfo; 38 import org.xml.sax.InputSource; 39 40 /* 41 * @summary Test getTypeName and getTypeNamespace methods of TypeInfo interface 42 */ 43 @Listeners({jaxp.library.BasePolicy.class}) 44 public class TypeInfoTest { 45 /* 46 * Get the TypeInfo of the root element, and verify it. 47 */ 48 @Test 49 public void test() throws Exception { 50 TypeInfo typeInfo = getTypeOfRoot(SCHEMA_INSTANCE, "<?xml version='1.0'?>\n" + "<test1 xmlns=\"testNS\"><code/></test1>\n"); 51 52 assertEquals(typeInfo.getTypeName(), "Test"); 53 assertEquals(typeInfo.getTypeNamespace(), "testNS"); 54 55 } 56 57 private TypeInfo getTypeOfRoot(String schemaText, String docText) throws Exception { 58 Element root = getRoot(schemaText, docText); 59 return root.getSchemaTypeInfo(); 60 } 61 62 private Element getRoot(String schemaText, String docText) throws Exception { 63 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 64 |