Home | History | Annotate | Download | only in core
      1 
      2 /*
      3 This Java source file was generated by test-to-java.xsl
      4 and is a derived work from the source document.
      5 The source document contained the following notice:
      6 
      7 
      8 
      9 Copyright (c) 2001-2004 World Wide Web Consortium,
     10 (Massachusetts Institute of Technology, Institut National de
     11 Recherche en Informatique et en Automatique, Keio University).  All
     12 Rights Reserved.  This program is distributed under the W3C's Software
     13 Intellectual Property License.  This program is distributed in the
     14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
     15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     16 PURPOSE.
     17 
     18 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     19 
     20 
     21 */
     22 
     23 package org.w3c.domts.level2.core;
     24 
     25 import org.w3c.dom.*;
     26 
     27 
     28 import org.w3c.domts.DOMTestCase;
     29 import org.w3c.domts.DOMTestDocumentBuilderFactory;
     30 
     31 
     32 
     33 /**
     34  *     The "removeAttributeNS(namespaceURI,localName)" method for an attribute causes the
     35  *    DOMException NO_MODIFICATION_ALLOWED_ERR to be raised
     36  *    if the node is readonly.
     37  *
     38  *    Obtain the children of the THIRD "gender" element.  The elements
     39  *    content is an entity reference.  Try to remove an attribute
     40  *    from the entity reference by executing the
     41  *    "removeAttributeNS(namespaceURI,localName)" method.
     42  *    This causes a NO_MODIFICATION_ALLOWED_ERR DOMException to be thrown.
     43 * @author NIST
     44 * @author Mary Brady
     45 * @see <a 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>
     46 * @see <a 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>
     47 * @see <a 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>
     48 */
     49 public final class removeAttributeNS01 extends DOMTestCase {
     50 
     51    /**
     52     * Constructor.
     53     * @param factory document factory, may not be null
     54     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     55     */
     56    public removeAttributeNS01(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     57 
     58       org.w3c.domts.DocumentBuilderSetting[] settings =
     59           new org.w3c.domts.DocumentBuilderSetting[] {
     60 org.w3c.domts.DocumentBuilderSetting.namespaceAware
     61         };
     62         DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
     63         setFactory(testFactory);
     64 
     65     //
     66     //   check if loaded documents are supported for content type
     67     //
     68     String contentType = getContentType();
     69     preload(contentType, "staffNS", true);
     70     }
     71 
     72    /**
     73     * Runs the test case.
     74     * @throws Throwable Any uncaught exception causes test to fail
     75     */
     76    public void runTest() throws Throwable {
     77       Document doc;
     78       NodeList genderList;
     79       Node gender;
     80       Node gen;
     81       NodeList gList;
     82       Element genElement;
     83       int nodeType;
     84       doc = (Document) load("staffNS", true);
     85       genderList = doc.getElementsByTagName("gender");
     86       gender = genderList.item(2);
     87       gen = gender.getFirstChild();
     88       nodeType = (int) gen.getNodeType();
     89 
     90       if (equals(1, nodeType)) {
     91           gen = doc.createEntityReference("ent4");
     92       assertNotNull("createdEntRefNotNull", gen);
     93       }
     94     gList = gen.getChildNodes();
     95       genElement = (Element) gList.item(0);
     96       assertNotNull("notnull", genElement);
     97 
     98       {
     99          boolean success = false;
    100          try {
    101             genElement.removeAttributeNS("www.xyz.com", "local1");
    102           } catch (DOMException ex) {
    103             success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
    104          }
    105          assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success);
    106       }
    107 }
    108    /**
    109     *  Gets URI that identifies the test.
    110     *  @return uri identifier of test
    111     */
    112    public String getTargetURI() {
    113       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/removeAttributeNS01";
    114    }
    115    /**
    116     * Runs this test from the command line.
    117     * @param args command line arguments
    118     */
    119    public static void main(final String[] args) {
    120         DOMTestCase.doMain(removeAttributeNS01.class, args);
    121    }
    122 }
    123 
    124