Home » displaytag-1.1.1-src » org » displaytag » jsptests » [javadoc | source]

    1   package org.displaytag.jsptests;
    2   
    3   import org.displaytag.tags.TableTagParameters;
    4   import org.displaytag.test.DisplaytagCase;
    5   import org.displaytag.util.ParamEncoder;
    6   
    7   import com.meterware.httpunit.GetMethodWebRequest;
    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    * Basic tests for pagination.
   16    * @author Fabrizio Giustina
   17    * @version $Revision: 853 $ ($Author: fgiust $)
   18    */
   19   public class PartialListTest extends DisplaytagCase
   20   {
   21   
   22       /**
   23        * @see org.displaytag.test.DisplaytagCase#getJspName()
   24        */
   25       public String getJspName()
   26       {
   27           return "partialList.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 jspName) throws Exception
   37       {
   38   
   39           WebRequest request = new GetMethodWebRequest(jspName);
   40   
   41           ParamEncoder p2 = new ParamEncoder("table2");
   42           ParamEncoder p3 = new ParamEncoder("table3");
   43   
   44           request.setParameter(p2.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "2"); // table 2 start page 2
   45           request.setParameter(p3.encodeParameterName(TableTagParameters.PARAMETER_SORT), "0"); // table 3 sort 0
   46           request.setParameter(p3.encodeParameterName(TableTagParameters.PARAMETER_ORDER), "1"); // table 3 order desc
   47   
   48           WebResponse response = runner.getResponse(request);
   49   
   50           if (log.isDebugEnabled())
   51           {
   52               log.debug("RESPONSE: " + response.getText());
   53           }
   54   
   55           WebLink[] links = response.getLinks();
   56           WebTable[] tables = response.getTables();
   57           // ensure all our search bar links contain page 2 as the param since we only have 2 pages
   58           assertEquals("2", links[0].getParameterValues(p2.encodeParameterName(TableTagParameters.PARAMETER_PAGE))[0]);
   59           assertEquals("2", links[1].getParameterValues(p2.encodeParameterName(TableTagParameters.PARAMETER_PAGE))[0]);
   60           assertEquals("2", links[2].getParameterValues(p2.encodeParameterName(TableTagParameters.PARAMETER_PAGE))[0]);
   61           assertEquals(3, tables[0].getRowCount()); // title row + 2 data's
   62           assertEquals("1", tables[0].getCellAsText(1, 0));
   63           assertEquals("4", tables[0].getCellAsText(2, 0));
   64   
   65           // second table assertions
   66           // links should point to first page
   67           assertEquals("1", links[4].getParameterValues(p2.encodeParameterName(TableTagParameters.PARAMETER_PAGE))[0]);
   68           assertEquals("1", links[5].getParameterValues(p2.encodeParameterName(TableTagParameters.PARAMETER_PAGE))[0]);
   69           assertEquals("1", links[6].getParameterValues(p2.encodeParameterName(TableTagParameters.PARAMETER_PAGE))[0]);
   70           assertEquals(3, tables[1].getRowCount()); // title row + 2 data's
   71           assertEquals("1", tables[1].getCellAsText(1, 0));
   72           assertEquals("4", tables[1].getCellAsText(2, 0));
   73   
   74           // third table assertions
   75           assertEquals(3, tables[2].getRowCount()); // title row + 2 data's
   76           assertEquals("4", tables[2].getCellAsText(1, 0));
   77           assertEquals("1", tables[2].getCellAsText(2, 0));
   78       }
   79   }

Home » displaytag-1.1.1-src » org » displaytag » jsptests » [javadoc | source]