Home | History | Annotate | Download | only in core
      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 Copyright (c) 2001-2004 World Wide Web Consortium,
      9 (Massachusetts Institute of Technology, Institut National de
     10 Recherche en Informatique et en Automatique, Keio University). All
     11 Rights Reserved. This program is distributed under the W3C's Software
     12 Intellectual Property License. This program is distributed in the
     13 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
     14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     15 PURPOSE.
     16 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     17 
     18 */
     19 
     20 package org.w3c.domts.level1.core;
     21 
     22 import org.w3c.dom.*;
     23 
     24 
     25 import org.w3c.domts.DOMTestCase;
     26 import org.w3c.domts.DOMTestDocumentBuilderFactory;
     27 
     28 
     29 
     30 /**
     31  *     Retrieve the second employee and replace its TWELFTH
     32  *     child(address) with its SECOND child(employeeId).   After the
     33  *     replacement the second child should now be the one that used
     34  *     to be at the third position and the TWELFTH child should be the
     35  *     one that used to be at the SECOND position.
     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-785887307">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-785887307</a>
     39 */
     40 public final class nodereplacechildnewchildexists 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 nodereplacechildnewchildexists(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       Node oldChild = null;
     67 
     68       Node newChild = null;
     69 
     70       String childName;
     71       Node childNode;
     72       int length;
     73       java.util.List actual = new java.util.ArrayList();
     74 
     75       java.util.List expected = new java.util.ArrayList();
     76 
     77       java.util.List expectedWithoutWhitespace = new java.util.ArrayList();
     78       expectedWithoutWhitespace.add("name");
     79       expectedWithoutWhitespace.add("position");
     80       expectedWithoutWhitespace.add("salary");
     81       expectedWithoutWhitespace.add("gender");
     82       expectedWithoutWhitespace.add("employeeId");
     83 
     84       java.util.List expectedWithWhitespace = new java.util.ArrayList();
     85       expectedWithWhitespace.add("#text");
     86       expectedWithWhitespace.add("#text");
     87       expectedWithWhitespace.add("name");
     88       expectedWithWhitespace.add("#text");
     89       expectedWithWhitespace.add("position");
     90       expectedWithWhitespace.add("#text");
     91       expectedWithWhitespace.add("salary");
     92       expectedWithWhitespace.add("#text");
     93       expectedWithWhitespace.add("gender");
     94       expectedWithWhitespace.add("#text");
     95       expectedWithWhitespace.add("employeeId");
     96       expectedWithWhitespace.add("#text");
     97 
     98       Node replacedChild;
     99       doc = (Document) load("staff", true);
    100       elementList = doc.getElementsByTagName("employee");
    101       employeeNode = elementList.item(1);
    102       childList = employeeNode.getChildNodes();
    103       length = (int) childList.getLength();
    104 
    105       if (equals(13, length)) {
    106           newChild = childList.item(1);
    107       oldChild = childList.item(11);
    108       expected =  expectedWithWhitespace;
    109       } else {
    110           newChild = childList.item(0);
    111       oldChild = childList.item(5);
    112       expected =  expectedWithoutWhitespace;
    113       }
    114 
    115     replacedChild = employeeNode.replaceChild(newChild, oldChild);
    116       assertSame("return_value_same", oldChild, replacedChild);
    117 for (int indexN100DE = 0; indexN100DE < childList.getLength(); indexN100DE++) {
    118           childNode = (Node) childList.item(indexN100DE);
    119     childName = childNode.getNodeName();
    120       actual.add(childName);
    121         }
    122       assertEquals("childNames", expected, actual);
    123       }
    124    /**
    125     *  Gets URI that identifies the test.
    126     *  @return uri identifier of test
    127     */
    128    public String getTargetURI() {
    129       return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodereplacechildnewchildexists";
    130    }
    131    /**
    132     * Runs this test from the command line.
    133     * @param args command line arguments
    134     */
    135    public static void main(final String[] args) {
    136         DOMTestCase.doMain(nodereplacechildnewchildexists.class, args);
    137    }
    138 }
    139 
    140