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 importNode method imports a node from another document to this document.
     35  *  The returned node has no parent; (parentNode is null). The source node is not
     36  *  altered or removed from the original document but a new copy of the source node
     37  *  is created.
     38  *
     39  *  Using the method importNode with deep=true, import the attribute, "street" of the second
     40  *  element node, from a list of nodes whose local names are "address" and namespaceURI
     41  *  "http://www.nist.gov" into the same document.  Check the parentNode, nodeName,
     42  *  nodeType and nodeValue of the imported node to verify if it has been imported correctly.
     43 * @author IBM
     44 * @author Neil Delima
     45 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core">http://www.w3.org/TR/DOM-Level-2-Core/core</a>
     46 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode">http://www.w3.org/TR/DOM-Level-2-Core/core#Core-Document-importNode</a>
     47 */
     48 public final class documentimportnode01 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 documentimportnode01(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     }
     70 
     71    /**
     72     * Runs the test case.
     73     * @throws Throwable Any uncaught exception causes test to fail
     74     */
     75    public void runTest() throws Throwable {
     76       Document doc;
     77       Element element;
     78       Attr attr;
     79       NodeList childList;
     80       Node importedAttr;
     81       String nodeName;
     82       int nodeType;
     83       String nodeValue;
     84       doc = (Document) load("staffNS", true);
     85       childList = doc.getElementsByTagNameNS("http://www.nist.gov", "address");
     86       element = (Element) childList.item(1);
     87       attr = element.getAttributeNode("street");
     88       importedAttr = doc.importNode(attr, false);
     89       nodeName = importedAttr.getNodeName();
     90       nodeValue = importedAttr.getNodeValue();
     91       nodeType = (int) importedAttr.getNodeType();
     92       assertEquals("documentimportnode01_nodeName", "street", nodeName);
     93       assertEquals("documentimportnode01_nodeType", 2, nodeType);
     94       assertEquals("documentimportnode01_nodeValue", "Yes", nodeValue);
     95       }
     96    /**
     97     *  Gets URI that identifies the test.
     98     *  @return uri identifier of test
     99     */
    100    public String getTargetURI() {
    101       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode01";
    102    }
    103    /**
    104     * Runs this test from the command line.
    105     * @param args command line arguments
    106     */
    107    public static void main(final String[] args) {
    108         DOMTestCase.doMain(documentimportnode01.class, args);
    109    }
    110 }
    111 
    112