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 dalvik.annotation.TestTargets; 26 import dalvik.annotation.TestLevel; 27 import dalvik.annotation.TestTargetNew; 28 import dalvik.annotation.TestTargetClass; 29 30 import org.w3c.dom.Node; 31 import org.w3c.dom.Document; 32 import org.w3c.dom.Element; 33 import org.w3c.dom.Attr; 34 35 import javax.xml.parsers.DocumentBuilder; 36 37 /** 38 * The method getNamespaceURI returns the namespace URI of this node, or null if it is unspecified 39 * For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with 40 * a DOM Level 1 method, such as createElement from the Document interface, this is always null. 41 * 42 * Ceate two new element nodes and atribute nodes, with and without namespace prefixes. 43 * Retreive their namespaceURI's using getNamespaceURI and verrify if it is correct. 44 * @author IBM 45 * @author Neil Delima 46 * @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> 47 * @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> 48 */ 49 @TestTargetClass(Node.class) 50 public final class NodeGetNamespaceURI extends DOMTestCase { 51 52 DOMDocumentBuilderFactory factory; 53 54 DocumentBuilder builder; 55 56 protected void setUp() throws Exception { 57 super.setUp(); 58 try { 59 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 60 .getConfiguration1()); 61 builder = factory.getBuilder(); 62 } catch (Exception e) { 63 fail("Unexpected exception" + e.getMessage()); 64 } 65 } 66 67 protected void tearDown() throws Exception { 68 factory = null; 69 builder = null; 70 super.tearDown(); 71 } 72 73 /** 74 * Runs the test case. 75 * @throws Throwable Any uncaught exception causes test to fail 76 */ 77 @TestTargetNew( 78 level = TestLevel.COMPLETE, 79 notes = "", 80 method = "getNamespaceURI", 81 args = {} 82 ) 83 public void testGetNamespaceURI() throws Throwable { 84 Document doc; 85 Element element; 86 Element elementNS; 87 Attr attr; 88 Attr attrNS; 89 String elemNSURI; 90 String elemNSURINull; 91 String attrNSURI; 92 String attrNSURINull; 93 String nullNS = null; 94 95 doc = (Document) load("staff", builder); 96 element = doc.createElementNS(nullNS, "elem"); 97 elementNS = doc.createElementNS("http://www.w3.org/DOM/Test/elem", "qual:qelem"); 98 attr = doc.createAttributeNS(nullNS, "attr"); 99 attrNS = doc.createAttributeNS("http://www.w3.org/DOM/Test/attr", "qual:qattr"); 100 elemNSURI = elementNS.getNamespaceURI(); 101 elemNSURINull = element.getNamespaceURI(); 102 attrNSURI = attrNS.getNamespaceURI(); 103 attrNSURINull = attr.getNamespaceURI(); 104 assertEquals("nodegetnamespaceuri03_elemNSURI", "http://www.w3.org/DOM/Test/elem", elemNSURI); 105 assertNull("nodegetnamespaceuri03_1", elemNSURINull); 106 assertEquals("nodegetnamespaceuri03_attrNSURI", "http://www.w3.org/DOM/Test/attr", attrNSURI); 107 assertNull("nodegetnamespaceuri03_2", attrNSURINull); 108 } 109 110 } 111 112