1
2/*
3This Java source file was generated by test-to-java.xsl
4and is a derived work from the source document.
5The source document contained the following notice:
6
7
8
9Copyright (c) 2001-2004 World Wide Web Consortium,
10(Massachusetts Institute of Technology, Institut National de
11Recherche en Informatique et en Automatique, Keio University).  All
12Rights Reserved.  This program is distributed under the W3C's Software
13Intellectual Property License.  This program is distributed in the
14hope that it will be useful, but WITHOUT ANY WARRANTY; without even
15the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16PURPOSE.
17
18See W3C License http://www.w3.org/Consortium/Legal/ for more details.
19
20
21*/
22
23package org.w3c.domts.level2.core;
24
25import org.w3c.dom.*;
26
27
28import org.w3c.domts.DOMTestCase;
29import 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=false, import the attribute, "emp:zone" of the
40 *  element node which is retreived by its elementId="CANADA", into the another document.
41 *  Check the parentNode, nodeName, nodeType and nodeValue of the imported node to
42 *  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*/
48public final class documentimportnode02 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 documentimportnode02(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
56
57      org.w3c.domts.DocumentBuilderSetting[] settings =
58          new org.w3c.domts.DocumentBuilderSetting[] {
59org.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, "staff", 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 docImported;
79      Element element;
80      Attr attr;
81      Node importedAttr;
82      String nodeName;
83      int nodeType;
84      String nodeValue;
85      NodeList addresses;
86      Node attrsParent;
87      doc = (Document) load("staffNS", true);
88      docImported = (Document) load("staff", true);
89      addresses = doc.getElementsByTagNameNS("http://www.nist.gov", "address");
90      element = (Element) addresses.item(1);
91      attr = element.getAttributeNodeNS("http://www.nist.gov", "zone");
92      importedAttr = docImported.importNode(attr, false);
93      nodeName = importedAttr.getNodeName();
94      nodeType = (int) importedAttr.getNodeType();
95      nodeValue = importedAttr.getNodeValue();
96      attrsParent = importedAttr.getParentNode();
97      assertNull("documentimportnode02_parentNull", attrsParent);
98      assertEquals("documentimportnode02_nodeName", "emp:zone", nodeName);
99      assertEquals("documentimportnode02_nodeType", 2, nodeType);
100      assertEquals("documentimportnode02_nodeValue", "CANADA", nodeValue);
101      }
102   /**
103    *  Gets URI that identifies the test.
104    *  @return uri identifier of test
105    */
106   public String getTargetURI() {
107      return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/documentimportnode02";
108   }
109   /**
110    * Runs this test from the command line.
111    * @param args command line arguments
112    */
113   public static void main(final String[] args) {
114        DOMTestCase.doMain(documentimportnode02.class, args);
115   }
116}
117
118