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 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 dalvik.annotation.TestTargets;
25import dalvik.annotation.TestLevel;
26import dalvik.annotation.TestTargetNew;
27import dalvik.annotation.TestTargetClass;
28
29import org.w3c.dom.Element;
30import org.w3c.dom.Document;
31import org.w3c.dom.NodeList;
32import org.w3c.dom.Attr;
33
34import javax.xml.parsers.DocumentBuilder;
35
36/**
37 * The method hasAttributeNS returns true when an attribute with a given local
38 * name and namespace URI is specified on this element or has a default value,
39 * false otherwise.
40 *
41 * Retreive the first employee element node. Invoke the hasAttributeNS method to
42 * check if it has the xmlns attribute that belongs to the namespace
43 * http://www.w3.org/2000/xmlns/.
44 *
45 * @author IBM
46 * @author Neil Delima
47 * @see <a
48 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElHasAttrNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElHasAttrNS</a>
49 */
50@TestTargetClass(Element.class)
51public final class ElementHasAttributeNS extends DOMTestCase {
52
53    DOMDocumentBuilderFactory factory;
54
55    DocumentBuilder builder;
56
57    protected void setUp() throws Exception {
58        super.setUp();
59        try {
60            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
61                    .getConfiguration2());
62            builder = factory.getBuilder();
63        } catch (Exception e) {
64            fail("Unexpected exception" + e.getMessage());
65        }
66    }
67
68    protected void tearDown() throws Exception {
69        factory = null;
70        builder = null;
71        super.tearDown();
72    }
73
74    /**
75     * Runs the test case.
76     *
77     * @throws Throwable
78     *             Any uncaught exception causes test to fail
79     */
80    @TestTargetNew(
81        level = TestLevel.PARTIAL,
82        notes = "Doesn't verify DOMException.",
83        method = "hasAttributeNS",
84        args = {java.lang.String.class, java.lang.String.class}
85    )
86    public void _testHasAttributeNS1() throws Throwable {
87        Document doc;
88        Element element;
89        boolean state;
90        NodeList elementList;
91        doc = (Document) load("staffNS", builder);
92        elementList = doc.getElementsByTagNameNS("*", "employee");
93        element = (Element) elementList.item(0);
94        state = element
95                .hasAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns");
96        assertTrue("elementhasattributens01", state);
97    }
98    @TestTargetNew(
99        level = TestLevel.PARTIAL,
100        notes = "Doesn't verify DOMException.",
101        method = "hasAttributeNS",
102        args = {java.lang.String.class, java.lang.String.class}
103    )
104    public void testHasAttributeNS2() throws Throwable {
105        Document doc;
106        Element element;
107        boolean state;
108        Attr attribute;
109
110        doc = (Document) load("staff", builder);
111        element = doc.createElementNS("http://www.w3.org/DOM", "address");
112        attribute = doc.createAttributeNS("http://www.w3.org/DOM", "domestic");
113        element.setAttributeNode(attribute);
114        state = element.hasAttributeNS("http://www.w3.org/DOM", "domestic");
115        assertTrue("hasDomesticAttr", state);
116    }
117    @TestTargetNew(
118        level = TestLevel.PARTIAL,
119        notes = "Doesn't verify DOMException.",
120        method = "hasAttributeNS",
121        args = {java.lang.String.class, java.lang.String.class}
122    )
123    public void testHasAttributeNS3() throws Throwable {
124        Document doc;
125        Element element;
126        boolean state;
127        Attr attribute;
128
129        String nullNS = null;
130
131        doc = (Document) load("staff", builder);
132        element = doc.createElementNS("http://www.w3.org/DOM", "address");
133        assertNotNull("createElementNotNull", element);
134        attribute = doc.createAttributeNS(nullNS, "domestic");
135        element.setAttributeNode(attribute);
136        state = element.hasAttributeNS(nullNS, "domestic");
137        assertTrue("elementhasattributens03", state);
138    }
139}
140