1 2 /* 3 This Java source file was generated by test-to-java.xsl 4 and is a derived work from the source document. 5 The source document contained the following notice: 6 7 8 9 Copyright (c) 2001-2003 World Wide Web Consortium, 10 (Massachusetts Institute of Technology, Institut National de 11 Recherche en Informatique et en Automatique, Keio University). All 12 Rights Reserved. This program is distributed under the W3C's Software 13 Intellectual Property License. This program is distributed in the 14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 PURPOSE. 17 18 See W3C License http://www.w3.org/Consortium/Legal/ for more details. 19 20 21 */ 22 23 package tests.org.w3c.dom; 24 25 import org.w3c.dom.Node; 26 import org.w3c.dom.Document; 27 import org.w3c.dom.Element; 28 import org.w3c.dom.Attr; 29 30 import javax.xml.parsers.DocumentBuilder; 31 32 /** 33 * The method getNamespaceURI returns the namespace URI of this node, or null if it is unspecified 34 * For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with 35 * a DOM Level 1 method, such as createElement from the Document interface, this is always null. 36 * 37 * Ceate two new element nodes and atribute nodes, with and without namespace prefixes. 38 * Retreive their namespaceURI's using getNamespaceURI and verrify if it is correct. 39 * @author IBM 40 * @author Neil Delima 41 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSname">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSname</a> 42 * @see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=259">http://www.w3.org/Bugs/Public/show_bug.cgi?id=259</a> 43 */ 44 public final class NodeGetNamespaceURI extends DOMTestCase { 45 46 DOMDocumentBuilderFactory factory; 47 48 DocumentBuilder builder; 49 setUp()50 protected void setUp() throws Exception { 51 super.setUp(); 52 try { 53 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 54 .getConfiguration1()); 55 builder = factory.getBuilder(); 56 } catch (Exception e) { 57 fail("Unexpected exception" + e.getMessage()); 58 } 59 } 60 tearDown()61 protected void tearDown() throws Exception { 62 factory = null; 63 builder = null; 64 super.tearDown(); 65 } 66 67 /** 68 * Runs the test case. 69 * @throws Throwable Any uncaught exception causes test to fail 70 */ testGetNamespaceURI()71 public void testGetNamespaceURI() throws Throwable { 72 Document doc; 73 Element element; 74 Element elementNS; 75 Attr attr; 76 Attr attrNS; 77 String elemNSURI; 78 String elemNSURINull; 79 String attrNSURI; 80 String attrNSURINull; 81 String nullNS = null; 82 83 doc = (Document) load("staff", builder); 84 element = doc.createElementNS(nullNS, "elem"); 85 elementNS = doc.createElementNS("http://www.w3.org/DOM/Test/elem", "qual:qelem"); 86 attr = doc.createAttributeNS(nullNS, "attr"); 87 attrNS = doc.createAttributeNS("http://www.w3.org/DOM/Test/attr", "qual:qattr"); 88 elemNSURI = elementNS.getNamespaceURI(); 89 elemNSURINull = element.getNamespaceURI(); 90 attrNSURI = attrNS.getNamespaceURI(); 91 attrNSURINull = attr.getNamespaceURI(); 92 assertEquals("nodegetnamespaceuri03_elemNSURI", "http://www.w3.org/DOM/Test/elem", elemNSURI); 93 assertNull("nodegetnamespaceuri03_1", elemNSURINull); 94 assertEquals("nodegetnamespaceuri03_attrNSURI", "http://www.w3.org/DOM/Test/attr", attrNSURI); 95 assertNull("nodegetnamespaceuri03_2", attrNSURINull); 96 } 97 98 } 99 100