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 "removeNamedItemNS(namespaceURI,localName)" method for a
     35  *   NamedNodeMap should raise NO_MODIFICATION_ALLOWED_ERR DOMException if
     36  *   this map is readonly.
     37  *
     38  *   Retrieve a list of "gender" elements. Get access to the THIRD element
     39  *   which contains an ENTITY_REFERENCE child node.  Try to remove the attribute
     40  *   in the node's map with method removeNamedItemNS(namespaceURI,localName).
     41  *   This should result in NO_MODIFICATION_ALLOWED_ERR
     42  *   DOMException.
     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-removeNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-removeNamedItemNS</a>
     47 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-removeNamedItemNS')/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-removeNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])</a>
     48 */
     49 public final class removeNamedItemNS03 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 removeNamedItemNS03(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       String namespaceURI = "http://www.w3.org/2000/xmlns/";
     78       String localName = "local1";
     79       Document doc;
     80       NodeList elementList;
     81       Node testAddress;
     82       NodeList nList;
     83       Node child;
     84       NodeList n2List;
     85       Node child2;
     86       NamedNodeMap attributes;
     87       Node removedNode;
     88       int nodeType;
     89       doc = (Document) load("staffNS", true);
     90       elementList = doc.getElementsByTagName("gender");
     91       testAddress = elementList.item(2);
     92       nList = testAddress.getChildNodes();
     93       child = nList.item(0);
     94       nodeType = (int) child.getNodeType();
     95 
     96       if (equals(1, nodeType)) {
     97           child = doc.createEntityReference("ent4");
     98       assertNotNull("createdEntRefNotNull", child);
     99       }
    100     n2List = child.getChildNodes();
    101       child2 = n2List.item(0);
    102       assertNotNull("notnull", child2);
    103       attributes = child2.getAttributes();
    104 
    105       {
    106          boolean success = false;
    107          try {
    108             removedNode = attributes.removeNamedItemNS(namespaceURI, localName);
    109           } catch (DOMException ex) {
    110             success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
    111          }
    112          assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success);
    113       }
    114 }
    115    /**
    116     *  Gets URI that identifies the test.
    117     *  @return uri identifier of test
    118     */
    119    public String getTargetURI() {
    120       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/removeNamedItemNS03";
    121    }
    122    /**
    123     * Runs this test from the command line.
    124     * @param args command line arguments
    125     */
    126    public static void main(final String[] args) {
    127         DOMTestCase.doMain(removeNamedItemNS03.class, args);
    128    }
    129 }
    130 
    131