OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / org / w3c / dom / NamedNodeMapRemoveNamedItemNS.java
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 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.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;
36
37 import javax.xml.parsers.DocumentBuilder;
38
39 /**
40  * The method removeNamedItemNS removes a node specified by local name and
41  * namespace
42  *
43  * Retreive an attribute node and then remove from the NamedNodeMap. Verify if
44  * the attribute node was actually remove from the node map.
45  *
46  * @author IBM
47  * @author Neil Delima
48  * @see <a
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>
50  */
51 @TestTargetClass(NamedNodeMap.class)
52 public final class NamedNodeMapRemoveNamedItemNS extends DOMTestCase {
53
54     DOMDocumentBuilderFactory factory;
55
56     DocumentBuilder builder;
57
58     protected void setUp() throws Exception {
59         super.setUp();
60         try {
61             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
62                     .getConfiguration2());
63             builder = factory.getBuilder();
64         } catch (Exception e) {
65             fail("Unexpected exception" + e.getMessage());
66         }
67     }
68
69     protected void tearDown() throws Exception {
70         factory = null;
71         builder = null;
72         super.tearDown();
73     }
74
75     /**
76      * Runs the test case.
77      *
78      * @throws Throwable
79      *             Any uncaught exception causes test to fail
80      */
81     @TestTargetNew(
82         level = TestLevel.PARTIAL_COMPLETE,
83         notes = "Doesn't verify DOMException.",
84         method = "removeNamedItemNS",
85         args = {java.lang.String.class, java.lang.String.class}
86     )
87     public void testRemoveNamedItemNS1() throws Throwable {
88         Document doc;
89         NamedNodeMap attributes;
90         Node element;
91         Attr attribute;
92         NodeList elementList;
93         doc = (Document) load("staffNS", builder);
94         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
95                 "address");
96         element = elementList.item(1);
97         attributes = element.getAttributes();
98         attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
99                 "domestic");
100         attribute = (Attr) attributes.getNamedItemNS("http://www.nist.gov",
101                 "domestic");
102         assertNull("namednodemapremovenameditemns01", attribute);
103     }
104
105 // Assumes validation.
106 //    public void testRemoveNamedItemNS2() throws Throwable {
107 //        Document doc;
108 //        NamedNodeMap attributes;
109 //        Node element;
110 //        Attr attribute;
111 //        NodeList elementList;
112 //        String attrValue;
113 //        String nullNS = null;
114 //
115 //        doc = (Document) load("staffNS", builder);
116 //        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
117 //                "employee");
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",
125 //                attrValue);
126 //    }
127     @TestTargetNew(
128         level = TestLevel.PARTIAL_COMPLETE,
129         notes = "Doesn't verify DOMException.",
130         method = "removeNamedItemNS",
131         args = {java.lang.String.class, java.lang.String.class}
132     )
133     public void testRemoveNamedItemNS3() throws Throwable {
134         Document doc;
135         NamedNodeMap attributes;
136         Node element;
137         Attr attribute;
138
139         Attr attribute1;
140         Attr attribute2;
141         String nodeName;
142         doc = (Document) load("staffNS", builder);
143         element = doc.createElementNS("http://www.w3.org/DOM/Test", "root");
144         attribute1 = doc
145                 .createAttributeNS("http://www.w3.org/DOM/L1", "L1:att");
146         ((Element) /* Node */element).setAttributeNodeNS(attribute1);
147         attribute2 = doc
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);
157     }
158     @TestTargetNew(
159         level = TestLevel.PARTIAL_COMPLETE,
160         notes = "Doesn't verify DOMException.",
161         method = "removeNamedItemNS",
162         args = {java.lang.String.class, java.lang.String.class}
163     )
164     public void _testRemoveNamedItemNS4() throws Throwable {
165         Document doc;
166         NamedNodeMap attributes;
167         Node element;
168         Attr attribute;
169
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);
183     }
184
185 // Assumes validation.
186 //    public void testRemoveNamedItemNS5() throws Throwable {
187 //        Document doc;
188 //        DocumentType docType;
189 //        NamedNodeMap entities;
190 //        NamedNodeMap notations;
191 //
192 //        String nullNS = null;
193 //
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);
200 //
201 //        try {
202 //            entities.removeNamedItemNS(nullNS, "ent1");
203 //            fail("entity_throw_DOMException");
204 //
205 //        } catch (DOMException ex) {
206 //            switch (ex.code) {
207 //            case 8:
208 //                break;
209 //            case 7:
210 //                break;
211 //            default:
212 //                throw ex;
213 //            }
214 //        }
215 //
216 //        try {
217 //            notations.removeNamedItemNS(nullNS, "notation1");
218 //            fail("notation_throw_DOMException");
219 //
220 //        } catch (DOMException ex) {
221 //            switch (ex.code) {
222 //            case 8:
223 //                break;
224 //            case 7:
225 //                break;
226 //            default:
227 //                throw ex;
228 //            }
229 //        }
230 //    }
231     @TestTargetNew(
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}
236     )
237     public void testRemoveNamedItemNS6() throws Throwable {
238         Document doc;
239         NamedNodeMap attributes;
240         Node element;
241
242         NodeList elementList;
243         doc = (Document) load("staffNS", builder);
244         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
245                 "employee");
246         element = elementList.item(1);
247         attributes = element.getAttributes();
248
249         {
250             boolean success = false;
251             try {
252                 attributes.removeNamedItemNS("http://www.Nist.gov", "domestic");
253             } catch (DOMException ex) {
254                 success = (ex.code == DOMException.NOT_FOUND_ERR);
255             }
256             assertTrue("throw_NOT_FOUND_ERR", success);
257         }
258     }
259     @TestTargetNew(
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}
264     )
265     public void testRemoveNamedItemNS7() throws Throwable {
266         Document doc;
267         NamedNodeMap attributes;
268         Node element;
269
270         NodeList elementList;
271         doc = (Document) load("staffNS", builder);
272         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
273                 "employee");
274         element = elementList.item(1);
275         attributes = element.getAttributes();
276
277         {
278             boolean success = false;
279             try {
280                 attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
281             } catch (DOMException ex) {
282                 success = (ex.code == DOMException.NOT_FOUND_ERR);
283             }
284             assertTrue("throw_NOT_FOUND_ERR", success);
285         }
286     }
287     @TestTargetNew(
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}
292     )
293     public void testRemoveNamedItemNS8() throws Throwable {
294         Document doc;
295         NamedNodeMap attributes;
296         Element element;
297
298         NodeList elementList;
299         doc = (Document) load("staffNS", builder);
300         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
301                 "address");
302         element = (Element) elementList.item(1);
303         attributes = element.getAttributes();
304         element.removeAttributeNS("http://www.nist.gov", "domestic");
305
306         {
307             boolean success = false;
308             try {
309                 attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
310             } catch (DOMException ex) {
311                 success = (ex.code == DOMException.NOT_FOUND_ERR);
312             }
313             assertTrue("throw_NOT_FOUND_ERR", success);
314         }
315     }
316     @TestTargetNew(
317         level = TestLevel.PARTIAL_COMPLETE,
318         notes = "Doesn't verify DOMException.",
319         method = "removeNamedItemNS",
320         args = {java.lang.String.class, java.lang.String.class}
321     )
322     public void testRemoveNamedItemNS9() throws Throwable {
323         Document doc;
324         NamedNodeMap attributes;
325         NamedNodeMap newAttributes;
326         Element element;
327         Attr attribute;
328         NodeList elementList;
329         doc = (Document) load("staffNS", builder);
330         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
331                 "address");
332         element = (Element) elementList.item(1);
333         attributes = element.getAttributes();
334         attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
335                 "domestic");
336         newAttributes = element.getAttributes();
337         attribute = (Attr) newAttributes.getNamedItemNS("http://www.nist.gov",
338                 "domestic");
339         assertNull("namednodemapremovenameditemns09", attribute);
340     }
341
342 }