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(importedNode,deep)" method for a 35 * Document should import the given importedNode into that Document. 36 * The importedNode is of type Attr. 37 * The ownerElement is set to null. Specified flag is set to true. 38 * Children is imported. 39 * 40 * Create a new attribute whose name is "elem:attr1" in a different document. 41 * Create a child Text node with value "importedText" for the attribute node above. 42 * Invoke method importNode(importedNode,deep) on this document with 43 * importedNode being the newly created attribute. 44 * Method should return a node whose name matches "elem:attr1" and a child node 45 * whose value equals "importedText". 46 * The returned node should belong to this document whose systemId is "staff.dtd" 47 * @author NIST 48 * @author Mary Brady 49 * @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> 50 */ 51 public final class importNode01 extends DOMTestCase { 52 53 /** 54 * Constructor. 55 * @param factory document factory, may not be null 56 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 57 */ 58 public importNode01(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 59 super(factory); 60 61 // 62 // check if loaded documents are supported for content type 63 // 64 String contentType = getContentType(); 65 preload(contentType, "staffNS", true); 66 preload(contentType, "staffNS", true); 67 } 68 69 /** 70 * Runs the test case. 71 * @throws Throwable Any uncaught exception causes test to fail 72 */ 73 public void runTest() throws Throwable { 74 Document doc; 75 Document aNewDoc; 76 Attr newAttr; 77 Text importedChild; 78 Node aNode; 79 Document ownerDocument; 80 Element attrOwnerElement; 81 DocumentType docType; 82 String system; 83 boolean specified; 84 NodeList childList; 85 String nodeName; 86 Node child; 87 String childValue; 88 java.util.List result = new java.util.ArrayList(); 89 90 java.util.List expectedResult = new java.util.ArrayList(); 91 expectedResult.add("elem:attr1"); 92 expectedResult.add("importedText"); 93 94 doc = (Document) load("staffNS", true); 95 aNewDoc = (Document) load("staffNS", true); 96 newAttr = aNewDoc.createAttribute("elem:attr1"); 97 importedChild = aNewDoc.createTextNode("importedText"); 98 aNode = newAttr.appendChild(importedChild); 99 aNode = doc.importNode(newAttr, false); 100 ownerDocument = aNode.getOwnerDocument(); 101 docType = ownerDocument.getDoctype(); 102 system = docType.getSystemId(); 103 assertNotNull("aNode", aNode); 104 assertURIEquals("systemId", null, null, null, "staffNS.dtd", null, null, null, null, system); 105 attrOwnerElement = ((Attr) /*Node */aNode).getOwnerElement(); 106 assertNull("ownerElement", attrOwnerElement); 107 specified = ((Attr) /*Node */aNode).getSpecified(); 108 assertTrue("specified", specified); 109 childList = aNode.getChildNodes(); 110 assertSize("childList", 1, childList); 111 nodeName = aNode.getNodeName(); 112 assertEquals("nodeName", "elem:attr1", nodeName); 113 child = aNode.getFirstChild(); 114 childValue = child.getNodeValue(); 115 assertEquals("childValue", "importedText", childValue); 116 } 117 /** 118 * Gets URI that identifies the test. 119 * @return uri identifier of test 120 */ 121 public String getTargetURI() { 122 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/importNode01"; 123 } 124 /** 125 * Runs this test from the command line. 126 * @param args command line arguments 127 */ 128 public static void main(final String[] args) { 129 DOMTestCase.doMain(importNode01.class, args); 130 } 131 } 132 133