Hi All,
   I am going mad with testing servlet redirections
using cactus.There are tons of articles on cactus on
the internet.None of them did help.I bought Vincent
Massol's book "Junit in Action" that too did not help.
Any one's help in this regard would be deeply
appreciated.

My sample servlet to be tested is as below
 ==============================================

   import java.io.IOException;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpServletRequest;


   public class SampleServlet extends HttpServlet
   {

       public void RedirectPage(HttpServletRequest
request,HttpServletResponse response)
          throws IOException
       {
        String strRedirectorFlag =
request.getParameter("strRedirectorFlag");

System.out.println("strRedirectorFlag"+strRedirectorFlag);

                if (strRedirectorFlag.equals("1") )
                {

                
response.sendRedirect("http://localhost/default.html";);
                }
                else
                {

                
response.sendRedirect("http://localhost/tp/default.html";);
                }

      }
  }//class SampleServlet
===================================================
My test servlet is as below
===================================================
   import java.io.IOException;
   import junit.framework.Test;
   import junit.framework.TestSuite;

   import org.apache.cactus.ServletTestCase;
   import org.apache.cactus.WebRequest;
   import org.apache.cactus.WebResponse;

   public class TestSampleServlet extends
   ServletTestCase
   {

       public void beginRedirection(WebRequest
webRequest)
       {
        webRequest.addParameter("strRedirectorFlag","1");
       }

       public void testRedirection()
       throws IOException
       {
           SampleServlet servlet = new
SampleServlet();

           servlet.RedirectPage(request,response);
       }

          public void endRedirection(WebResponse
webResponse)
          {
        
System.out.println("Response"+webResponse.getText());
        
assertTrue("udupi",webResponse.getText().indexOf("<TITLE>prithvibhat.com
                 - Comprehensive information on Udupi</TITLE>") >
0);
          }

   }

 ===================================================

 If you see the code carefully in my Test case I want
 to check whether the redirection in my servlet was to

 http://localhost/default.html or
 http://localhost/tp/default.html

 So I use the response.getText() method to compare it
 with the page contents.Unfortunately getText() method
 always returns me NULL!

 Please help...

 Best Regards,
  Prithvi

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to