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 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 "setNamedItemNS(arg)" method for a
     35  *    NamedNodeMap should raise WRONG_DOCUMENT_ERR DOMException if arg was
     36  *    created from a different document than the one that created this map.
     37  *
     38  *    Create an attr node in a different document with qualifiedName equals
     39  *    "dmstc:domestic" and namespaceURI is "http://www.usa.com".
     40  *    Access the namednodemap of the first "address" element in this document.
     41  *    Invoke method setNamedItemNS(arg) with arg being the attr node from above.
     42  *    Method should raise WRONG_DOCUMENT_ERR 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='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])</a>
     46 * @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>
     47 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-setNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-setNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])</a>
     48 */
     49 public final class setNamedItemNS02 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 setNamedItemNS02(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     57       super(factory);
     58 
     59     //
     60     //   check if loaded documents are supported for content type
     61     //
     62     String contentType = getContentType();
     63     preload(contentType, "staffNS", true);
     64     preload(contentType, "staffNS", true);
     65     }
     66 
     67    /**
     68     * Runs the test case.
     69     * @throws Throwable Any uncaught exception causes test to fail
     70     */
     71    public void runTest() throws Throwable {
     72       String namespaceURI = "http://www.usa.com";
     73       String qualifiedName = "dmstc:domestic";
     74       Document doc;
     75       Document anotherDoc;
     76       Node arg;
     77       NodeList elementList;
     78       Node testAddress;
     79       NamedNodeMap attributes;
     80       Node setNode;
     81       doc = (Document) load("staffNS", true);
     82       anotherDoc = (Document) load("staffNS", true);
     83       arg = anotherDoc.createAttributeNS(namespaceURI, qualifiedName);
     84       arg.setNodeValue("Maybe");
     85       elementList = doc.getElementsByTagName("address");
     86       testAddress = elementList.item(0);
     87       attributes = testAddress.getAttributes();
     88 
     89       {
     90          boolean success = false;
     91          try {
     92             setNode = attributes.setNamedItemNS(arg);
     93           } catch (DOMException ex) {
     94             success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
     95          }
     96          assertTrue("throw_WRONG_DOCUMENT_ERR", success);
     97       }
     98 }
     99    /**
    100     *  Gets URI that identifies the test.
    101     *  @return uri identifier of test
    102     */
    103    public String getTargetURI() {
    104       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setNamedItemNS02";
    105    }
    106    /**
    107     * Runs this test from the command line.
    108     * @param args command line arguments
    109     */
    110    public static void main(final String[] args) {
    111         DOMTestCase.doMain(setNamedItemNS02.class, args);
    112    }
    113 }
    114 
    115