public void doTest(String jspName) throws Exception {
WebRequest request = new GetMethodWebRequest(jspName);
WebResponse response;
response = runner.getResponse(request);
if (log.isDebugEnabled())
{
log.debug(response.getText());
}
WebTable[] tables = response.getTables();
assertEquals("Wrong number of tables in result.", 3, tables.length);
for (int j = 0; j < tables.length; j++)
{
assertEquals("invalid id", "row" + j, tables[j].getID());
}
WebLink[] links = response.getLinks();
assertEquals("Wrong number of links in result.", 3, links.length);
// click to sort the first table
response = links[0].click();
// get the links
links = response.getLinks();
assertEquals("Wrong number of links in result.", 3, links.length);
// and click again to sort in reversed order
response = links[0].click();
if (log.isDebugEnabled())
{
log.debug(response.getText());
}
tables = response.getTables();
assertEquals("Wrong number of tables in result.", 3, tables.length);
// first is sorted, other aren't
assertTrue("First table should be sorted. Wrong class attribute.", //
StringUtils.contains(tables[0].getTableCell(0, 0).getClassName(), "sorted"));
assertEquals("Second table should not be sorted. Wrong class attribute.", //
"sortable",
tables[1].getTableCell(0, 0).getClassName());
assertEquals("Third table should not be sorted. Wrong class attribute.", //
"sortable",
tables[2].getTableCell(0, 0).getClassName());
// and just to be sure also check values: sorted table
for (int j = 1; j < tables[0].getRowCount(); j++)
{
assertEquals("Unexpected value in table cell", Integer.toString(4 - j), tables[0].getCellAsText(j, 0));
}
// unsorted tables:
for (int j = 1; j < tables[1].getRowCount(); j++)
{
assertEquals("Unexpected value in table cell", Integer.toString(j), tables[1].getCellAsText(j, 0));
assertEquals("Unexpected value in table cell", Integer.toString(j), tables[2].getCellAsText(j, 0));
}
}
Try to sort generated tables. |