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 dalvik.annotation.TestTargets;
     25 import dalvik.annotation.TestLevel;
     26 import dalvik.annotation.TestTargetNew;
     27 import dalvik.annotation.TestTargetClass;
     28 
     29 import org.w3c.dom.Element;
     30 import org.w3c.dom.Document;
     31 import org.w3c.dom.NodeList;
     32 import org.w3c.dom.Attr;
     33 
     34 import javax.xml.parsers.DocumentBuilder;
     35 
     36 /**
     37  * The "getAttributeNodeNS(namespaceURI,localName)" method retrieves an
     38  * attribute node by local name and NamespaceURI.
     39  *
     40  * Retrieve the first emp:address element node. The getAttributeNodeNS method
     41  * returns an Attr node, the "value" can be examined to ensure the proper
     42  * attribute node was retrieved. This attribute value should be null since there
     43  * is no such attribute.
     44  *
     45  * @author NIST
     46  * @author Mary Brady
     47  * @see <a
     48  *      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>
     49  */
     50 @TestTargetClass(Element.class)
     51 public final class GetAttributeNodeNS 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 = "getAttributeNodeNS",
     84         args = {java.lang.String.class, java.lang.String.class}
     85     )
     86     public void testGetAttributeNodeNS1() throws Throwable {
     87         String namespaceURI = "http://www.nist.gov";
     88         String localName = "invalidlocalname";
     89         Document doc;
     90         NodeList elementList;
     91         Element testAddr;
     92         Attr attribute;
     93         doc = (Document) load("staffNS", builder);
     94         elementList = doc.getElementsByTagName("emp:address");
     95         testAddr = (Element) elementList.item(0);
     96         assertNotNull("empAddrNotNull", testAddr);
     97         attribute = testAddr.getAttributeNodeNS(namespaceURI, localName);
     98         assertNull("throw_Null", attribute);
     99     }
    100     @TestTargetNew(
    101         level = TestLevel.PARTIAL,
    102         notes = "Doesn't verify DOMException.",
    103         method = "getAttributeNodeNS",
    104         args = {java.lang.String.class, java.lang.String.class}
    105     )
    106     public void testGetAttributeNodeNS2() throws Throwable {
    107         Document doc;
    108         NodeList elementList;
    109         Element testAddr;
    110         Attr attribute;
    111         String attrName;
    112         doc = (Document) load("staffNS", builder);
    113         elementList = doc.getElementsByTagName("emp:address");
    114         testAddr = (Element) elementList.item(0);
    115         assertNotNull("empAddrNotNull", testAddr);
    116         attribute = testAddr.getAttributeNodeNS("http://www.nist.gov",
    117                 "domestic");
    118         attrName = attribute.getNodeName();
    119         assertEquals("attrName", "emp:domestic", attrName);
    120     }
    121 }
    122