Home | History | Annotate | Download | only in dom
      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 
     22 package tests.org.w3c.dom;
     23 
     24 import org.w3c.dom.Element;
     25 import org.w3c.dom.Document;
     26 import org.w3c.dom.NodeList;
     27 
     28 import javax.xml.parsers.DocumentBuilder;
     29 
     30 /**
     31  *
     32  * The "hasAttributeNS()" method for an Element should return false if the
     33  * element does not have an attribute with the given local name and/or a
     34  * namespace URI specified on this element or does not have a default value.
     35  * Retrieve the first "address" element and the "hasAttributeNS()" method should
     36  * return false since the element has "nomatch" as the local name and
     37  * "http://www.usa.com" as the namespace URI.
     38  *
     39  * @author NIST
     40  * @author Mary Brady
     41  * @see <a
     42  *      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>
     43  */
     44 public final class HasAttributeNS extends DOMTestCase {
     45 
     46     DOMDocumentBuilderFactory factory;
     47 
     48     DocumentBuilder builder;
     49 
     50     protected void setUp() throws Exception {
     51         super.setUp();
     52         try {
     53             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     54                     .getConfiguration2());
     55             builder = factory.getBuilder();
     56         } catch (Exception e) {
     57             fail("Unexpected exception" + e.getMessage());
     58         }
     59     }
     60 
     61     protected void tearDown() throws Exception {
     62         factory = null;
     63         builder = null;
     64         super.tearDown();
     65     }
     66 
     67     /**
     68      * Runs the test case.
     69      *
     70      * @throws Throwable
     71      *             Any uncaught exception causes test to fail
     72      */
     73     public void testHasAttributeNS1() throws Throwable {
     74         String localName = "nomatch";
     75         String namespaceURI = "http://www.usa.com";
     76         Document doc;
     77         NodeList elementList;
     78         Element testNode;
     79         boolean state;
     80         doc = (Document) load("staffNS", builder);
     81         elementList = doc.getElementsByTagName("address");
     82         testNode = (Element) elementList.item(0);
     83         state = testNode.hasAttributeNS(namespaceURI, localName);
     84         assertFalse("throw_False", state);
     85     }
     86     public void testHasAttributeNS2() throws Throwable {
     87         String localName = "domestic";
     88         String namespaceURI = "http://www.nomatch.com";
     89         Document doc;
     90         NodeList elementList;
     91         Element testNode;
     92         boolean state;
     93         doc = (Document) load("staffNS", builder);
     94         elementList = doc.getElementsByTagName("address");
     95         testNode = (Element) elementList.item(0);
     96         state = testNode.hasAttributeNS(namespaceURI, localName);
     97         assertFalse("throw_False", state);
     98     }
     99     public void testHasAttributeNS3() throws Throwable {
    100         String localName = "blank";
    101         String namespaceURI = "http://www.nist.gov";
    102         Document doc;
    103         NodeList elementList;
    104         Element testNode;
    105         boolean state;
    106         doc = (Document) load("staffNS", builder);
    107         elementList = doc.getElementsByTagName("emp:address");
    108         testNode = (Element) elementList.item(0);
    109         assertNotNull("empAddrNotNull", testNode);
    110         state = testNode.hasAttributeNS(namespaceURI, localName);
    111         assertFalse("throw_False", state);
    112     }
    113 
    114 // Assumes validation.
    115 //    public void testHasAttributeNS4() throws Throwable {
    116 //        String localName = "district";
    117 //        String namespaceURI = "http://www.nist.gov";
    118 //        Document doc;
    119 //        NodeList elementList;
    120 //        Element testNode;
    121 //        boolean state;
    122 //        doc = (Document) load("staffNS", builder);
    123 //        elementList = doc.getElementsByTagName("emp:address");
    124 //        testNode = (Element) elementList.item(0);
    125 //        assertNotNull("empAddressNotNull", testNode);
    126 //        state = testNode.hasAttributeNS(namespaceURI, localName);
    127 //        assertTrue("hasAttribute", state);
    128 //    }
    129     public void testHasAttributeNS5() throws Throwable {
    130         String localName = "domestic";
    131         String namespaceURI = "http://www.usa.com";
    132         Document doc;
    133         NodeList elementList;
    134         Element testNode;
    135         boolean state;
    136         doc = (Document) load("staffNS", builder);
    137         elementList = doc.getElementsByTagName("address");
    138         testNode = (Element) elementList.item(0);
    139         state = testNode.hasAttributeNS(namespaceURI, localName);
    140         assertTrue("hasAttribute", state);
    141     }
    142 }
    143