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  *    Retrieve the last employee and attempt to set a new
     36  *    attribute node for its "employee" element.  The new
     37  *    attribute was created from a document other than the
     38  *    one that created this element, therefore a
     39  *    WRONG_DOCUMENT_ERR DOMException should be raised.
     40  *    This test uses the "createAttribute(newAttr)" method
     41  *    from the Document interface.
     42 * @author Curt Arnold
     43 * @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>
     44 * @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>
     45 * @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>
     46 * @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>
     47 */
     48 public final class hc_elementwrongdocumenterr 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 hc_elementwrongdocumenterr(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     56       super(factory);
     57 
     58     //
     59     //   check if loaded documents are supported for content type
     60     //
     61     String contentType = getContentType();
     62     preload(contentType, "hc_staff", true);
     63     preload(contentType, "hc_staff", false);
     64     }
     65 
     66    /**
     67     * Runs the test case.
     68     * @throws Throwable Any uncaught exception causes test to fail
     69     */
     70    public void runTest() throws Throwable {
     71       Document doc1;
     72       Document doc2;
     73       Attr newAttribute;
     74       NodeList addressElementList;
     75       Element testAddress;
     76       Attr attrAddress;
     77       doc1 = (Document) load("hc_staff", true);
     78       doc2 = (Document) load("hc_staff", false);
     79       newAttribute = doc2.createAttribute("newAttribute");
     80       addressElementList = doc1.getElementsByTagName("acronym");
     81       testAddress = (Element) addressElementList.item(4);
     82 
     83       {
     84          boolean success = false;
     85          try {
     86             attrAddress = testAddress.setAttributeNode(newAttribute);
     87           } catch (DOMException ex) {
     88             success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
     89          }
     90          assertTrue("throw_WRONG_DOCUMENT_ERR", success);
     91       }
     92 }
     93    /**
     94     *  Gets URI that identifies the test.
     95     *  @return uri identifier of test
     96     */
     97    public String getTargetURI() {
     98       return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementwrongdocumenterr";
     99    }
    100    /**
    101     * Runs this test from the command line.
    102     * @param args command line arguments
    103     */
    104    public static void main(final String[] args) {
    105         DOMTestCase.doMain(hc_elementwrongdocumenterr.class, args);
    106    }
    107 }
    108 
    109