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-2003 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.Attr;
     25 import org.w3c.dom.Document;
     26 import org.w3c.dom.NodeList;
     27 import org.w3c.dom.Element;
     28 import org.w3c.dom.Node;
     29 
     30 import javax.xml.parsers.DocumentBuilder;
     31 
     32 /**
     33  * The "getNamespaceURI()" method for an Attribute returns the namespace URI of
     34  * this node, or null if unspecified.
     35  *
     36  * Retrieve the first "emp:address" node which has an attribute of
     37  * "emp:district" that is specified in the DTD. Invoke the "getNamespaceURI()"
     38  * method on the attribute. The method should return "http://www.nist.gov".
     39  *
     40  * @author NIST
     41  * @author Mary Brady
     42  * @see <a
     43  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSname">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSname</a>
     44  * @see <a
     45  *      href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=238">http://www.w3.org/Bugs/Public/show_bug.cgi?id=238</a>
     46  */
     47 public final class NamespaceURI extends DOMTestCase {
     48 
     49     DOMDocumentBuilderFactory factory;
     50 
     51     DocumentBuilder builder;
     52 
     53     protected void setUp() throws Exception {
     54         super.setUp();
     55         try {
     56             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     57                     .getConfiguration2());
     58             builder = factory.getBuilder();
     59         } catch (Exception e) {
     60             fail("Unexpected exception" + e.getMessage());
     61         }
     62     }
     63 
     64     protected void tearDown() throws Exception {
     65         factory = null;
     66         builder = null;
     67         super.tearDown();
     68     }
     69 
     70     /**
     71      * Runs the test case.
     72      *
     73      * @throws Throwable
     74      *             Any uncaught exception causes test to fail
     75      */
     76 // Assumes validation.
     77 //    public void testGetNamespaceURI1() throws Throwable {
     78 //        Document doc;
     79 //        NodeList elementList;
     80 //        Element testAddr;
     81 //        Attr addrAttr;
     82 //        String attrNamespaceURI;
     83 //        doc = (Document) load("staffNS", builder);
     84 //        elementList = doc.getElementsByTagName("emp:address");
     85 //        testAddr = (Element) elementList.item(0);
     86 //        addrAttr = testAddr.getAttributeNodeNS("http://www.nist.gov",
     87 //                "district");
     88 //        attrNamespaceURI = addrAttr.getNamespaceURI();
     89 //        assertEquals("namespaceURI", "http://www.nist.gov", attrNamespaceURI);
     90 //    }
     91     public void testGetNamespaceURI2() throws Throwable {
     92         Document doc;
     93         NodeList elementList;
     94         Element testAddr;
     95         Attr addrAttr;
     96         String attrNamespaceURI;
     97         doc = (Document) load("staffNS", builder);
     98         elementList = doc.getElementsByTagName("emp:address");
     99         testAddr = (Element) elementList.item(0);
    100         assertNotNull("empAddressNotNull", testAddr);
    101         addrAttr = testAddr.getAttributeNodeNS("http://www.nist.gov",
    102                 "domestic");
    103         attrNamespaceURI = addrAttr.getNamespaceURI();
    104         assertEquals("namespaceURI", "http://www.nist.gov", attrNamespaceURI);
    105     }
    106     public void testGetNamespaceURI3() throws Throwable {
    107         Document doc;
    108         NodeList elementList;
    109         Node testEmployee;
    110         String employeeNamespace;
    111         doc = (Document) load("staffNS", builder);
    112         elementList = doc.getElementsByTagName("employee");
    113         testEmployee = elementList.item(0);
    114         assertNotNull("employeeNotNull", testEmployee);
    115         employeeNamespace = testEmployee.getNamespaceURI();
    116         assertEquals("namespaceURI", "http://www.nist.gov", employeeNamespace);
    117     }
    118     public void testGetNamespaceURI4() throws Throwable {
    119         Document doc;
    120         NodeList elementList;
    121         Node testEmployee;
    122         String employeeNamespace;
    123         doc = (Document) load("staffNS", builder);
    124         elementList = doc.getElementsByTagName("employee");
    125         testEmployee = elementList.item(1);
    126         employeeNamespace = testEmployee.getNamespaceURI();
    127         assertNull("throw_Null", employeeNamespace);
    128     }
    129 }
    130