nodeappendchilddocfragment.java revision a0881d052ee72e3f7e773374e9b1aa75fbd6be4c
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-2004 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 *     Create and populate a new DocumentFragment object and
32 *     append it to the second employee.   After the
33 *     "appendChild(newChild)" method is invoked retrieve the
34 *     new nodes at the end of the list, they should be the
35 *     two Element nodes from the DocumentFragment.
36* @author NIST
37* @author Mary Brady
38* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-184E7107">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-184E7107</a>
39*/
40public final class nodeappendchilddocfragment extends DOMTestCase {
41
42   /**
43    * Constructor.
44    * @param factory document factory, may not be null
45    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
46    */
47   public nodeappendchilddocfragment(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
48      super(factory);
49
50    //
51    //   check if loaded documents are supported for content type
52    //
53    String contentType = getContentType();
54    preload(contentType, "staff", true);
55    }
56
57   /**
58    * Runs the test case.
59    * @throws Throwable Any uncaught exception causes test to fail
60    */
61   public void runTest() throws Throwable {
62      Document doc;
63      NodeList elementList;
64      Node employeeNode;
65      NodeList childList;
66      DocumentFragment newdocFragment;
67      Node newChild1;
68      Node newChild2;
69      Node child;
70      String childName;
71      java.util.List result = new java.util.ArrayList();
72
73      int nodeType;
74      Node appendedChild;
75      java.util.List expected = new java.util.ArrayList();
76      expected.add("employeeId");
77      expected.add("name");
78      expected.add("position");
79      expected.add("salary");
80      expected.add("gender");
81      expected.add("address");
82      expected.add("newChild1");
83      expected.add("newChild2");
84
85      doc = (Document) load("staff", true);
86      elementList = doc.getElementsByTagName("employee");
87      employeeNode = elementList.item(1);
88      childList = employeeNode.getChildNodes();
89      newdocFragment = doc.createDocumentFragment();
90      newChild1 = doc.createElement("newChild1");
91      newChild2 = doc.createElement("newChild2");
92      appendedChild = newdocFragment.appendChild(newChild1);
93      appendedChild = newdocFragment.appendChild(newChild2);
94      appendedChild = employeeNode.appendChild(newdocFragment);
95      for (int indexN1009F = 0; indexN1009F < childList.getLength(); indexN1009F++) {
96          child = (Node) childList.item(indexN1009F);
97    nodeType = (int) child.getNodeType();
98
99      if (equals(1, nodeType)) {
100          childName = child.getNodeName();
101      result.add(childName);
102      }
103      }
104      assertEquals("elementNames", expected, result);
105      }
106   /**
107    *  Gets URI that identifies the test.
108    *  @return uri identifier of test
109    */
110   public String getTargetURI() {
111      return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeappendchilddocfragment";
112   }
113   /**
114    * Runs this test from the command line.
115    * @param args command line arguments
116    */
117   public static void main(final String[] args) {
118        DOMTestCase.doMain(nodeappendchilddocfragment.class, args);
119   }
120}
121
122