OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / tests / org / w3c / dom / HCNotationsSetNamedItemNS.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  Copyright (c) 2004 World Wide Web Consortium,
8  (Massachusetts Institute of Technology, Institut National de
9  Recherche en Informatique et en Automatique, Keio University). All
10  Rights Reserved. This program is distributed under the W3C's Software
11  Intellectual Property License. This program is distributed in the
12  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE.
15  See W3C License http://www.w3.org/Consortium/Legal/ for more details.
16
17  */
18
19 package tests.org.w3c.dom;
20
21 import dalvik.annotation.TestTargets;
22 import dalvik.annotation.TestLevel;
23 import dalvik.annotation.TestTargetNew;
24 import dalvik.annotation.TestTargetClass;
25
26 import org.w3c.dom.NamedNodeMap;
27 import org.w3c.dom.Document;
28 import org.w3c.dom.DocumentType;
29 import org.w3c.dom.Element;
30 import org.w3c.dom.DOMException;
31
32 import javax.xml.parsers.DocumentBuilder;
33
34 /**
35  * An attempt to add an element to the named node map returned by notations
36  * should result in a NO_MODIFICATION_ERR or HIERARCHY_REQUEST_ERR.
37  *
38  * @author Curt Arnold
39  * @see <a
40  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D46829EF">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D46829EF</a>
41  * @see <a
42  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS</a>
43  */
44 @TestTargetClass(NamedNodeMap.class)
45 public final class HCNotationsSetNamedItemNS extends DOMTestCase {
46
47     DOMDocumentBuilderFactory factory;
48
49     DocumentBuilder builder;
50
51     protected void setUp() throws Exception {
52         super.setUp();
53         try {
54             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
55                     .getConfiguration1());
56             builder = factory.getBuilder();
57         } catch (Exception e) {
58             fail("Unexpected exception" + e.getMessage());
59         }
60     }
61
62     protected void tearDown() throws Exception {
63         factory = null;
64         builder = null;
65         super.tearDown();
66     }
67
68     /**
69      * Runs the test case.
70      *
71      * @throws Throwable
72      *             Any uncaught exception causes test to fail
73      */
74     @TestTargetNew(
75         level = TestLevel.PARTIAL_COMPLETE,
76         notes = "Verifies that setNamedItemNS throws DOMException.",
77         method = "setNamedItemNS",
78         args = {org.w3c.dom.Node.class}
79     )
80     public void testNotationsSetNamedItemNS() throws Throwable {
81         Document doc;
82         NamedNodeMap notations;
83         DocumentType docType;
84
85         Element elem;
86         doc = (Document) load("hc_staff", builder);
87         docType = doc.getDoctype();
88
89         if (!(("text/html".equals(getContentType())))) {
90             assertNotNull("docTypeNotNull", docType);
91             notations = docType.getNotations();
92             assertNotNull("notationsNotNull", notations);
93             elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "br");
94
95             try {
96                 notations.setNamedItemNS(elem);
97                 fail("throw_HIER_OR_NO_MOD_ERR");
98
99             } catch (DOMException ex) {
100                 switch (ex.code) {
101                 case 3:
102                     break;
103                 case 7:
104                     break;
105                 default:
106                     throw ex;
107                 }
108             }
109         }
110     }
111
112 }