package org.displaytag.jsptests;

import org.apache.commons.lang.StringUtils;
import org.displaytag.tags.TableTagParameters;
import org.displaytag.test.DisplaytagCase;
import org.displaytag.util.ParamEncoder;

import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.HTMLElement;
import com.meterware.httpunit.TableCell;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;


/**
 * Test for DISPL-129 - Partial list support with valuelist pattern.
 * @author Fabrizio Giustina
 * @version $Id$
 */
public class Displ129Test extends DisplaytagCase
{

    /**
     * @see org.displaytag.test.DisplaytagCase#getJspName()
     */
    public String getJspName()
    {
        return "DISPL-129.jsp";
    }

    /**
     * No exception when an invalid page is requested.
     * @param jspName jsp name, with full path
     * @throws Exception any axception thrown during test.
     */
    public void doTest(String jspName) throws Exception
    {
        WebRequest request = new GetMethodWebRequest(jspName);
        WebResponse response = runner.getResponse(request);

        ParamEncoder encoder = new ParamEncoder("table");
        request.setParameter(encoder.encodeParameterName(TableTagParameters.PARAMETER_PAGE), "2");

        if (log.isDebugEnabled())
        {
            log.debug(response.getText());
        }

        WebTable[] tables = response.getTables();
        assertEquals("Wrong number of tables in result.", 1, tables.length);
        assertEquals("Wrong number of rows in result.", 3, tables[0].getRowCount());

        if (log.isDebugEnabled())
        {
            log.debug(response.getText());
        }

        assertEquals("Wrong column header.", "Number", tables[0].getCellAsText(0, 0));
        assertEquals("Wrong column content.", "3", tables[0].getCellAsText(1, 0));
        assertEquals("Wrong column content.", "4", tables[0].getCellAsText(2, 0));

        TableCell headerCell = tables[0].getTableCell(0, 0);

        String cssClass = headerCell.getClassName();
        assertEqualsIgnoreOrder("Wrong css attributes.", new String[]{"sortable", "sorted", "order2"}, StringUtils
            .split(cssClass));

        WebLink[] headerLinks = headerCell.getLinks();
        assertEquals("Sorting link not found.", 1, headerLinks.length);
        WebLink sortingLink = headerLinks[0];
        assertEqualsIgnoreOrder("Wrong parameters.", new String[]{"sort", "searchid", "dir"}, sortingLink
            .getParameterNames());

        HTMLElement pagebanner = response.getElementWithID("pagebanner");
        assertEquals("Wrong page banner", "10|3|4", pagebanner.getText());
        HTMLElement pagelinks = response.getElementWithID("pagelinks");
        assertEquals("Wrong page links", "1|[2]|3|4|5", pagelinks.getText());

    }

}
@@ -1136,68 +1136,8 @@
 me);
-%0A        WebResponse response = runner.getResponse(request);
 %0A%0A  
@@ -1204,19 +1204,19 @@
     
-request.set
+String page
 Para
@@ -1220,17 +1220,19 @@
 arameter
-(
+ = 
 encoder.
@@ -1289,13 +1289,118 @@
 AGE)
-, %222%22
+;%0A        request.setParameter(pageParameter, %222%22);%0A%0A        WebResponse response = runner.getResponse(request
 );%0A%0A
@@ -2525,24 +2525,37 @@
 IgnoreOrder(
+%0A            
 %22Wrong param
@@ -2558,24 +2558,36 @@
 arameters.%22,
+%0A           
  new String%5B
@@ -2617,22 +2617,25 @@
 dir%22
-%7D
 , 
-sortingLink
+pageParameter%7D,
 %0A   
@@ -2643,16 +2643,27 @@
         
+sortingLink
 .getPara

fix bad test