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.TestTargetClass;
     25 
     26 import javax.xml.parsers.DocumentBuilder;
     27 
     28 import org.w3c.dom.Attr;
     29 import org.w3c.dom.DOMException;
     30 import org.w3c.dom.Document;
     31 import org.w3c.dom.Element;
     32 import org.w3c.dom.Node;
     33 import org.w3c.dom.NodeList;
     34 
     35 /**
     36  * The "removeAttributeNS(namespaceURI,localName)" method for an attribute
     37  * causes the DOMException NO_MODIFICATION_ALLOWED_ERR to be raised if the node
     38  * is readonly.
     39  *
     40  * Obtain the children of the THIRD "gender" element. The elements content is an
     41  * entity reference. Try to remove an attribute from the entity reference by
     42  * executing the "removeAttributeNS(namespaceURI,localName)" method. This causes
     43  * a NO_MODIFICATION_ALLOWED_ERR DOMException to be thrown.
     44  *
     45  * @author NIST
     46  * @author Mary Brady
     47  * @see <a
     48  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])</a>
     49  * @see <a
     50  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS</a>
     51  * @see <a
     52  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElRemAtNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElRemAtNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])</a>
     53  */
     54 @TestTargetClass(Attr.class)
     55 public final class RemoveAttributeNS extends DOMTestCase {
     56 
     57     DOMDocumentBuilderFactory factory;
     58 
     59     DocumentBuilder builder;
     60 
     61     protected void setUp() throws Exception {
     62         super.setUp();
     63         try {
     64             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     65                     .getConfiguration2());
     66             builder = factory.getBuilder();
     67         } catch (Exception e) {
     68             fail("Unexpected exception" + e.getMessage());
     69         }
     70     }
     71 
     72     protected void tearDown() throws Exception {
     73         factory = null;
     74         builder = null;
     75         super.tearDown();
     76     }
     77 
     78     /**
     79      * Runs the test case.
     80      *
     81      * @throws Throwable
     82      *             Any uncaught exception causes test to fail
     83      */
     84 // Assumes validation.
     85 //    public void testRemoveAttributeNS1() throws Throwable {
     86 //        Document doc;
     87 //        NodeList genderList;
     88 //        Node gender;
     89 //        Node gen;
     90 //        NodeList gList;
     91 //        Element genElement;
     92 //        int nodeType;
     93 //        doc = (Document) load("staffNS", builder);
     94 //        genderList = doc.getElementsByTagName("gender");
     95 //        gender = genderList.item(2);
     96 //        gen = gender.getFirstChild();
     97 //        nodeType = (int) gen.getNodeType();
     98 //
     99 //        if (1 == nodeType) {
    100 //            gen = doc.createEntityReference("ent4");
    101 //            assertNotNull("createdEntRefNotNull", gen);
    102 //        }
    103 //        gList = gen.getChildNodes();
    104 //        genElement = (Element) gList.item(0);
    105 //        assertNotNull("notnull", genElement);
    106 //
    107 //        {
    108 //            boolean success = false;
    109 //            try {
    110 //                genElement.removeAttributeNS("www.xyz.com", "local1");
    111 //            } catch (DOMException ex) {
    112 //                success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
    113 //            }
    114 //            assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success);
    115 //        }
    116 //    }
    117 
    118 // Assumes validation
    119 //    public void testRemoveAttributeNS2() throws Throwable {
    120 //        Document doc;
    121 //        NodeList elementList;
    122 //        Node testAddr;
    123 //        Attr addrAttr;
    124 //        String attr;
    125 //        String namespaceURI;
    126 //        String localName;
    127 //        String prefix;
    128 //        doc = (Document) load("staffNS", builder);
    129 //        elementList = doc.getElementsByTagName("emp:address");
    130 //        testAddr = elementList.item(0);
    131 //        ((Element) /* Node */testAddr).removeAttributeNS("http://www.nist.gov",
    132 //                "local1");
    133 //        elementList = doc.getElementsByTagName("emp:address");
    134 //        testAddr = elementList.item(0);
    135 //        addrAttr = ((Element) /* Node */testAddr).getAttributeNodeNS(
    136 //                "http://www.nist.gov", "local1");
    137 //        attr = ((Element) /* Node */testAddr).getAttributeNS(
    138 //                "http://www.nist.gov", "local1");
    139 //        namespaceURI = addrAttr.getNamespaceURI();
    140 //        localName = addrAttr.getLocalName();
    141 //        prefix = testAddr.getPrefix();
    142 //        assertEquals("attr", "FALSE", attr);
    143 //        assertEquals("uri", "http://www.nist.gov", namespaceURI);
    144 //        assertEquals("lname", "local1", localName);
    145 //        assertEquals("prefix", "emp", prefix);
    146 //    }
    147 }
    148