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.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 import org.w3c.dom.DOMException;
     31 
     32 import javax.xml.parsers.DocumentBuilder;
     33 
     34 /**
     35  * The method removeNamedItemNS removes a node specified by local name and
     36  * namespace
     37  *
     38  * Retreive an attribute node and then remove from the NamedNodeMap. Verify if
     39  * the attribute node was actually remove from the node map.
     40  *
     41  * @author IBM
     42  * @author Neil Delima
     43  * @see <a
     44  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D58B193">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D58B193</a>
     45  */
     46 public final class NamedNodeMapRemoveNamedItemNS extends DOMTestCase {
     47 
     48     DOMDocumentBuilderFactory factory;
     49 
     50     DocumentBuilder builder;
     51 
     52     protected void setUp() throws Exception {
     53         super.setUp();
     54         try {
     55             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     56                     .getConfiguration2());
     57             builder = factory.getBuilder();
     58         } catch (Exception e) {
     59             fail("Unexpected exception" + e.getMessage());
     60         }
     61     }
     62 
     63     protected void tearDown() throws Exception {
     64         factory = null;
     65         builder = null;
     66         super.tearDown();
     67     }
     68 
     69     /**
     70      * Runs the test case.
     71      *
     72      * @throws Throwable
     73      *             Any uncaught exception causes test to fail
     74      */
     75     public void testRemoveNamedItemNS1() throws Throwable {
     76         Document doc;
     77         NamedNodeMap attributes;
     78         Node element;
     79         Attr attribute;
     80         NodeList elementList;
     81         doc = (Document) load("staffNS", builder);
     82         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
     83                 "address");
     84         element = elementList.item(1);
     85         attributes = element.getAttributes();
     86         attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
     87                 "domestic");
     88         attribute = (Attr) attributes.getNamedItemNS("http://www.nist.gov",
     89                 "domestic");
     90         assertNull("namednodemapremovenameditemns01", attribute);
     91     }
     92 
     93 // Assumes validation.
     94 //    public void testRemoveNamedItemNS2() throws Throwable {
     95 //        Document doc;
     96 //        NamedNodeMap attributes;
     97 //        Node element;
     98 //        Attr attribute;
     99 //        NodeList elementList;
    100 //        String attrValue;
    101 //        String nullNS = null;
    102 //
    103 //        doc = (Document) load("staffNS", builder);
    104 //        elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
    105 //                "employee");
    106 //        element = elementList.item(1);
    107 //        attributes = element.getAttributes();
    108 //        attribute = (Attr) attributes.removeNamedItemNS(nullNS, "defaultAttr");
    109 //        attribute = (Attr) attributes.getNamedItemNS(nullNS, "defaultAttr");
    110 //        attrValue = attribute.getNodeValue();
    111 //        assertNotNull("namednodemapremovenameditemns02", attribute);
    112 //        assertEquals("namednodemapremovenameditemns02_attrValue", "defaultVal",
    113 //                attrValue);
    114 //    }
    115     public void testRemoveNamedItemNS3() throws Throwable {
    116         Document doc;
    117         NamedNodeMap attributes;
    118         Node element;
    119         Attr attribute;
    120 
    121         Attr attribute1;
    122         Attr attribute2;
    123         String nodeName;
    124         doc = (Document) load("staffNS", builder);
    125         element = doc.createElementNS("http://www.w3.org/DOM/Test", "root");
    126         attribute1 = doc
    127                 .createAttributeNS("http://www.w3.org/DOM/L1", "L1:att");
    128         ((Element) /* Node */element).setAttributeNodeNS(attribute1);
    129         attribute2 = doc
    130                 .createAttributeNS("http://www.w3.org/DOM/L2", "L2:att");
    131         ((Element) /* Node */element).setAttributeNodeNS(attribute2);
    132         attributes = element.getAttributes();
    133         attribute = (Attr) attributes.removeNamedItemNS(
    134                 "http://www.w3.org/DOM/L1", "att");
    135         attribute = (Attr) attributes.getNamedItemNS(
    136                 "http://www.w3.org/DOM/L2", "att");
    137         nodeName = attribute.getNodeName();
    138         assertEquals("namednodemapremovenameditemns02", "L2:att", nodeName);
    139     }
    140     public void _testRemoveNamedItemNS4() throws Throwable {
    141         Document doc;
    142         NamedNodeMap attributes;
    143         Node element;
    144         Attr attribute;
    145 
    146         NodeList elementList;
    147         doc = (Document) load("staffNS", builder);
    148         elementList = doc.getElementsByTagNameNS("*", "employee");
    149         element = elementList.item(0);
    150         attributes = element.getAttributes();
    151         attributes.removeNamedItemNS("http://www.w3.org/2000/xmlns/", "xmlns");
    152         attribute = (Attr) attributes.getNamedItemNS(
    153                 "http://www.w3.org/2000/xmlns/", "xmlns");
    154         assertNull("namednodemapremovenameditemns04_1", attribute);
    155         attributes.removeNamedItemNS("http://www.w3.org/2000/xmlns/", "dmstc");
    156         attribute = (Attr) attributes.getNamedItemNS(
    157                 "http://www.w3.org/2000/xmlns/", "dmstc");
    158         assertNull("namednodemapremovenameditemns04_2", attribute);
    159     }
    160 
    161 // Assumes validation.
    162 //    public void testRemoveNamedItemNS5() throws Throwable {
    163 //        Document doc;
    164 //        DocumentType docType;
    165 //        NamedNodeMap entities;
    166 //        NamedNodeMap notations;
    167 //
    168 //        String nullNS = null;
    169 //
    170 //        doc = (Document) load("staffNS", builder);
    171 //        docType = doc.getDoctype();
    172 //        entities = docType.getEntities();
    173 //        assertNotNull("entitiesNotNull", entities);
    174 //        notations = docType.getNotations();
    175 //        assertNotNull("notationsNotNull", notations);
    176 //
    177 //        try {
    178 //            entities.removeNamedItemNS(nullNS, "ent1");
    179 //            fail("entity_throw_DOMException");
    180 //
    181 //        } catch (DOMException ex) {
    182 //            switch (ex.code) {
    183 //            case 8:
    184 //                break;
    185 //            case 7:
    186 //                break;
    187 //            default:
    188 //                throw ex;
    189 //            }
    190 //        }
    191 //
    192 //        try {
    193 //            notations.removeNamedItemNS(nullNS, "notation1");
    194 //            fail("notation_throw_DOMException");
    195 //
    196 //        } catch (DOMException ex) {
    197 //            switch (ex.code) {
    198 //            case 8:
    199 //                break;
    200 //            case 7:
    201 //                break;
    202 //            default:
    203 //                throw ex;
    204 //            }
    205 //        }
    206 //    }
    207     public void testRemoveNamedItemNS6() throws Throwable {
    208         Document doc;
    209         NamedNodeMap attributes;
    210         Node element;
    211 
    212         NodeList elementList;
    213         doc = (Document) load("staffNS", builder);
    214         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
    215                 "employee");
    216         element = elementList.item(1);
    217         attributes = element.getAttributes();
    218 
    219         {
    220             boolean success = false;
    221             try {
    222                 attributes.removeNamedItemNS("http://www.Nist.gov", "domestic");
    223             } catch (DOMException ex) {
    224                 success = (ex.code == DOMException.NOT_FOUND_ERR);
    225             }
    226             assertTrue("throw_NOT_FOUND_ERR", success);
    227         }
    228     }
    229     public void testRemoveNamedItemNS7() throws Throwable {
    230         Document doc;
    231         NamedNodeMap attributes;
    232         Node element;
    233 
    234         NodeList elementList;
    235         doc = (Document) load("staffNS", builder);
    236         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
    237                 "employee");
    238         element = elementList.item(1);
    239         attributes = element.getAttributes();
    240 
    241         {
    242             boolean success = false;
    243             try {
    244                 attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
    245             } catch (DOMException ex) {
    246                 success = (ex.code == DOMException.NOT_FOUND_ERR);
    247             }
    248             assertTrue("throw_NOT_FOUND_ERR", success);
    249         }
    250     }
    251     public void testRemoveNamedItemNS8() throws Throwable {
    252         Document doc;
    253         NamedNodeMap attributes;
    254         Element element;
    255 
    256         NodeList elementList;
    257         doc = (Document) load("staffNS", builder);
    258         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
    259                 "address");
    260         element = (Element) elementList.item(1);
    261         attributes = element.getAttributes();
    262         element.removeAttributeNS("http://www.nist.gov", "domestic");
    263 
    264         {
    265             boolean success = false;
    266             try {
    267                 attributes.removeNamedItemNS("http://www.nist.gov", "domestic");
    268             } catch (DOMException ex) {
    269                 success = (ex.code == DOMException.NOT_FOUND_ERR);
    270             }
    271             assertTrue("throw_NOT_FOUND_ERR", success);
    272         }
    273     }
    274     public void testRemoveNamedItemNS9() throws Throwable {
    275         Document doc;
    276         NamedNodeMap attributes;
    277         NamedNodeMap newAttributes;
    278         Element element;
    279         Attr attribute;
    280         NodeList elementList;
    281         doc = (Document) load("staffNS", builder);
    282         elementList = doc.getElementsByTagNameNS("http://www.nist.gov",
    283                 "address");
    284         element = (Element) elementList.item(1);
    285         attributes = element.getAttributes();
    286         attribute = (Attr) attributes.removeNamedItemNS("http://www.nist.gov",
    287                 "domestic");
    288         newAttributes = element.getAttributes();
    289         attribute = (Attr) newAttributes.getNamedItemNS("http://www.nist.gov",
    290                 "domestic");
    291         assertNull("namednodemapremovenameditemns09", attribute);
    292     }
    293 
    294 }
    295