Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,8 @@ Authors:
<include name="schema/config/SurrogatePairLengthTest.class"/>
<include name="schema/config/UseGrammarPoolOnly_True_Test.class"/>
<include name="schema/config/UnparsedEntityCheckingTest.class"/>
-->
-->
<include name="dom/treewalker/TestFirstChild.class"/>
<include name="schema/Test.class"/>
<include name="jaxp/JAXPSpecTest.class"/>
<include name="dom/ids/Test.class"/>
Expand Down
59 changes: 35 additions & 24 deletions tests/dom/treewalker/TestFirstChild.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import junit.framework.TestCase;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
Expand All @@ -41,32 +43,41 @@
* @author Christian Geuer-Pollmann <geuer-pollmann@nue.et-inf.uni-siegen.de>
* @version $Id$
*/
public class TestFirstChild {

public static void main(String args[]) throws Exception {

public class TestFirstChild extends TestCase {

System.out.println(" --- "
+ org.apache.xerces.impl.Version.getVersion()
+ " --- ");
public void testTreeWalkerFirstChild() throws Exception {
Document doc = getNodeSet1();
NodeFilter nodefilter = null;
boolean entityReferenceExpansion = true;
int whatToShow = NodeFilter.SHOW_ALL;
TreeWalker treewalker =
((DocumentTraversal) doc).createTreeWalker(doc, whatToShow,
nodefilter, entityReferenceExpansion);
ByteArrayOutputStream bytearrayoutputstream =
new ByteArrayOutputStream();
PrintWriter printwriter =
new PrintWriter(new OutputStreamWriter(bytearrayoutputstream,
"UTF8"));

process2(treewalker, printwriter);
printwriter.flush();

System.out.println();
System.out.println("Testing the following XML document:\n" + new String(bytearrayoutputstream.toByteArray()));
TreeWalker treewalker = ((DocumentTraversal) doc).createTreeWalker(
doc, NodeFilter.SHOW_ALL, null, true);

// Starting at document, first child should be RootElement
Node first = treewalker.firstChild();
assertNotNull("Should have first child", first);
assertEquals("RootElement", first.getNodeName());

// First child of RootElement should be Element1
Node child = treewalker.firstChild();
assertNotNull("RootElement should have children", child);
assertEquals("Element1", child.getNodeName());

// Next sibling should be Element2
Node next = treewalker.nextSibling();
assertNotNull("Should have next sibling", next);
assertEquals("Element2", next.getNodeName());

// Next sibling should be Element3
next = treewalker.nextSibling();
assertNotNull("Should have next sibling", next);
assertEquals("Element3", next.getNodeName());

// First child of Element3 should be text node
child = treewalker.firstChild();
assertNotNull("Element3 should have text child", child);
assertEquals(Node.TEXT_NODE, child.getNodeType());
assertEquals("Text in Element3", child.getNodeValue());

// Should be no next sibling for this text node
assertNull("Text node should have no next sibling", treewalker.nextSibling());
}

/**
Expand Down
Loading