00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 package org.w3c.domts.level1.core;
00021
00022 import org.w3c.dom.*;
00023 import org.w3c.dom.html.*;
00024 import org.w3c.dom.events.*;
00025 import org.w3c.domts.*;
00026 import javax.xml.parsers.*;
00027 import java.util.*;
00028
00029
00030
00044 public class nodeinsertbefore extends DOMTestCase {
00045
00046 public nodeinsertbefore(DOMTestDocumentBuilderFactory factory)
00047 {
00048 super(factory);
00049
00050 }
00051
00052 public void runTest() throws java.lang.Throwable {
00053 Document doc;
00054 NodeList elementList;
00055 Node employeeNode;
00056 NodeList childList;
00057 Node refChild;
00058 Node newChild;
00059 Node child;
00060 String childName;
00061 Node insertedNode;
00062 List actual = new ArrayList();
00063
00064 List expectedWithWhitespace = new ArrayList();
00065 expectedWithWhitespace.add("#text");
00066 expectedWithWhitespace.add("employeeId");
00067 expectedWithWhitespace.add("#text");
00068 expectedWithWhitespace.add("name");
00069 expectedWithWhitespace.add("#text");
00070 expectedWithWhitespace.add("position");
00071 expectedWithWhitespace.add("#text");
00072 expectedWithWhitespace.add("newChild");
00073 expectedWithWhitespace.add("salary");
00074 expectedWithWhitespace.add("#text");
00075 expectedWithWhitespace.add("gender");
00076 expectedWithWhitespace.add("#text");
00077 expectedWithWhitespace.add("address");
00078 expectedWithWhitespace.add("#text");
00079
00080 List expectedWithoutWhitespace = new ArrayList();
00081 expectedWithoutWhitespace.add("employeeId");
00082 expectedWithoutWhitespace.add("name");
00083 expectedWithoutWhitespace.add("position");
00084 expectedWithoutWhitespace.add("newChild");
00085 expectedWithoutWhitespace.add("salary");
00086 expectedWithoutWhitespace.add("gender");
00087 expectedWithoutWhitespace.add("address");
00088
00089 List expected = new ArrayList();
00090
00091 doc = load("staff");
00092 elementList = doc.getElementsByTagName("employee");
00093 employeeNode = elementList.item(1);
00094 childList = employeeNode.getChildNodes();
00095
00096 if(
00097 isIgnoringElementContentWhitespace()
00098 ) {
00099 refChild = childList.item(3);
00100 expected = expectedWithoutWhitespace;
00101
00102 }
00103
00104 else {
00105 refChild = childList.item(7);
00106 expected = expectedWithWhitespace;
00107
00108 }
00109 newChild = doc.createElement("newChild");
00110 insertedNode = employeeNode.insertBefore(newChild,refChild);
00111 for(int _index = 0; _index < childList.getLength();_index++) {
00112 child = ( Node ) childList.item(_index);
00113 childName = child.getNodeName();
00114 actual.add(childName);
00115
00116 }
00117 assertEquals("nodeNames",expected,actual);
00118
00119 }
00120 public String getTargetURI() {
00121 return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeinsertbefore";
00122 }
00123 public static void main(String[] args) {
00124 DOMTestCase.doMain(nodeinsertbefore.class,args);
00125 }
00126 }