KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.displaytag.jsptests;
2
3 import org.displaytag.properties.MediaTypeEnum;
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.WebRequest;
10 import com.meterware.httpunit.WebResponse;
11 import com.meterware.httpunit.WebTable;
12
13
14 /**
15  * Tests for optimized iterations (don't evaluate unneeded body of columns).
16  * @author Fabrizio Giustina
17  * @version $Revision: 707 $ ($Author: fgiust $)
18  */

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

25     public String JavaDoc getJspName()
26     {
27         return "optimizediteration2.jsp";
28     }
29
30     /**
31      * Verifies that the generated page contains the pagination links with the inupt parameter. Tests #917200 ("{}" in
32      * parameters).
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
39         WebRequest request = new GetMethodWebRequest(jspName);
40         ParamEncoder encoder = new ParamEncoder("table");
41
42         // page 1, not sorted
43
request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "1");
44         checkNumberOfIterations(runner.getResponse(request), 1);
45
46         // page 2, not sorted
47
request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "2");
48         checkNumberOfIterations(runner.getResponse(request), 1);
49
50         // page 1, sorted (only current page)
51
request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_SORT), "1");
52         request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "1");
53         checkNumberOfIterations(runner.getResponse(request), 1);
54
55         // page 2, sorted (only current page)
56
request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_SORT), "1");
57         request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "2");
58         checkNumberOfIterations(runner.getResponse(request), 1);
59
60         // page 1, export single page
61
request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "2");
62         request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_EXPORTTYPE), Integer
63             .toString(MediaTypeEnum.CSV.getCode()));
64         request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "1");
65
66         WebResponse response = runner.getResponse(request);
67         String JavaDoc csvExport = response.getText();
68         if (log.isDebugEnabled())
69         {
70             log.debug(response.getText());
71         }
72
73         assertEquals("Wrong csv export", "ant,1\n", csvExport);
74
75     }
76
77     /**
78      * @param response WebResponse
79      * @param iterations expected number of iterations
80      * @throws Exception any axception thrown during test.
81      */

82     private void checkNumberOfIterations(WebResponse response, int iterations) throws Exception JavaDoc
83     {
84         if (log.isDebugEnabled())
85         {
86             log.debug(response.getText());
87         }
88
89         WebTable[] tables = response.getTables();
90         assertEquals("Expected 1 table in result.", 1, tables.length);
91         assertEquals("Expected 2 rows in table.", 2, tables[0].getRowCount());
92
93         assertEquals("Wrong number of iterations. Evaluated column bodies number is different from expected", Integer
94             .toString(iterations), response.getElementWithID("iterations").getText());
95     }
96 }
Popular Tags