KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.displaytag.jsptests;
2
3 import org.apache.commons.lang.StringUtils;
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.HTMLElement;
10 import com.meterware.httpunit.TableCell;
11 import com.meterware.httpunit.WebLink;
12 import com.meterware.httpunit.WebRequest;
13 import com.meterware.httpunit.WebResponse;
14 import com.meterware.httpunit.WebTable;
15
16
17 /**
18  * Test for DISPL-129 - Partial list support with valuelist pattern.
19  * @author Fabrizio Giustina
20  * @version $Id$
21  */

22 public class Displ129Test extends DisplaytagCase
23 {
24
25     /**
26      * @see org.displaytag.test.DisplaytagCase#getJspName()
27      */

28     public String JavaDoc getJspName()
29     {
30         return "DISPL-129.jsp";
31     }
32
33     /**
34      * No exception when an invalid page is requested.
35      * @param jspName jsp name, with full path
36      * @throws Exception any axception thrown during test.
37      */

38     public void doTest(String JavaDoc jspName) throws Exception JavaDoc
39     {
40         WebRequest request = new GetMethodWebRequest(jspName);
41
42         ParamEncoder encoder = new ParamEncoder("table");
43         String JavaDoc pageParameter = encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE);
44         request.setParameter(pageParameter, "2");
45
46         WebResponse response = runner.getResponse(request);
47
48         if (log.isDebugEnabled())
49         {
50             log.debug(response.getText());
51         }
52
53         WebTable[] tables = response.getTables();
54         assertEquals("Wrong number of tables in result.", 1, tables.length);
55         assertEquals("Wrong number of rows in result.", 3, tables[0].getRowCount());
56
57         if (log.isDebugEnabled())
58         {
59             log.debug(response.getText());
60         }
61
62         assertEquals("Wrong column header.", "Number", tables[0].getCellAsText(0, 0));
63         assertEquals("Wrong column content.", "3", tables[0].getCellAsText(1, 0));
64         assertEquals("Wrong column content.", "4", tables[0].getCellAsText(2, 0));
65
66         TableCell headerCell = tables[0].getTableCell(0, 0);
67
68         String JavaDoc cssClass = headerCell.getClassName();
69         assertEqualsIgnoreOrder("Wrong css attributes.", new String JavaDoc[]{"sortable", "sorted", "order2"}, StringUtils
70             .split(cssClass));
71
72         WebLink[] headerLinks = headerCell.getLinks();
73         assertEquals("Sorting link not found.", 1, headerLinks.length);
74         WebLink sortingLink = headerLinks[0];
75         assertEqualsIgnoreOrder(
76             "Wrong parameters.",
77             new String JavaDoc[]{"sort", "searchid", "dir", pageParameter},
78             sortingLink.getParameterNames());
79
80         HTMLElement pagebanner = response.getElementWithID("pagebanner");
81         assertEquals("Wrong page banner", "10|3|4", pagebanner.getText());
82         HTMLElement pagelinks = response.getElementWithID("pagelinks");
83         assertEquals("Wrong page links", "1|[2]|3|4|5", pagelinks.getText());
84
85     }
86
87 }
Popular Tags