[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit HtmlTablesTest.java,1.11,1.12 HttpUnitTe
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2001-10-25 17:30:06
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv31578/test/com/meterware/httpunit
Modified Files:
HtmlTablesTest.java HttpUnitTest.java
Log Message:
from Benoit Xhenseval: added getTableCellWithID
Index: HtmlTablesTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HtmlTablesTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- HtmlTablesTest.java 2000/12/13 21:55:16 1.11
+++ HtmlTablesTest.java 2001/10/25 17:30:03 1.12
@@ -2,14 +2,14 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, Russell Gold
+* Copyright (c) 2000-2001, 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
+* 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
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
+* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
@@ -27,15 +27,18 @@
/**
- * A unit test of the httpunit parsing classes.
+ * A unit test of the table handling code.
+ *
+ * @author <a href="mailto:rus...@ac...">Russell Gold</a>
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
**/
public class HtmlTablesTest extends HttpUnitTest {
public static void main(String args[]) {
junit.textui.TestRunner.run( suite() );
}
-
-
+
+
public static Test suite() {
return new TestSuite( HtmlTablesTest.class );
}
@@ -53,9 +56,9 @@
defineWebPage( "OneTable", "<h2>Interesting data</h2>" +
"<table summary=\"tough luck\">" +
"<tr><td>One</td><td> </td><td>1</td></tr>" +
- "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" +
+ "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" +
"<tr><td>Two</td><td> </td><td>2</td></tr>" +
- "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" +
+ "<tr><td colspan=3><IMG SRC=\"/images/spacer.gif\" ALT=\"\" WIDTH=1 HEIGHT=1></td></tr>" +
"<tr><td>Three</td><td> </td><td>3</td></tr>" +
"</table>" );
defineWebPage( "SpanTable", "<h2>Interesting data</h2>" +
@@ -65,8 +68,8 @@
"<tr><td>Green</td><td><a href=\"nowhere\">vert</a></td></tr>" +
"</table>" );
}
-
-
+
+
public void testFindNoTables() throws Exception {
defineWebPage( "Default", "This has no tables but it does" +
"have <a href=\"/other.html\">an active link</A>" +
@@ -143,8 +146,8 @@
assertEquals( "nested columns", 2, nested[0].getColumnCount() );
String nestedString = tables[0].getCellAsText( 0, 0 );
- assert( "Cannot find 'Red' in string", nestedString.indexOf( "Red" ) >= 0 );
- assert( "Cannot find 'Blue' in string", nestedString.indexOf( "Blue" ) >= 0 );
+ assertTrue( "Cannot find 'Red' in string", nestedString.indexOf( "Red" ) >= 0 );
+ assertTrue( "Cannot find 'Blue' in string", nestedString.indexOf( "Blue" ) >= 0 );
}
@@ -256,6 +259,44 @@
assertEquals( "Non-blank rows", 3, cells.length );
assertEquals( "Non-blank columns", 2, cells[0].length );
assertEquals( "cell at 1,1", "Value", cells[1][1] );
+ }
+
+ /**
+ * Get a specific cell with a given id in a WebTable
+ * @author <a href="mailto:bx...@bi...">Benoit Xhenseval</a>
+ **/
+ public void testCellsWithID() throws Exception {
+ defineWebPage( "Default", "<h2>Interesting data</h2>" +
+ "<table id=\"table\" summary=little>" +
+ "<tr><td>Title</td><td>Data</td></tr>" +
+ "<tr><td id=\"id1\">value1</td><td id=\"id2\">value2</td><td>Value</td></tr>" +
+ "<tr><td> </td><td> </td><td>Value</td></tr>" +
+ "</table>" );
+
+ WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );
+ WebTable table = page.getTableWithID("table");
+ assertNotNull("there is a table",table);
+ TableCell cell = table.getTableCellWithID("id1");
+ assertNotNull("cell id1",cell);
+ assertEquals("Value of cell id1","value1",cell.asText());
+ cell = table.getTableCellWithID("id2");
+ assertNotNull("cell id2",cell);
+ assertEquals("Value of cell id2","value2",cell.asText());
+
+ // test non existent cell id
+ cell = table.getTableCellWithID("nonExistingID");
+ assertNull("cell id2",cell);
+
+ // check the ignore case.TRUE
+ HttpUnitOptions.setMatchesIgnoreCase(true);
+ cell = table.getTableCellWithID("iD2");
+ assertNotNull("cell id2",cell);
+ assertEquals("Value of cell id2","value2",cell.asText());
+
+ // check the ignore case FALSE
+ HttpUnitOptions.setMatchesIgnoreCase(false);
+ cell = table.getTableCellWithID("iD2");
+ assertNull("cell iD2",cell);
}
private WebConversation _wc;
Index: HttpUnitTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/HttpUnitTest.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- HttpUnitTest.java 2001/08/06 20:19:41 1.15
+++ HttpUnitTest.java 2001/10/25 17:30:03 1.16
@@ -31,7 +31,9 @@
/**
- * A unit test of the httpunit parsing classes.
+ * a base class for HttpUnit regression tests.
+ *
+ * @author <a href="mailto:rus...@ac...">Russell Gold</a>
**/
abstract
class HttpUnitTest extends TestCase {
@@ -90,6 +92,10 @@
protected String getHostPath() {
return _hostPath;
+ }
+
+ public void assertTrue( String comment, boolean expression ) {
+ assert( comment, expression );
}
|