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 8Copyright (c) 2001 World Wide Web Consortium, 9(Massachusetts Institute of Technology, Institut National de 10Recherche en Informatique et en Automatique, Keio University). All 11Rights Reserved. This program is distributed under the W3C's Software 12Intellectual Property License. This program is distributed in the 13hope that it will be useful, but WITHOUT ANY WARRANTY; without even 14the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15PURPOSE. 16See W3C License http://www.w3.org/Consortium/Legal/ for more details. 17 18*/ 19 20package org.w3c.domts.level1.core; 21 22import org.w3c.dom.*; 23 24 25import org.w3c.domts.DOMTestCase; 26import org.w3c.domts.DOMTestDocumentBuilderFactory; 27 28 29 30/** 31 * The "insertBefore(newChild,refChild)" method inserts the 32 * node "newChild" before the node "refChild". 33 * 34 * Insert a newly created Element node before the eigth 35 * child of the second employee and check the "newChild" 36 * and "refChild" after insertion for correct placement. 37* @author NIST 38* @author Mary Brady 39* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-952280727">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-952280727</a> 40*/ 41public final class nodeinsertbefore extends DOMTestCase { 42 43 /** 44 * Constructor. 45 * @param factory document factory, may not be null 46 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 47 */ 48 public nodeinsertbefore(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 49 super(factory); 50 51 // 52 // check if loaded documents are supported for content type 53 // 54 String contentType = getContentType(); 55 preload(contentType, "staff", true); 56 } 57 58 /** 59 * Runs the test case. 60 * @throws Throwable Any uncaught exception causes test to fail 61 */ 62 public void runTest() throws Throwable { 63 Document doc; 64 NodeList elementList; 65 Node employeeNode; 66 NodeList childList; 67 Node refChild; 68 Node newChild; 69 Node child; 70 String childName; 71 int length; 72 Node insertedNode; 73 java.util.List actual = new java.util.ArrayList(); 74 75 java.util.List expectedWithWhitespace = new java.util.ArrayList(); 76 expectedWithWhitespace.add("#text"); 77 expectedWithWhitespace.add("employeeId"); 78 expectedWithWhitespace.add("#text"); 79 expectedWithWhitespace.add("name"); 80 expectedWithWhitespace.add("#text"); 81 expectedWithWhitespace.add("position"); 82 expectedWithWhitespace.add("#text"); 83 expectedWithWhitespace.add("newChild"); 84 expectedWithWhitespace.add("salary"); 85 expectedWithWhitespace.add("#text"); 86 expectedWithWhitespace.add("gender"); 87 expectedWithWhitespace.add("#text"); 88 expectedWithWhitespace.add("address"); 89 expectedWithWhitespace.add("#text"); 90 91 java.util.List expectedWithoutWhitespace = new java.util.ArrayList(); 92 expectedWithoutWhitespace.add("employeeId"); 93 expectedWithoutWhitespace.add("name"); 94 expectedWithoutWhitespace.add("position"); 95 expectedWithoutWhitespace.add("newChild"); 96 expectedWithoutWhitespace.add("salary"); 97 expectedWithoutWhitespace.add("gender"); 98 expectedWithoutWhitespace.add("address"); 99 100 java.util.List expected = new java.util.ArrayList(); 101 102 doc = (Document) load("staff", true); 103 elementList = doc.getElementsByTagName("employee"); 104 employeeNode = elementList.item(1); 105 childList = employeeNode.getChildNodes(); 106 length = (int) childList.getLength(); 107 108 if (equals(6, length)) { 109 refChild = childList.item(3); 110 expected = expectedWithoutWhitespace; 111 } else { 112 refChild = childList.item(7); 113 expected = expectedWithWhitespace; 114 } 115 116 newChild = doc.createElement("newChild"); 117 insertedNode = employeeNode.insertBefore(newChild, refChild); 118 for (int indexN100DC = 0; indexN100DC < childList.getLength(); indexN100DC++) { 119 child = (Node) childList.item(indexN100DC); 120 childName = child.getNodeName(); 121 actual.add(childName); 122 } 123 assertEquals("nodeNames", expected, actual); 124 } 125 /** 126 * Gets URI that identifies the test. 127 * @return uri identifier of test 128 */ 129 public String getTargetURI() { 130 return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeinsertbefore"; 131 } 132 /** 133 * Runs this test from the command line. 134 * @param args command line arguments 135 */ 136 public static void main(final String[] args) { 137 DOMTestCase.doMain(nodeinsertbefore.class, args); 138 } 139} 140 141