KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.displaytag.jsptests;
2
3 import org.displaytag.properties.SortOrderEnum;
4 import org.displaytag.tags.TableTagParameters;
5 import org.displaytag.test.DisplaytagCase;
6 import org.displaytag.util.ParamEncoder;
7
8 import com.meterware.httpunit.GetMethodWebRequest;
9 import com.meterware.httpunit.WebLink;
10 import com.meterware.httpunit.WebRequest;
11 import com.meterware.httpunit.WebResponse;
12 import com.meterware.httpunit.WebTable;
13
14
15 /**
16  * Test for DISPL-243 - Default column sort breaks sorting after a few sorts of the column
17  * @author Fabrizio Giustina
18  * @version $Revision$ ($Author$)
19  */

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

26     public String JavaDoc getJspName()
27     {
28         return "DISPL-243.jsp";
29     }
30
31     /**
32      * CHeck sort order after some clicks
33      * @param jspName jsp name, with full path
34      * @throws Exception any axception thrown during test.
35      */

36     public void doTest(String JavaDoc jspName) throws Exception JavaDoc
37     {
38         WebRequest request = new GetMethodWebRequest(jspName);
39         ParamEncoder encoder = new ParamEncoder("table");
40         String JavaDoc orderParameter = encoder.encodeParameterName(TableTagParameters.PARAMETER_ORDER);
41
42         WebResponse response = runner.getResponse(request);
43
44         if (log.isDebugEnabled())
45         {
46             log.debug(response.getText());
47         }
48
49         WebTable[] tables = response.getTables();
50         assertEquals("Wrong number of tables.", 1, tables.length);
51
52         WebLink[] links = response.getLinks();
53         assertEquals("Wrong number of links.", 1, links.length);
54
55         assertEquals("wrong sorting order", Integer.toString(SortOrderEnum.DESCENDING.getCode()), links[0]
56             .getParameterValues(orderParameter)[0]);
57
58         // a few clicks...
59
for (int j = 0; j < 10; j++)
60         {
61             String JavaDoc expectedSortOrder = (j % 2 == 0) ? SortOrderEnum.ASCENDING.getName() : SortOrderEnum.DESCENDING
62                 .getName();
63
64             response = links[0].click();
65
66             if (log.isDebugEnabled())
67             {
68                 log.debug(response.getText());
69             }
70
71             tables = response.getTables();
72             assertEquals("Wrong number of tables.", 1, tables.length);
73
74             links = response.getLinks();
75             assertEquals("Wrong number of links.", 1, links.length);
76
77             assertEquals("Wrong sorting order for iteration " + j, expectedSortOrder, SortOrderEnum.fromCode(
78                 Integer.parseInt(links[0].getParameterValues(orderParameter)[0])).getName());
79         }
80
81     }
82
83 }
Popular Tags