KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > jsptests > NestedTest


1 package org.displaytag.jsptests;
2
3 import org.displaytag.test.DisplaytagCase;
4 import org.displaytag.test.KnownValue;
5
6 import com.meterware.httpunit.GetMethodWebRequest;
7 import com.meterware.httpunit.HTMLElementPredicate;
8 import com.meterware.httpunit.WebRequest;
9 import com.meterware.httpunit.WebResponse;
10 import com.meterware.httpunit.WebTable;
11
12
13 /**
14  * Simple nested tables.
15  * @author Fabrizio Giustina
16  * @version $Revision: 707 $ ($Author: fgiust $)
17  */

18 public class NestedTest extends DisplaytagCase
19 {
20
21     /**
22      * @see org.displaytag.test.DisplaytagCase#getJspName()
23      */

24     public String JavaDoc getJspName()
25     {
26         return "nested.jsp";
27     }
28
29     /**
30      * Test for content disposition and filename.
31      * @param jspName jsp name, with full path
32      * @throws Exception any axception thrown during test.
33      */

34     public void doTest(String JavaDoc jspName) throws Exception JavaDoc
35     {
36         WebRequest request = new GetMethodWebRequest(jspName);
37
38         WebResponse response = runner.getResponse(request);
39
40         WebTable[] tables = response.getTables();
41
42         // nested tables don't show up in the count
43
assertEquals("Wrong number of first-level tables", 1, tables.length);
44         assertEquals("Wrong number of columns in main table", 4, tables[0].getColumnCount());
45         assertEquals("Wrong number of rows in main table", 4, tables[0].getRowCount());
46
47         for (int j = 1; j < tables[0].getRowCount(); j++)
48         {
49             assertEquals("Content in cell [" + j + ",0] in main table is wrong", Integer.toString(j), tables[0]
50                 .getCellAsText(j, 0));
51             assertEquals("Content in cell [" + j + ",1] in main table is wrong", KnownValue.ANT, tables[0]
52                 .getCellAsText(j, 1));
53             assertEquals("Content in cell [" + j + ",2] in main table is wrong", KnownValue.BEE, tables[0]
54                 .getCellAsText(j, 2));
55
56             WebTable nested = tables[0].getTableCell(j, 3).getFirstMatchingTable(new HTMLElementPredicate()
57             {
58
59                 public boolean matchesCriteria(Object JavaDoc htmlElement, Object JavaDoc criteria)
60                 {
61                     return true;
62                 }
63             }, null);
64
65             assertNotNull("Nested table not found in cell [" + j + ",3]", nested);
66             assertEquals("Wrong number of columns in nested table", 3, nested.getColumnCount());
67             assertEquals("Wrong number of rows in nested table", 4, nested.getRowCount());
68
69             for (int x = 1; x < nested.getRowCount(); x++)
70             {
71                 assertEquals("Content in cell [" + x + ",0] in nested table is wrong", Integer.toString(x), nested
72                     .getCellAsText(x, 0));
73                 assertEquals("Content in cell [" + x + ",1] in nested table is wrong", KnownValue.ANT, nested
74                     .getCellAsText(x, 1));
75                 assertEquals("Content in cell [" + x + ",2] in nested table is wrong", KnownValue.CAMEL, nested
76                     .getCellAsText(x, 2));
77             }
78
79         }
80
81     }
82
83 }
Popular Tags