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 org.w3c.dom.Element; 25 import org.w3c.dom.Attr; 26 import org.w3c.dom.Document; 27 import org.w3c.dom.NodeList; 28 29 import javax.xml.parsers.DocumentBuilder; 30 31 /** 32 * The "getAttributeNS(namespaceURI,localName)" method retrieves an attribute 33 * value by local name and NamespaceURI. 34 * 35 * Retrieve the first "emp:address" element. The value returned by the 36 * "getAttributeNS()" method should be the value "DISTRICT" since the attribute 37 * has a default value. 38 * 39 * @author NIST 40 * @author Mary Brady 41 * @see <a 42 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElGetAttrNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElGetAttrNS</a> 43 * @see <a 44 * href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=238">http://www.w3.org/Bugs/Public/show_bug.cgi?id=238</a> 45 */ 46 public final class GetAttributeNS extends DOMTestCase { 47 48 DOMDocumentBuilderFactory factory; 49 50 DocumentBuilder builder; 51 52 protected void setUp() throws Exception { 53 super.setUp(); 54 try { 55 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 56 .getConfiguration2()); 57 builder = factory.getBuilder(); 58 } catch (Exception e) { 59 fail("Unexpected exception" + e.getMessage()); 60 } 61 } 62 63 protected void tearDown() throws Exception { 64 factory = null; 65 builder = null; 66 super.tearDown(); 67 } 68 69 /** 70 * Runs the test case. 71 * 72 * @throws Throwable 73 * Any uncaught exception causes test to fail 74 */ 75 // Assumes validation. 76 // public void testGetAttributeNS1() throws Throwable { 77 // String namespaceURI = "http://www.nist.gov"; 78 // String localName = "district"; 79 // 80 // Document doc; 81 // NodeList elementList; 82 // Element testAddr; 83 // String attrValue; 84 // doc = (Document) load("staffNS", builder); 85 // elementList = doc.getElementsByTagName("emp:address"); 86 // testAddr = (Element) elementList.item(0); 87 // attrValue = testAddr.getAttributeNS(namespaceURI, localName); 88 // assertEquals("attrValue", "DISTRICT", attrValue); 89 // } 90 public void testGetAttributeNS2() throws Throwable { 91 String namespaceURI = "http://www.nist.gov"; 92 String localName = "district"; 93 String qualifiedName = "emp:district"; 94 Document doc; 95 Attr newAttribute; 96 NodeList elementList; 97 Element testAddr; 98 99 String attrValue; 100 doc = (Document) load("staffNS", builder); 101 newAttribute = doc.createAttributeNS(namespaceURI, qualifiedName); 102 elementList = doc.getElementsByTagName("emp:address"); 103 testAddr = (Element) elementList.item(0); 104 assertNotNull("empAddrNotNull", testAddr); 105 testAddr.setAttributeNodeNS(newAttribute); 106 elementList = doc.getElementsByTagName("emp:address"); 107 testAddr = (Element) elementList.item(0); 108 attrValue = testAddr.getAttributeNS(namespaceURI, localName); 109 assertEquals("throw_Equals", "", attrValue); 110 } 111 public void testGetAttributeNS3() throws Throwable { 112 String namespaceURI = "http://www.nist.gov"; 113 String localName = "domestic"; 114 Document doc; 115 NodeList elementList; 116 Element testAddr; 117 String attrValue; 118 doc = (Document) load("staffNS", builder); 119 elementList = doc.getElementsByTagName("emp:address"); 120 testAddr = (Element) elementList.item(0); 121 assertNotNull("empAddrNotNull", testAddr); 122 testAddr.removeAttributeNS(namespaceURI, localName); 123 attrValue = testAddr.getAttributeNS(namespaceURI, localName); 124 assertEquals("throw_Equals", "", attrValue); 125 } 126 public void testGetAttributeNS4() throws Throwable { 127 String namespaceURI = "http://www.nist.gov"; 128 String localName = "blank"; 129 String qualifiedName = "emp:blank"; 130 Document doc; 131 132 NodeList elementList; 133 Element testAddr; 134 135 String attrValue; 136 doc = (Document) load("staffNS", builder); 137 doc.createAttributeNS(namespaceURI, qualifiedName); 138 elementList = doc.getElementsByTagName("emp:address"); 139 testAddr = (Element) elementList.item(0); 140 assertNotNull("empAddrNotNull", testAddr); 141 testAddr.setAttributeNS(namespaceURI, qualifiedName, "NewValue"); 142 attrValue = testAddr.getAttributeNS(namespaceURI, localName); 143 assertEquals("throw_Equals", "NewValue", attrValue); 144 } 145 public void testGetAttributeNS5() throws Throwable { 146 Document doc; 147 NodeList elementList; 148 Element testAddr; 149 String attrValue; 150 doc = (Document) load("staffNS", builder); 151 elementList = doc.getElementsByTagName("emp:address"); 152 testAddr = (Element) elementList.item(0); 153 assertNotNull("empAddrNotNull", testAddr); 154 attrValue = testAddr.getAttributeNS("http://www.nist.gov", "domestic"); 155 assertEquals("attrValue", "Yes", attrValue); 156 } 157 } 158