KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.displaytag.jsptests;
2
3 import org.displaytag.test.DisplaytagCase;
4 import org.xml.sax.SAXException JavaDoc;
5
6 import com.meterware.httpunit.GetMethodWebRequest;
7 import com.meterware.httpunit.TableCell;
8 import com.meterware.httpunit.WebLink;
9 import com.meterware.httpunit.WebRequest;
10 import com.meterware.httpunit.WebResponse;
11 import com.meterware.httpunit.WebTable;
12
13
14 /**
15  * Tests for basic displaytag functionalities.
16  * @author Fabrizio Giustina
17  * @version $Revision: 894 $ ($Author: fgiust $)
18  */

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

25     public String JavaDoc getJspName()
26     {
27         return "DISPL-017.jsp";
28     }
29
30     /**
31      * Verifies that the generated page contains a table with the expected number of columns.
32      * @param jspName jsp name, with full path
33      * @throws Exception any axception thrown during test.
34      */

35     public void doTest(String JavaDoc jspName) throws Exception JavaDoc
36     {
37
38         WebRequest request = new GetMethodWebRequest(jspName);
39
40         WebResponse response = runner.getResponse(request);
41
42         for (int j = 0; j < 4; j++)
43         {
44             WebLink[] links = response.getLinks();
45             response = links[j].click();
46
47             if (log.isDebugEnabled())
48             {
49                 log.debug("After clicking on " + j + ":\n" + response.getText());
50             }
51             checkOnlyOneSorted(response, j);
52         }
53
54     }
55
56     /**
57      * Check that only the expected column is sorted.
58      * @param response WebResponse
59      * @param sortedColumn expected sorted column number
60      * @throws SAXException in processing WebTables
61      */

62     private void checkOnlyOneSorted(WebResponse response, int sortedColumn) throws SAXException JavaDoc
63     {
64         WebTable[] tables = response.getTables();
65
66         assertEquals("Wrong number of tables.", 1, tables.length);
67         assertEquals("Wrong number of columns in result.", 4, tables[0].getColumnCount());
68
69         for (int j = 0; j < 4; j++)
70         {
71             TableCell cell = tables[0].getTableCell(0, j);
72             boolean containsSorted = (cell.getAttribute("class").indexOf("sorted") > -1);
73             if (j == sortedColumn)
74             {
75                 assertTrue("Column " + j + " is not sorted as expected", containsSorted);
76             }
77             else
78             {
79                 assertFalse("Column " + j + " is sorted, but only " + sortedColumn + " should be", containsSorted);
80             }
81
82         }
83
84     }
85
86 }
Popular Tags