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-2004 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 import org.w3c.dom.Attr;
     28 
     29 import javax.xml.parsers.DocumentBuilder;
     30 
     31 /**
     32  * The "getAttributeNodeNS(namespaceURI,localName)" method retrieves an
     33  * attribute node by local name and NamespaceURI.
     34  *
     35  * Retrieve the first emp:address element node. The getAttributeNodeNS method
     36  * returns an Attr node, the "value" can be examined to ensure the proper
     37  * attribute node was retrieved. This attribute value should be null since there
     38  * is no such attribute.
     39  *
     40  * @author NIST
     41  * @author Mary Brady
     42  * @see <a
     43  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElGetAtNodeNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElGetAtNodeNS</a>
     44  */
     45 public final class GetAttributeNodeNS 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 testGetAttributeNodeNS1() throws Throwable {
     75         String namespaceURI = "http://www.nist.gov";
     76         String localName = "invalidlocalname";
     77         Document doc;
     78         NodeList elementList;
     79         Element testAddr;
     80         Attr attribute;
     81         doc = (Document) load("staffNS", builder);
     82         elementList = doc.getElementsByTagName("emp:address");
     83         testAddr = (Element) elementList.item(0);
     84         assertNotNull("empAddrNotNull", testAddr);
     85         attribute = testAddr.getAttributeNodeNS(namespaceURI, localName);
     86         assertNull("throw_Null", attribute);
     87     }
     88     public void testGetAttributeNodeNS2() throws Throwable {
     89         Document doc;
     90         NodeList elementList;
     91         Element testAddr;
     92         Attr attribute;
     93         String attrName;
     94         doc = (Document) load("staffNS", builder);
     95         elementList = doc.getElementsByTagName("emp:address");
     96         testAddr = (Element) elementList.item(0);
     97         assertNotNull("empAddrNotNull", testAddr);
     98         attribute = testAddr.getAttributeNodeNS("http://www.nist.gov",
     99                 "domestic");
    100         attrName = attribute.getNodeName();
    101         assertEquals("attrName", "emp:domestic", attrName);
    102     }
    103 }
    104