1package tests.org.w3c.dom;
2
3import dalvik.annotation.TestTargets;
4import dalvik.annotation.TestLevel;
5import dalvik.annotation.TestTargetNew;
6import dalvik.annotation.TestTargetClass;
7
8import org.w3c.dom.Element;
9import org.w3c.dom.Attr;
10import org.w3c.dom.Document;
11
12import javax.xml.parsers.DocumentBuilder;
13
14/**
15 * The method removeAttributeNS removes an attribute by local name and namespace
16 * URI. Create a new element and add a new attribute node to it. Remove the
17 * attribute node using the removeAttributeNodeNS method. Check if the attribute
18 * was remove by invoking the hasAttributeNS method on the element and check if
19 * it returns false.
20 *
21 * @author IBM
22 * @author Neil Delima
23 * @see <a
24 *      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>
25 */
26@TestTargetClass(Element.class)
27public final class ElementRemoveAttributeNS extends DOMTestCase {
28
29    DOMDocumentBuilderFactory factory;
30
31    DocumentBuilder builder;
32
33    protected void setUp() throws Exception {
34        super.setUp();
35        try {
36            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
37                    .getConfiguration1());
38            builder = factory.getBuilder();
39        } catch (Exception e) {
40            fail("Unexpected exception" + e.getMessage());
41        }
42    }
43
44    protected void tearDown() throws Exception {
45        factory = null;
46        builder = null;
47        super.tearDown();
48    }
49
50    /**
51     * Runs the test case.
52     *
53     * @throws Throwable
54     *             Any uncaught exception causes test to fail
55     */
56    @TestTargetNew(
57        level = TestLevel.PARTIAL,
58        notes = "Doesn't verify DOMException.",
59        method = "removeAttributeNS",
60        args = {java.lang.String.class, java.lang.String.class}
61    )
62    public void testRemoveAttributeNS() throws Throwable {
63        Document doc;
64        Element element;
65        boolean state;
66        Attr attribute;
67
68        doc = (Document) load("staff", builder);
69        element = doc.createElementNS("http://www.w3.org/DOM", "elem");
70        attribute = doc.createAttributeNS(
71                "http://www.w3.org/DOM/Test/createAttributeNS", "attr");
72        element.setAttributeNodeNS(attribute);
73        element.removeAttributeNS(
74                "http://www.w3.org/DOM/Test/createAttributeNS", "attr");
75        state = element.hasAttributeNS(
76                "http://www.w3.org/DOM/Test/createAttributeNS", "attr");
77        assertFalse("elementremoveattributens01", state);
78    }
79
80}
81