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 18 public class NestedTest extends DisplaytagCase 19 { 20 21 24 public String getJspName() 25 { 26 return "nested.jsp"; 27 } 28 29 34 public void doTest(String jspName) throws Exception 35 { 36 WebRequest request = new GetMethodWebRequest(jspName); 37 38 WebResponse response = runner.getResponse(request); 39 40 WebTable[] tables = response.getTables(); 41 42 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 htmlElement, Object 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 |