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:
8 Copyright (c) 2001 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
17 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
22 package tests.org.w3c.dom;
24 import dalvik.annotation.TestTargets;
25 import dalvik.annotation.TestLevel;
26 import dalvik.annotation.TestTargetNew;
27 import dalvik.annotation.TestTargetClass;
29 import org.w3c.dom.NamedNodeMap;
30 import org.w3c.dom.Document;
31 import org.w3c.dom.Node;
32 import org.w3c.dom.NodeList;
33 import org.w3c.dom.Attr;
34 import org.w3c.dom.Element;
35 import org.w3c.dom.DOMException;
37 import javax.xml.parsers.DocumentBuilder;
40 * The method removeNamedItemNS removes a node specified by local name and
43 * Retreive an attribute node and then remove from the NamedNodeMap. Verify if
44 * the attribute node was actually remove from the node map.
49 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D58B193">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D58B193</a>
51 @TestTargetClass(NamedNodeMap.class)
52 public final class NamedNodeMapRemoveNamedItemNS extends DOMTestCase {
54 DOMDocumentBuilderFactory factory;
56 DocumentBuilder builder;
58 protected void setUp() throws Exception {
61 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
62 .getConfiguration2());
63 builder = factory.getBuilder();
64 } catch (Exception e) {
65 fail("Unexpected exception" + e.getMessage());
69 protected void tearDown() throws Exception {
79 * Any uncaught exception causes test to fail
82 level = TestLevel.PARTIAL_COMPLETE,
83 notes = "Doesn't verify DOMException.",
84 method = "removeNamedItemNS",
85 args = {java.lang.String.class, java.lang.String.class}
87 public void testRemoveNamedItemNS1() throws Throwable {
89 NamedNodeMap attributes;
93 doc = (Document) load("staffNS", builder);
94 elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
96 element = elementList.item(1);
97 attributes = element.getAttributes();
98 attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
100 attribute = (Attr) attributes.getNamedItemNS("http://www.nist.gov",
102 assertNull("namednodemapremovenameditemns01", attribute);
105 // Assumes validation.
106 // public void testRemoveNamedItemNS2() throws Throwable {
108 // NamedNodeMap attributes;
111 // NodeList elementList;
113 // String nullNS = null;
115 // doc = (Document) load("staffNS", builder);
116 // elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
118 // element = elementList.item(1);
119 // attributes = element.getAttributes();
120 // attribute = (Attr) attributes.removeNamedItemNS(nullNS, "defaultAttr");
121 // attribute = (Attr) attributes.getNamedItemNS(nullNS, "defaultAttr");
122 // attrValue = attribute.getNodeValue();
123 // assertNotNull("namednodemapremovenameditemns02", attribute);
124 // assertEquals("namednodemapremovenameditemns02_attrValue", "defaultVal",
128 level = TestLevel.PARTIAL_COMPLETE,
129 notes = "Doesn't verify DOMException.",
130 method = "removeNamedItemNS",
131 args = {java.lang.String.class, java.lang.String.class}
133 public void testRemoveNamedItemNS3() throws Throwable {
135 NamedNodeMap attributes;
142 doc = (Document) load("staffNS", builder);
143 element = doc.createElementNS("http://www.w3.org/DOM/Test", "root");
145 .createAttributeNS("http://www.w3.org/DOM/L1", "L1:att");
146 ((Element) /* Node */element).setAttributeNodeNS(attribute1);
148 .createAttributeNS("http://www.w3.org/DOM/L2", "L2:att");
149 ((Element) /* Node */element).setAttributeNodeNS(attribute2);
150 attributes = element.getAttributes();
151 attribute = (Attr) attributes.removeNamedItemNS(
152 "http://www.w3.org/DOM/L1", "att");
153 attribute = (Attr) attributes.getNamedItemNS(
154 "http://www.w3.org/DOM/L2", "att");
155 nodeName = attribute.getNodeName();
156 assertEquals("namednodemapremovenameditemns02", "L2:att", nodeName);
159 level = TestLevel.PARTIAL_COMPLETE,
160 notes = "Doesn't verify DOMException.",
161 method = "removeNamedItemNS",
162 args = {java.lang.String.class, java.lang.String.class}
164 public void _testRemoveNamedItemNS4() throws Throwable {
166 NamedNodeMap attributes;
170 NodeList elementList;
171 doc = (Document) load("staffNS", builder);
172 elementList = doc.getElementsByTagNameNS("*", "employee");
173 element = elementList.item(0);
174 attributes = element.getAttributes();
175 attributes.removeNamedItemNS("http://www.w3.org/2000/xmlns/", "xmlns");
176 attribute = (Attr) attributes.getNamedItemNS(
177 "http://www.w3.org/2000/xmlns/", "xmlns");
178 assertNull("namednodemapremovenameditemns04_1", attribute);
179 attributes.removeNamedItemNS("http://www.w3.org/2000/xmlns/", "dmstc");
180 attribute = (Attr) attributes.getNamedItemNS(
181 "http://www.w3.org/2000/xmlns/", "dmstc");
182 assertNull("namednodemapremovenameditemns04_2", attribute);
185 // Assumes validation.
186 // public void testRemoveNamedItemNS5() throws Throwable {
188 // DocumentType docType;
189 // NamedNodeMap entities;
190 // NamedNodeMap notations;
192 // String nullNS = null;
194 // doc = (Document) load("staffNS", builder);
195 // docType = doc.getDoctype();
196 // entities = docType.getEntities();
197 // assertNotNull("entitiesNotNull", entities);
198 // notations = docType.getNotations();
199 // assertNotNull("notationsNotNull", notations);
202 // entities.removeNamedItemNS(nullNS, "ent1");
203 // fail("entity_throw_DOMException");
205 // } catch (DOMException ex) {
206 // switch (ex.code) {
217 // notations.removeNamedItemNS(nullNS, "notation1");
218 // fail("notation_throw_DOMException");
220 // } catch (DOMException ex) {
221 // switch (ex.code) {
232 level = TestLevel.PARTIAL_COMPLETE,
233 notes = "Verifies that removeNamedItemNS method throws DOMException with NOT_FOUND_ERR code.",
234 method = "removeNamedItemNS",
235 args = {java.lang.String.class, java.lang.String.class}
237 public void testRemoveNamedItemNS6() throws Throwable {
239 NamedNodeMap attributes;
242 NodeList elementList;
243 doc = (Document) load("staffNS", builder);
244 elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
246 element = elementList.item(1);
247 attributes = element.getAttributes();
250 boolean success = false;
252 attributes.removeNamedItemNS("http://www.Nist.gov", "domestic");
253 } catch (DOMException ex) {
254 success = (ex.code == DOMException.NOT_FOUND_ERR);
256 assertTrue("throw_NOT_FOUND_ERR", success);
260 level = TestLevel.PARTIAL_COMPLETE,
261 notes = "Verifies that removeNamedItemNS method throws DOMException with NOT_FOUND_ERR code.",
262 method = "removeNamedItemNS",
263 args = {java.lang.String.class, java.lang.String.class}
265 public void testRemoveNamedItemNS7() throws Throwable {
267 NamedNodeMap attributes;
270 NodeList elementList;
271 doc = (Document) load("staffNS", builder);
272 elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
274 element = elementList.item(1);
275 attributes = element.getAttributes();
278 boolean success = false;
280 attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
281 } catch (DOMException ex) {
282 success = (ex.code == DOMException.NOT_FOUND_ERR);
284 assertTrue("throw_NOT_FOUND_ERR", success);
288 level = TestLevel.PARTIAL_COMPLETE,
289 notes = "Verifies that removeNamedItemNS method throws DOMException with NOT_FOUND_ERR code.",
290 method = "removeNamedItemNS",
291 args = {java.lang.String.class, java.lang.String.class}
293 public void testRemoveNamedItemNS8() throws Throwable {
295 NamedNodeMap attributes;
298 NodeList elementList;
299 doc = (Document) load("staffNS", builder);
300 elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
302 element = (Element) elementList.item(1);
303 attributes = element.getAttributes();
304 element.removeAttributeNS("http://www.nist.gov", "domestic");
307 boolean success = false;
309 attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
310 } catch (DOMException ex) {
311 success = (ex.code == DOMException.NOT_FOUND_ERR);
313 assertTrue("throw_NOT_FOUND_ERR", success);
317 level = TestLevel.PARTIAL_COMPLETE,
318 notes = "Doesn't verify DOMException.",
319 method = "removeNamedItemNS",
320 args = {java.lang.String.class, java.lang.String.class}
322 public void testRemoveNamedItemNS9() throws Throwable {
324 NamedNodeMap attributes;
325 NamedNodeMap newAttributes;
328 NodeList elementList;
329 doc = (Document) load("staffNS", builder);
330 elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
332 element = (Element) elementList.item(1);
333 attributes = element.getAttributes();
334 attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
336 newAttributes = element.getAttributes();
337 attribute = (Attr) newAttributes.getNamedItemNS("http://www.nist.gov",
339 assertNull("namednodemapremovenameditemns09", attribute);