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 Copyright (c) 2001-2003 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 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     17 
     18 */
     19 
     20 package org.w3c.domts.level1.core;
     21 
     22 import org.w3c.dom.*;
     23 
     24 
     25 import org.w3c.domts.DOMTestCase;
     26 import org.w3c.domts.DOMTestDocumentBuilderFactory;
     27 
     28 
     29 
     30 /**
     31  *     The "setAttributeNode(newAttr)" method raises an
     32  *    "WRONG_DOCUMENT_ERR DOMException if the "newAttr"
     33  *    was created from a different document than the one that
     34  *    created this document.
     35  *
     36  *    Retrieve the last employee and attempt to set a new
     37  *    attribute node for its "employee" element.  The new
     38  *    attribute was created from a document other than the
     39  *    one that created this element, therefore a
     40  *    WRONG_DOCUMENT_ERR DOMException should be raised.
     41  *    This test uses the "createAttribute(newAttr)" method
     42  *    from the Document interface.
     43 * @author NIST
     44 * @author Mary Brady
     45 * @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='WRONG_DOCUMENT_ERR'])</a>
     46 * @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-887236154">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-887236154</a>
     47 * @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-887236154')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-887236154')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='WRONG_DOCUMENT_ERR'])</a>
     48 * @see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=249">http://www.w3.org/Bugs/Public/show_bug.cgi?id=249</a>
     49 */
     50 public final class elementwrongdocumenterr extends DOMTestCase {
     51 
     52    /**
     53     * Constructor.
     54     * @param factory document factory, may not be null
     55     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     56     */
     57    public elementwrongdocumenterr(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     58       super(factory);
     59 
     60     //
     61     //   check if loaded documents are supported for content type
     62     //
     63     String contentType = getContentType();
     64     preload(contentType, "staff", true);
     65     preload(contentType, "staff", false);
     66     }
     67 
     68    /**
     69     * Runs the test case.
     70     * @throws Throwable Any uncaught exception causes test to fail
     71     */
     72    public void runTest() throws Throwable {
     73       Document doc1;
     74       Document doc2;
     75       Attr newAttribute;
     76       NodeList addressElementList;
     77       Element testAddress;
     78       Attr attrAddress;
     79       doc1 = (Document) load("staff", true);
     80       doc2 = (Document) load("staff", false);
     81       newAttribute = doc2.createAttribute("newAttribute");
     82       addressElementList = doc1.getElementsByTagName("address");
     83       testAddress = (Element) addressElementList.item(4);
     84 
     85       {
     86          boolean success = false;
     87          try {
     88             attrAddress = testAddress.setAttributeNode(newAttribute);
     89           } catch (DOMException ex) {
     90             success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
     91          }
     92          assertTrue("throw_WRONG_DOCUMENT_ERR", success);
     93       }
     94 }
     95    /**
     96     *  Gets URI that identifies the test.
     97     *  @return uri identifier of test
     98     */
     99    public String getTargetURI() {
    100       return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/elementwrongdocumenterr";
    101    }
    102    /**
    103     * Runs this test from the command line.
    104     * @param args command line arguments
    105     */
    106    public static void main(final String[] args) {
    107         DOMTestCase.doMain(elementwrongdocumenterr.class, args);
    108    }
    109 }
    110 
    111