Save This Page
Home » displaytag-1.1.1-src » org » displaytag » jsptests » [javadoc | source]
    1   package org.displaytag.jsptests;
    2   
    3   import org.apache.commons.lang.SystemUtils;
    4   import org.displaytag.properties.MediaTypeEnum;
    5   import org.displaytag.test.DisplaytagCase;
    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    * Tests for encoded uri.
   16    * @author Fabrizio Giustina
   17    * @version $Revision: 1006 $ ($Author: fgiust $)
   18    */
   19   public class EncodedUriTest extends DisplaytagCase
   20   {
   21   
   22       /**
   23        * @see org.displaytag.test.DisplaytagCase#getJspName()
   24        */
   25       public String getJspName()
   26       {
   27           return "requesturi.jsp";
   28       }
   29   
   30       /**
   31        * Test link generated using requestUri.
   32        * @param jspName jsp name, with full path
   33        * @throws Exception any axception thrown during test.
   34        */
   35       public void doTest(String jspName) throws Exception
   36       {
   37           WebRequest request = new GetMethodWebRequest(jspName);
   38           request.setParameter("city", "München");
   39   
   40           WebResponse response = runner.getResponse(request);
   41   
   42           if (log.isDebugEnabled())
   43           {
   44               log.debug(response.getText());
   45           }
   46   
   47           WebTable[] tables = response.getTables();
   48           assertEquals("Wrong number of tables.", 1, tables.length);
   49   
   50           WebLink[] links = response.getLinks();
   51           assertEquals("Wrong number of links in result.", MediaTypeEnum.getSize() - 1, links.length);
   52   
   53           if (SystemUtils.isJavaVersionAtLeast(1.4f))
   54           {
   55               assertTrue("Encoded parameter in link is wrong: " + links[0].getURLString(), links[0]
   56                   .getURLString()
   57                   .indexOf("M%C3%BCnchen") > -1);
   58           }
   59           else
   60           {
   61   
   62               log.info("Warning, jse 1.4 not available. Encoding used in link will be wrong");
   63               assertTrue("Encoded parameter in link is wrong: " + links[0].getURLString(), links[0]
   64                   .getURLString()
   65                   .indexOf("M%FCnchen") > -1);
   66           }
   67   
   68       }
   69   }

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