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 method setNamedItemNS adds a node using its namespaceURI and localName and
     35  *  raises a WRONG_DOCUMENT_ERR if arg was created from a different document than the
     36  *  one that created this map.
     37  *
     38  *  Retreieve the second element whose local name is address and its attribute into a named node map.
     39  *  Do the same for another document and retreive its street attribute.  Call the setNamedItemNS
     40  *  using the first namedNodeMap and the retreive street attribute of the second.  This should
     41  *  raise a WRONG_DOCUMENT_ERR.
     42 * @author IBM
     43 * @author Neil Delima
     44 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS</a>
     45 * @see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=259">http://www.w3.org/Bugs/Public/show_bug.cgi?id=259</a>
     46 * @see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=408">http://www.w3.org/Bugs/Public/show_bug.cgi?id=408</a>
     47 */
     48 public final class namednodemapsetnameditemns03 extends DOMTestCase {
     49 
     50    /**
     51     * Constructor.
     52     * @param factory document factory, may not be null
     53     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     54     */
     55    public namednodemapsetnameditemns03(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     56 
     57       org.w3c.domts.DocumentBuilderSetting[] settings =
     58           new org.w3c.domts.DocumentBuilderSetting[] {
     59 org.w3c.domts.DocumentBuilderSetting.namespaceAware
     60         };
     61         DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
     62         setFactory(testFactory);
     63 
     64     //
     65     //   check if loaded documents are supported for content type
     66     //
     67     String contentType = getContentType();
     68     preload(contentType, "staffNS", true);
     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       Document docAlt;
     79       NamedNodeMap attributes;
     80       NamedNodeMap attributesAlt;
     81       NodeList elementList;
     82       NodeList elementListAlt;
     83       Element element;
     84       Element elementAlt;
     85       Attr attr;
     86       Node newNode;
     87       String nullNS = null;
     88 
     89       doc = (Document) load("staffNS", true);
     90       elementList = doc.getElementsByTagNameNS("*", "address");
     91       element = (Element) elementList.item(1);
     92       attributes = element.getAttributes();
     93       docAlt = (Document) load("staffNS", true);
     94       elementListAlt = docAlt.getElementsByTagNameNS("*", "address");
     95       elementAlt = (Element) elementListAlt.item(1);
     96       attributesAlt = elementAlt.getAttributes();
     97       attr = (Attr) attributesAlt.getNamedItemNS(nullNS, "street");
     98       newNode = attributesAlt.removeNamedItemNS(nullNS, "street");
     99 
    100       {
    101          boolean success = false;
    102          try {
    103             newNode = attributes.setNamedItemNS(attr);
    104           } catch (DOMException ex) {
    105             success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
    106          }
    107          assertTrue("throw_WRONG_DOCUMENT_ERR", success);
    108       }
    109 }
    110    /**
    111     *  Gets URI that identifies the test.
    112     *  @return uri identifier of test
    113     */
    114    public String getTargetURI() {
    115       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/namednodemapsetnameditemns03";
    116    }
    117    /**
    118     * Runs this test from the command line.
    119     * @param args command line arguments
    120     */
    121    public static void main(final String[] args) {
    122         DOMTestCase.doMain(namednodemapsetnameditemns03.class, args);
    123    }
    124 }
    125 
    126