1 /* 2 This Java source file was generated by test-to-java.xsl 3 and is a derived work from the source document. 4 The source document contained the following notice: 5 6 7 8 Copyright (c) 2001-2003 World Wide Web Consortium, 9 (Massachusetts Institute of Technology, Institut National de 10 Recherche en Informatique et en Automatique, Keio University). All 11 Rights Reserved. This program is distributed under the W3C's Software 12 Intellectual Property License. This program is distributed in the 13 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. 16 17 See W3C License http://www.w3.org/Consortium/Legal/ for more details. 18 19 20 */ 21 22 package tests.org.w3c.dom; 23 24 import dalvik.annotation.TestTargets; 25 import dalvik.annotation.TestLevel; 26 import dalvik.annotation.TestTargetNew; 27 import dalvik.annotation.TestTargetClass; 28 29 import org.w3c.dom.Attr; 30 import org.w3c.dom.Document; 31 import org.w3c.dom.NodeList; 32 import org.w3c.dom.Element; 33 import org.w3c.dom.Node; 34 35 import javax.xml.parsers.DocumentBuilder; 36 37 /** 38 * The "getNamespaceURI()" method for an Attribute returns the namespace URI of 39 * this node, or null if unspecified. 40 * 41 * Retrieve the first "emp:address" node which has an attribute of 42 * "emp:district" that is specified in the DTD. Invoke the "getNamespaceURI()" 43 * method on the attribute. The method should return "http://www.nist.gov". 44 * 45 * @author NIST 46 * @author Mary Brady 47 * @see <a 48 * 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> 49 * @see <a 50 * href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=238">http://www.w3.org/Bugs/Public/show_bug.cgi?id=238</a> 51 */ 52 @TestTargetClass(Attr.class) 53 public final class NamespaceURI extends DOMTestCase { 54 55 DOMDocumentBuilderFactory factory; 56 57 DocumentBuilder builder; 58 59 protected void setUp() throws Exception { 60 super.setUp(); 61 try { 62 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 63 .getConfiguration2()); 64 builder = factory.getBuilder(); 65 } catch (Exception e) { 66 fail("Unexpected exception" + e.getMessage()); 67 } 68 } 69 70 protected void tearDown() throws Exception { 71 factory = null; 72 builder = null; 73 super.tearDown(); 74 } 75 76 /** 77 * Runs the test case. 78 * 79 * @throws Throwable 80 * Any uncaught exception causes test to fail 81 */ 82 // Assumes validation. 83 // public void testGetNamespaceURI1() throws Throwable { 84 // Document doc; 85 // NodeList elementList; 86 // Element testAddr; 87 // Attr addrAttr; 88 // String attrNamespaceURI; 89 // doc = (Document) load("staffNS", builder); 90 // elementList = doc.getElementsByTagName("emp:address"); 91 // testAddr = (Element) elementList.item(0); 92 // addrAttr = testAddr.getAttributeNodeNS("http://www.nist.gov", 93 // "district"); 94 // attrNamespaceURI = addrAttr.getNamespaceURI(); 95 // assertEquals("namespaceURI", "http://www.nist.gov", attrNamespaceURI); 96 // } 97 @TestTargetNew( 98 level = TestLevel.PARTIAL, 99 notes = "Doesn't verify that getNamespaceURI method returns null.", 100 method = "getNamespaceURI", 101 args = {} 102 ) 103 public void testGetNamespaceURI2() throws Throwable { 104 Document doc; 105 NodeList elementList; 106 Element testAddr; 107 Attr addrAttr; 108 String attrNamespaceURI; 109 doc = (Document) load("staffNS", builder); 110 elementList = doc.getElementsByTagName("emp:address"); 111 testAddr = (Element) elementList.item(0); 112 assertNotNull("empAddressNotNull", testAddr); 113 addrAttr = testAddr.getAttributeNodeNS("http://www.nist.gov", 114 "domestic"); 115 attrNamespaceURI = addrAttr.getNamespaceURI(); 116 assertEquals("namespaceURI", "http://www.nist.gov", attrNamespaceURI); 117 } 118 @TestTargetNew( 119 level = TestLevel.PARTIAL, 120 notes = "Doesn't verify that getNamespaceURI method returns null.", 121 method = "getNamespaceURI", 122 args = {} 123 ) 124 public void testGetNamespaceURI3() throws Throwable { 125 Document doc; 126 NodeList elementList; 127 Node testEmployee; 128 String employeeNamespace; 129 doc = (Document) load("staffNS", builder); 130 elementList = doc.getElementsByTagName("employee"); 131 testEmployee = elementList.item(0); 132 assertNotNull("employeeNotNull", testEmployee); 133 employeeNamespace = testEmployee.getNamespaceURI(); 134 assertEquals("namespaceURI", "http://www.nist.gov", employeeNamespace); 135 } 136 @TestTargetNew( 137 level = TestLevel.PARTIAL, 138 notes = "Verifies that getNamespaceURI method returns null.", 139 method = "getNamespaceURI", 140 args = {} 141 ) 142 public void testGetNamespaceURI4() throws Throwable { 143 Document doc; 144 NodeList elementList; 145 Node testEmployee; 146 String employeeNamespace; 147 doc = (Document) load("staffNS", builder); 148 elementList = doc.getElementsByTagName("employee"); 149 testEmployee = elementList.item(1); 150 employeeNamespace = testEmployee.getNamespaceURI(); 151 assertNull("throw_Null", employeeNamespace); 152 } 153 } 154