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-2004 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 22package tests.org.w3c.dom; 23 24import dalvik.annotation.TestTargets; 25import dalvik.annotation.TestLevel; 26import dalvik.annotation.TestTargetNew; 27import dalvik.annotation.TestTargetClass; 28 29import org.w3c.dom.NamedNodeMap; 30import org.w3c.dom.Document; 31import org.w3c.dom.Node; 32import org.w3c.dom.NodeList; 33import org.w3c.dom.Attr; 34import org.w3c.dom.Element; 35 36import javax.xml.parsers.DocumentBuilder; 37 38/** 39 * Using the method getNamedItemNS, retreive the entity "ent1" and notation 40 * "notation1" from a NamedNodeMap of this DocumentTypes entities and notations. 41 * Both should be null since entities and notations are not namespaced. 42 * 43 * @author IBM 44 * @author Neil Delima 45 * @see <a 46 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getNamedItemNS</a> 47 * @see <a 48 * href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=259">http://www.w3.org/Bugs/Public/show_bug.cgi?id=259</a> 49 * @see <a 50 * href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=407">http://www.w3.org/Bugs/Public/show_bug.cgi?id=407</a> 51 * @see <a 52 * href="http://lists.w3.org/Archives/Member/w3c-dom-ig/2003Nov/0016.html">http://lists.w3.org/Archives/Member/w3c-dom-ig/2003Nov/0016.html</a> 53 */ 54@TestTargetClass(NamedNodeMap.class) 55public final class NamedNodeMapGetNamedItemNS extends DOMTestCase { 56 57 DOMDocumentBuilderFactory factory; 58 59 DocumentBuilder builder; 60 61 protected void setUp() throws Exception { 62 super.setUp(); 63 try { 64 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 65 .getConfiguration2()); 66 builder = factory.getBuilder(); 67 } catch (Exception e) { 68 fail("Unexpected exception" + e.getMessage()); 69 } 70 } 71 72 protected void tearDown() throws Exception { 73 factory = null; 74 builder = null; 75 super.tearDown(); 76 } 77 78 /** 79 * Runs the test case. 80 * 81 * @throws Throwable 82 * Any uncaught exception causes test to fail 83 */ 84// Assumes validation. 85// public void testGetNamedItemNS1() throws Throwable { 86// Document doc; 87// DocumentType docType; 88// NamedNodeMap entities; 89// NamedNodeMap notations; 90// Entity entity; 91// Notation notation; 92// 93// String nullNS = null; 94// 95// doc = (Document) load("staffNS", builder); 96// docType = doc.getDoctype(); 97// entities = docType.getEntities(); 98// assertNotNull("entitiesNotNull", entities); 99// notations = docType.getNotations(); 100// assertNotNull("notationsNotNull", notations); 101// entity = (Entity) entities.getNamedItemNS(nullNS, "ent1"); 102// assertNotNull("entityNull", entity); 103// notation = (Notation) notations.getNamedItemNS(nullNS, "notation1"); 104// assertNotNull("notationNull", notation); 105// } 106 @TestTargetNew( 107 level = TestLevel.PARTIAL, 108 notes = "Doesn't verify DOMException.", 109 method = "getNamedItemNS", 110 args = {java.lang.String.class, java.lang.String.class} 111 ) 112 public void testGetNamedItemNS2() throws Throwable { 113 Document doc; 114 NamedNodeMap attributes; 115 Node element; 116 Attr attribute; 117 NodeList elementList; 118 String attrName; 119 doc = (Document) load("staffNS", builder); 120 elementList = doc.getElementsByTagNameNS("http://www.nist.gov", 121 "address"); 122 element = elementList.item(1); 123 attributes = element.getAttributes(); 124 attribute = (Attr) attributes.getNamedItemNS("http://www.nist.gov", 125 "domestic"); 126 attrName = attribute.getNodeName(); 127 assertEquals("namednodemapgetnameditemns02", "emp:domestic", attrName); 128 } 129 @TestTargetNew( 130 level = TestLevel.PARTIAL, 131 notes = "Doesn't verify DOMException.", 132 method = "getNamedItemNS", 133 args = {java.lang.String.class, java.lang.String.class} 134 ) 135 public void testGetNamedItemNS3() throws Throwable { 136 Document doc; 137 NamedNodeMap attributes; 138 Node element; 139 Attr attribute; 140 Attr newAttr1; 141 Attr newAttr2; 142 143 String attrName; 144 doc = (Document) load("staffNS", builder); 145 element = doc.createElementNS("http://www.w3.org/DOM/Test", "root"); 146 newAttr1 = doc.createAttributeNS("http://www.w3.org/DOM/L1", "L1:att"); 147 ((Element) /* Node */element).setAttributeNodeNS(newAttr1); 148 newAttr2 = doc.createAttributeNS("http://www.w3.org/DOM/L2", "L2:att"); 149 ((Element) /* Node */element).setAttributeNodeNS(newAttr2); 150 attributes = element.getAttributes(); 151 attribute = (Attr) attributes.getNamedItemNS( 152 "http://www.w3.org/DOM/L2", "att"); 153 attrName = attribute.getNodeName(); 154 assertEquals("namednodemapgetnameditemns03", "L2:att", attrName); 155 } 156 @TestTargetNew( 157 level = TestLevel.PARTIAL, 158 notes = "Doesn't verify DOMException.", 159 method = "getNamedItemNS", 160 args = {java.lang.String.class, java.lang.String.class} 161 ) 162 public void testGetNamedItemNS4() throws Throwable { 163 Document doc; 164 NamedNodeMap attributes; 165 Element element; 166 Attr attribute; 167 Attr newAttr1; 168 NodeList elementList; 169 String attrName; 170 doc = (Document) load("staffNS", builder); 171 elementList = doc.getElementsByTagNameNS("*", "address"); 172 element = (Element) elementList.item(1); 173 newAttr1 = doc.createAttributeNS("http://www.w3.org/DOM/L1", "street"); 174 element.setAttributeNodeNS(newAttr1); 175 attributes = element.getAttributes(); 176 attribute = (Attr) attributes.getNamedItemNS( 177 "http://www.w3.org/DOM/L1", "street"); 178 attrName = attribute.getNodeName(); 179 assertEquals("namednodemapgetnameditemns04", "street", attrName); 180 } 181 @TestTargetNew( 182 level = TestLevel.PARTIAL, 183 notes = "Doesn't verify DOMException.", 184 method = "getNamedItemNS", 185 args = {java.lang.String.class, java.lang.String.class} 186 ) 187 public void testGetNamedItemNS5() throws Throwable { 188 Document doc; 189 NamedNodeMap attributes; 190 Node element; 191 Attr attribute; 192 NodeList elementList; 193 doc = (Document) load("staffNS", builder); 194 elementList = doc.getElementsByTagNameNS("*", "address"); 195 element = elementList.item(1); 196 attributes = element.getAttributes(); 197 attribute = (Attr) attributes.getNamedItemNS("*", "street"); 198 assertNull("namednodemapgetnameditemns05", attribute); 199 } 200 201// Assumes validation. 202// public void testGetNamedItemNS6() throws Throwable { 203// Document doc; 204// NamedNodeMap attributesMap1; 205// NamedNodeMap attributesMap2; 206// Element element; 207// Attr attribute; 208// Attr newAttr1; 209// 210// NodeList elementList; 211// String attrName; 212// doc = (Document) load("staffNS", builder); 213// elementList = doc.getElementsByTagNameNS("*", "address"); 214// element = (Element) elementList.item(1); 215// attributesMap1 = element.getAttributes(); 216// attributesMap2 = element.getAttributes(); 217// newAttr1 = doc.createAttributeNS("http://www.w3.org/DOM/L1", "street"); 218// element.setAttributeNodeNS(newAttr1); 219// attribute = (Attr) attributesMap1.getNamedItemNS( 220// "http://www.w3.org/DOM/L1", "street"); 221// attrName = attribute.getNodeName(); 222// assertEquals("namednodemapgetnameditemnsMap106", "street", attrName); 223// attribute = (Attr) attributesMap2.getNamedItemNS( 224// "http://www.w3.org/DOM/L1", "street"); 225// attrName = attribute.getNodeName(); 226// assertEquals("namednodemapgetnameditemnsMap206", "street", attrName); 227// } 228 229} 230