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) 2001-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.TestTargets;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTargetNew;
24import dalvik.annotation.TestTargetClass;
25
26import org.w3c.dom.NamedNodeMap;
27import org.w3c.dom.Document;
28import org.w3c.dom.Element;
29import org.w3c.dom.DOMException;
30
31import javax.xml.parsers.DocumentBuilder;
32
33/**
34 * Attempt to insert an element into an attribute list, should raise a
35 * HIERARCHY_REQUEST_ERR.
36 *
37 * @author Curt Arnold
38 * @see <a
39 *      href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='HIERARCHY_REQUEST_ERR'])">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='HIERARCHY_REQUEST_ERR'])</a>
40 * @see <a
41 *      href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788</a>
42 * @see <a
43 *      href="http://www.w3.org/2000/11/DOM-Level-2-errata#core-4">http://www.w3.org/2000/11/DOM-Level-2-errata#core-4</a>
44 */
45@TestTargetClass(NamedNodeMap.class)
46public final class HCNamedNodeMapInvalidType extends DOMTestCase {
47
48    DOMDocumentBuilderFactory factory;
49
50    DocumentBuilder builder;
51
52    protected void setUp() throws Exception {
53        super.setUp();
54        try {
55            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
56                    .getConfiguration1());
57            builder = factory.getBuilder();
58        } catch (Exception e) {
59            fail("Unexpected exception" + e.getMessage());
60        }
61    }
62
63    protected void tearDown() throws Exception {
64        factory = null;
65        builder = null;
66        super.tearDown();
67    }
68
69    /**
70     * Runs the test case.
71     *
72     * @throws Throwable
73     *             Any uncaught exception causes test to fail
74     */
75    @TestTargetNew(
76        level = TestLevel.PARTIAL,
77        notes = "Verifies that setNamedItem method throws DOMException with HIERARCHY_REQUEST_ERR code.",
78        method = "setNamedItem",
79        args = {org.w3c.dom.Node.class}
80    )
81    public void testNamedNodeMapInvalidType() throws Throwable {
82        Document doc;
83        NamedNodeMap attributes;
84        Element docElem;
85        Element newElem;
86
87        doc = (Document) load("hc_staff", builder);
88        docElem = doc.getDocumentElement();
89        attributes = docElem.getAttributes();
90        newElem = doc.createElement("html");
91
92        {
93            boolean success = false;
94            try {
95                attributes.setNamedItem(newElem);
96            } catch (DOMException ex) {
97                success = (ex.code == DOMException.HIERARCHY_REQUEST_ERR);
98            }
99            assertTrue("throw_HIERARCHY_REQUEST_ERR", success);
100        }
101    }
102
103}
104