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.NamedNodeMap;
     25 import org.w3c.dom.Document;
     26 import org.w3c.dom.Node;
     27 import org.w3c.dom.NodeList;
     28 import org.w3c.dom.Attr;
     29 import org.w3c.dom.Element;
     30 
     31 import javax.xml.parsers.DocumentBuilder;
     32 
     33 /**
     34  * Using the method getNamedItemNS, retreive the entity "ent1" and notation
     35  * "notation1" from a NamedNodeMap of this DocumentTypes entities and notations.
     36  * Both should be null since entities and notations are not namespaced.
     37  *
     38  * @author IBM
     39  * @author Neil Delima
     40  * @see <a
     41  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getNamedItemNS</a>
     42  * @see <a
     43  *      href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=259">http://www.w3.org/Bugs/Public/show_bug.cgi?id=259</a>
     44  * @see <a
     45  *      href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=407">http://www.w3.org/Bugs/Public/show_bug.cgi?id=407</a>
     46  * @see <a
     47  *      href="http://lists.w3.org/Archives/Member/w3c-dom-ig/2003Nov/0016.html">http://lists.w3.org/Archives/Member/w3c-dom-ig/2003Nov/0016.html</a>
     48  */
     49 public final class NamedNodeMapGetNamedItemNS extends DOMTestCase {
     50 
     51     DOMDocumentBuilderFactory factory;
     52 
     53     DocumentBuilder builder;
     54 
     55     protected void setUp() throws Exception {
     56         super.setUp();
     57         try {
     58             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     59                     .getConfiguration2());
     60             builder = factory.getBuilder();
     61         } catch (Exception e) {
     62             fail("Unexpected exception" + e.getMessage());
     63         }
     64     }
     65 
     66     protected void tearDown() throws Exception {
     67         factory = null;
     68         builder = null;
     69         super.tearDown();
     70     }
     71 
     72     /**
     73      * Runs the test case.
     74      *
     75      * @throws Throwable
     76      *             Any uncaught exception causes test to fail
     77      */
     78 // Assumes validation.
     79 //    public void testGetNamedItemNS1() throws Throwable {
     80 //        Document doc;
     81 //        DocumentType docType;
     82 //        NamedNodeMap entities;
     83 //        NamedNodeMap notations;
     84 //        Entity entity;
     85 //        Notation notation;
     86 //
     87 //        String nullNS = null;
     88 //
     89 //        doc = (Document) load("staffNS", builder);
     90 //        docType = doc.getDoctype();
     91 //        entities = docType.getEntities();
     92 //        assertNotNull("entitiesNotNull", entities);
     93 //        notations = docType.getNotations();
     94 //        assertNotNull("notationsNotNull", notations);
     95 //        entity = (Entity) entities.getNamedItemNS(nullNS, "ent1");
     96 //        assertNotNull("entityNull", entity);
     97 //        notation = (Notation) notations.getNamedItemNS(nullNS, "notation1");
     98 //        assertNotNull("notationNull", notation);
     99 //    }
    100     public void testGetNamedItemNS2() throws Throwable {
    101         Document doc;
    102         NamedNodeMap attributes;
    103         Node element;
    104         Attr attribute;
    105         NodeList elementList;
    106         String attrName;
    107         doc = (Document) load("staffNS", builder);
    108         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
    109                 "address");
    110         element = elementList.item(1);
    111         attributes = element.getAttributes();
    112         attribute = (Attr) attributes.getNamedItemNS("http://www.nist.gov",
    113                 "domestic");
    114         attrName = attribute.getNodeName();
    115         assertEquals("namednodemapgetnameditemns02", "emp:domestic", attrName);
    116     }
    117     public void testGetNamedItemNS3() throws Throwable {
    118         Document doc;
    119         NamedNodeMap attributes;
    120         Node element;
    121         Attr attribute;
    122         Attr newAttr1;
    123         Attr newAttr2;
    124 
    125         String attrName;
    126         doc = (Document) load("staffNS", builder);
    127         element = doc.createElementNS("http://www.w3.org/DOM/Test", "root");
    128         newAttr1 = doc.createAttributeNS("http://www.w3.org/DOM/L1", "L1:att");
    129         ((Element) /* Node */element).setAttributeNodeNS(newAttr1);
    130         newAttr2 = doc.createAttributeNS("http://www.w3.org/DOM/L2", "L2:att");
    131         ((Element) /* Node */element).setAttributeNodeNS(newAttr2);
    132         attributes = element.getAttributes();
    133         attribute = (Attr) attributes.getNamedItemNS(
    134                 "http://www.w3.org/DOM/L2", "att");
    135         attrName = attribute.getNodeName();
    136         assertEquals("namednodemapgetnameditemns03", "L2:att", attrName);
    137     }
    138     public void testGetNamedItemNS4() throws Throwable {
    139         Document doc;
    140         NamedNodeMap attributes;
    141         Element element;
    142         Attr attribute;
    143         Attr newAttr1;
    144         NodeList elementList;
    145         String attrName;
    146         doc = (Document) load("staffNS", builder);
    147         elementList = doc.getElementsByTagNameNS("*", "address");
    148         element = (Element) elementList.item(1);
    149         newAttr1 = doc.createAttributeNS("http://www.w3.org/DOM/L1", "street");
    150         element.setAttributeNodeNS(newAttr1);
    151         attributes = element.getAttributes();
    152         attribute = (Attr) attributes.getNamedItemNS(
    153                 "http://www.w3.org/DOM/L1", "street");
    154         attrName = attribute.getNodeName();
    155         assertEquals("namednodemapgetnameditemns04", "street", attrName);
    156     }
    157     public void testGetNamedItemNS5() throws Throwable {
    158         Document doc;
    159         NamedNodeMap attributes;
    160         Node element;
    161         Attr attribute;
    162         NodeList elementList;
    163         doc = (Document) load("staffNS", builder);
    164         elementList = doc.getElementsByTagNameNS("*", "address");
    165         element = elementList.item(1);
    166         attributes = element.getAttributes();
    167         attribute = (Attr) attributes.getNamedItemNS("*", "street");
    168         assertNull("namednodemapgetnameditemns05", attribute);
    169     }
    170 
    171 // Assumes validation.
    172 //    public void testGetNamedItemNS6() throws Throwable {
    173 //        Document doc;
    174 //        NamedNodeMap attributesMap1;
    175 //        NamedNodeMap attributesMap2;
    176 //        Element element;
    177 //        Attr attribute;
    178 //        Attr newAttr1;
    179 //
    180 //        NodeList elementList;
    181 //        String attrName;
    182 //        doc = (Document) load("staffNS", builder);
    183 //        elementList = doc.getElementsByTagNameNS("*", "address");
    184 //        element = (Element) elementList.item(1);
    185 //        attributesMap1 = element.getAttributes();
    186 //        attributesMap2 = element.getAttributes();
    187 //        newAttr1 = doc.createAttributeNS("http://www.w3.org/DOM/L1", "street");
    188 //        element.setAttributeNodeNS(newAttr1);
    189 //        attribute = (Attr) attributesMap1.getNamedItemNS(
    190 //                "http://www.w3.org/DOM/L1", "street");
    191 //        attrName = attribute.getNodeName();
    192 //        assertEquals("namednodemapgetnameditemnsMap106", "street", attrName);
    193 //        attribute = (Attr) attributesMap2.getNamedItemNS(
    194 //                "http://www.w3.org/DOM/L1", "street");
    195 //        attrName = attribute.getNodeName();
    196 //        assertEquals("namednodemapgetnameditemnsMap206", "street", attrName);
    197 //    }
    198 
    199 }
    200