HCNotationsSetNamedItemNS.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
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
19package tests.org.w3c.dom;
20
21import dalvik.annotation.TestInfo;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTarget;
24import dalvik.annotation.TestTargetClass;
25
26import org.w3c.dom.NamedNodeMap;
27import org.w3c.dom.Document;
28import org.w3c.dom.DocumentType;
29import org.w3c.dom.Element;
30import org.w3c.dom.DOMException;
31
32import 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)
45public 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    @TestInfo(
75      level = TestLevel.PARTIAL_OK,
76      purpose = "Verifies that setNamedItemNS throws DOMException.",
77      targets = {
78        @TestTarget(
79          methodName = "setNamedItemNS",
80          methodArgs = {org.w3c.dom.Node.class}
81        )
82    })
83    public void testNotationsSetNamedItemNS() throws Throwable {
84        Document doc;
85        NamedNodeMap notations;
86        DocumentType docType;
87
88        Element elem;
89        doc = (Document) load("hc_staff", builder);
90        docType = doc.getDoctype();
91
92        if (!(("text/html".equals(getContentType())))) {
93            assertNotNull("docTypeNotNull", docType);
94            notations = docType.getNotations();
95            assertNotNull("notationsNotNull", notations);
96            elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "br");
97
98            try {
99                notations.setNamedItemNS(elem);
100                fail("throw_HIER_OR_NO_MOD_ERR");
101
102            } catch (DOMException ex) {
103                switch (ex.code) {
104                case 3:
105                    break;
106                case 7:
107                    break;
108                default:
109                    throw ex;
110                }
111            }
112        }
113    }
114
115}
116