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-2004 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
22package tests.org.w3c.dom;
23
24import javax.xml.parsers.DocumentBuilder;
25
26import org.w3c.dom.Attr;
27import org.w3c.dom.DOMException;
28import org.w3c.dom.Document;
29import org.w3c.dom.Element;
30import org.w3c.dom.Node;
31import org.w3c.dom.NodeList;
32
33/**
34 * The "removeAttributeNS(namespaceURI,localName)" method for an attribute
35 * causes the DOMException NO_MODIFICATION_ALLOWED_ERR to be raised if the node
36 * is readonly.
37 *
38 * Obtain the children of the THIRD "gender" element. The elements content is an
39 * entity reference. Try to remove an attribute from the entity reference by
40 * executing the "removeAttributeNS(namespaceURI,localName)" method. This causes
41 * a NO_MODIFICATION_ALLOWED_ERR DOMException to be thrown.
42 *
43 * @author NIST
44 * @author Mary Brady
45 * @see <a
46 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])</a>
47 * @see <a
48 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS</a>
49 * @see <a
50 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElRemAtNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElRemAtNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])</a>
51 */
52public final class RemoveAttributeNS 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// Assumes validation.
82//    public void testRemoveAttributeNS1() throws Throwable {
83//        Document doc;
84//        NodeList genderList;
85//        Node gender;
86//        Node gen;
87//        NodeList gList;
88//        Element genElement;
89//        int nodeType;
90//        doc = (Document) load("staffNS", builder);
91//        genderList = doc.getElementsByTagName("gender");
92//        gender = genderList.item(2);
93//        gen = gender.getFirstChild();
94//        nodeType = (int) gen.getNodeType();
95//
96//        if (1 == nodeType) {
97//            gen = doc.createEntityReference("ent4");
98//            assertNotNull("createdEntRefNotNull", gen);
99//        }
100//        gList = gen.getChildNodes();
101//        genElement = (Element) gList.item(0);
102//        assertNotNull("notnull", genElement);
103//
104//        {
105//            boolean success = false;
106//            try {
107//                genElement.removeAttributeNS("www.xyz.com", "local1");
108//            } catch (DOMException ex) {
109//                success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
110//            }
111//            assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success);
112//        }
113//    }
114
115// Assumes validation
116//    public void testRemoveAttributeNS2() throws Throwable {
117//        Document doc;
118//        NodeList elementList;
119//        Node testAddr;
120//        Attr addrAttr;
121//        String attr;
122//        String namespaceURI;
123//        String localName;
124//        String prefix;
125//        doc = (Document) load("staffNS", builder);
126//        elementList = doc.getElementsByTagName("emp:address");
127//        testAddr = elementList.item(0);
128//        ((Element) /* Node */testAddr).removeAttributeNS("http://www.nist.gov",
129//                "local1");
130//        elementList = doc.getElementsByTagName("emp:address");
131//        testAddr = elementList.item(0);
132//        addrAttr = ((Element) /* Node */testAddr).getAttributeNodeNS(
133//                "http://www.nist.gov", "local1");
134//        attr = ((Element) /* Node */testAddr).getAttributeNS(
135//                "http://www.nist.gov", "local1");
136//        namespaceURI = addrAttr.getNamespaceURI();
137//        localName = addrAttr.getLocalName();
138//        prefix = testAddr.getPrefix();
139//        assertEquals("attr", "FALSE", attr);
140//        assertEquals("uri", "http://www.nist.gov", namespaceURI);
141//        assertEquals("lname", "local1", localName);
142//        assertEquals("prefix", "emp", prefix);
143//    }
144}
145