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 org.w3c.dom.Element;
25import org.w3c.dom.Document;
26import org.w3c.dom.NodeList;
27import org.w3c.dom.Attr;
28
29import javax.xml.parsers.DocumentBuilder;
30
31/**
32 * The method hasAttributeNS returns true when an attribute with a given local
33 * name and namespace URI is specified on this element or has a default value,
34 * false otherwise.
35 *
36 * Retreive the first employee element node. Invoke the hasAttributeNS method to
37 * check if it has the xmlns attribute that belongs to the namespace
38 * http://www.w3.org/2000/xmlns/.
39 *
40 * @author IBM
41 * @author Neil Delima
42 * @see <a
43 *      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>
44 */
45public final class ElementHasAttributeNS 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                    .getConfiguration2());
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    public void _testHasAttributeNS1() throws Throwable {
75        Document doc;
76        Element element;
77        boolean state;
78        NodeList elementList;
79        doc = (Document) load("staffNS", builder);
80        elementList = doc.getElementsByTagNameNS("*", "employee");
81        element = (Element) elementList.item(0);
82        state = element
83                .hasAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns");
84        assertTrue("elementhasattributens01", state);
85    }
86    public void testHasAttributeNS2() throws Throwable {
87        Document doc;
88        Element element;
89        boolean state;
90        Attr attribute;
91
92        doc = (Document) load("staff", builder);
93        element = doc.createElementNS("http://www.w3.org/DOM", "address");
94        attribute = doc.createAttributeNS("http://www.w3.org/DOM", "domestic");
95        element.setAttributeNode(attribute);
96        state = element.hasAttributeNS("http://www.w3.org/DOM", "domestic");
97        assertTrue("hasDomesticAttr", state);
98    }
99    public void testHasAttributeNS3() throws Throwable {
100        Document doc;
101        Element element;
102        boolean state;
103        Attr attribute;
104
105        String nullNS = null;
106
107        doc = (Document) load("staff", builder);
108        element = doc.createElementNS("http://www.w3.org/DOM", "address");
109        assertNotNull("createElementNotNull", element);
110        attribute = doc.createAttributeNS(nullNS, "domestic");
111        element.setAttributeNode(attribute);
112        state = element.hasAttributeNS(nullNS, "domestic");
113        assertTrue("elementhasattributens03", state);
114    }
115}
116