[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit HtmlTablesTest.java,1.13,1.14 WebFormTes
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-12-26 04:59:38
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory sc8-pr-cvs1:/tmp/cvs-serv4153/test/com/meterware/httpunit
Modified Files:
HtmlTablesTest.java WebFormTest.java WebPageTest.java
XMLPageTest.java
Log Message:
Adding support for getElementWithID
Index: HtmlTablesTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HtmlTablesTest.java 25 Nov 2002 17:02:21 -0000 1.13
+++ HtmlTablesTest.java 26 Dec 2002 04:59:35 -0000 1.14
@@ -191,11 +191,17 @@
defineWebPage( "Default", "<h2>Interesting data</h2>" +
"<table id=you summary=\"outer one\">" +
"<tr><td>Here we are</td><td>" +
- "Inner Table<br>" +
- "<table id=me summary=\"inner one\">" +
+ "Inner Table 1<br>" +
+ "<table id=you summary='inner zero'>" +
" <tr><td colspan=2> </td></tr>" +
" <tr><td>Red</td><td>1</td></tr>" +
" <tr><td>Blue</td><td>2</td></tr>" +
+ "</table></td><td>" +
+ "Inner Table 2<br>" +
+ "<table id=me summary=\"inner one\">" +
+ " <tr><td colspan=2> </td></tr>" +
+ " <tr><td>Black</td><td>1</td></tr>" +
+ " <tr><td>White</td><td>2</td></tr>" +
"</table></td></tr>" +
"</table>" );
@@ -219,14 +225,14 @@
cells = wt.asText();
assertEquals( "Total rows", 3, cells.length );
assertEquals( "Total columns", 2, cells[0].length );
- assertEquals( "cell at 2,0", "Blue", cells[2][0] );
+ assertEquals( "cell at 2,0", "White", cells[2][0] );
wt = page.getTableWithID( "me" );
assertNotNull( "Did not find table with id 'me'", wt );
cells = wt.asText();
assertEquals( "Total rows", 3, cells.length );
assertEquals( "Total columns", 2, cells[0].length );
- assertEquals( "cell at 2,0", "Blue", cells[2][0] );
+ assertEquals( "cell at 2,0", "White", cells[2][0] );
}
Index: WebFormTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- WebFormTest.java 24 Oct 2002 13:28:55 -0000 1.28
+++ WebFormTest.java 26 Dec 2002 04:59:35 -0000 1.29
@@ -135,7 +135,7 @@
WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );
assertNull( "Found nonexistent form", page.getFormWithID( "nobody" ) );
- assertNotNull( "Did not find specified form", page.getFormWithID( "oneform" ) );
+ assertNotNull( "Did not find specified form", page.getFormWithID( "oneForm" ) );
}
Index: WebPageTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- WebPageTest.java 13 Nov 2002 14:01:24 -0000 1.26
+++ WebPageTest.java 26 Dec 2002 04:59:35 -0000 1.27
@@ -22,12 +22,14 @@
import com.meterware.pseudoserver.PseudoServlet;
import com.meterware.pseudoserver.WebResource;
+import java.io.PrintWriter;
+import java.io.FileWriter;
+import java.io.File;
+import java.io.IOException;
+
import junit.framework.Test;
import junit.framework.TestSuite;
-import java.io.*;
-import java.net.MalformedURLException;
-
/**
@@ -44,9 +46,6 @@
public static Test suite() {
-// DefaultWebResponse blankResponse = new DefaultWebResponse( null, null, WebResponse.BLANK_HTML );
-// HttpUnitOptions.getScriptingEngine().associate( blankResponse );
-
return new TestSuite( WebPageTest.class );
}
@@ -405,5 +404,21 @@
assertEquals( "Full string", "abcdefghijklmnopqrstuvwxyz", alphabet );
} catch (IOException e) {
}
+ }
+
+
+ public void testGetElementByID() throws Exception {
+ defineResource( "SimplePage.html",
+ "<html><head><title>A Sample Page</title></head>\n" +
+ "<body><form id='aForm'><input name=color></form>" +
+ "have <a id='link1' href='/other.html'>an <b>active</b> link</A>\n" +
+ "<img id='23' src='/images/arrow.gif' ALT='Next -->' WIDTH=1 HEIGHT=4>\n" +
+ "</body></html>\n" );
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.html" );
+ WebResponse simplePage = wc.getResponse( request );
+ assertImplements( "element with id 'aForm'", simplePage.getElementWithID( "aForm" ), WebForm.class );
+ assertImplements( "element with id 'link1'", simplePage.getElementWithID( "link1" ), WebLink.class );
+ assertImplements( "element with id '23'", simplePage.getElementWithID( "23" ), WebImage.class );
}
}
Index: XMLPageTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/XMLPageTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLPageTest.java 2 Apr 2001 19:03:54 -0000 1.1
+++ XMLPageTest.java 26 Dec 2002 04:59:35 -0000 1.2
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -19,11 +19,11 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-import junit.framework.Test;
-import junit.framework.TestCase;
+import java.util.Iterator;
+
import junit.framework.TestSuite;
-import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* A test for the XML handling functionality.
@@ -35,7 +35,7 @@
}
- public static Test suite() {
+ public static TestSuite suite() {
return new TestSuite( XMLPageTest.class );
}
@@ -53,6 +53,32 @@
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.xml" );
WebResponse simplePage = wc.getResponse( request );
- Document doc = simplePage.getDOM();
+ simplePage.getDOM();
+ }
+
+
+ public void testTraversal() throws Exception {
+ defineResource( "SimplePage.xml",
+ "<?xml version='1.0' ?><zero><main><first><second/></first><main><normal/><simple/></main><after/></main><end/></zero>",
+ "text/xml" );
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/SimplePage.xml" );
+ WebResponse simplePage = wc.getResponse( request );
+ NodeUtils.PreOrderTraversal pot = new NodeUtils.PreOrderTraversal( simplePage.getDOM() );
+ final StringBuffer sb = new StringBuffer();
+ pot.perform( new NodeUtils.NodeAction() {
+ public boolean processElement( NodeUtils.PreOrderTraversal traversal, Element element ) {
+ if (element.getNodeName().equals( "main" )) {
+ traversal.pushContext( "x" );
+ } else {
+ for (Iterator i = traversal.getContexts(); i.hasNext();) sb.append( i.next() );
+ sb.append( element.getNodeName() ).append( "|" );
+ }
+ return true;
+ }
+ public void processTextNodeValue( String value ) {
+ }
+ } );
+ assertEquals( "Traversal result", "zero|xfirst|xsecond|xxnormal|xxsimple|xafter|end|", sb.toString() );
}
}
|