jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Franz Roth" <franzr...@gmx.de>
Subject Re: Servlet redirection testing
Date Sat, 02 Sep 2006 11:56:52 GMT
hi,
that's true; you can get the redirection-string by  
webresponse.getHeaderField("LOCATION");

by the way: method-names should never begin upperCased ("RedirectPage")
in your example it would be a good solution to overwrite the service-Method

bye

On Sat, 02 Sep 2006 13:43:50 +0200, Miroslav Ć ulc  
<miroslav.sulc@startnet.cz> wrote:

> Hi Prithvi,
>
> I'm still in the "before newbie" stage but I guess it won't work the way
> you expect. I think it works this way:
>
> You say: "Hey, give me  http://localhost/"
> And you get: "Hey, you should send request for
> http://localhost/default.html (or http://localhost/tp/default.html) to
> the server"
>
> And then in the next request you can get the content of the page you are
> redirected to. So what you get is the information that you should send
> request for another page, not the new page itself. You'll get the new
> page on the next request (if you make the next request).
>
> I hope this helps.
>
> --
> Miroslav
>
> Prithvi Bhat wrote:
>> 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: cactus-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>>
>>
>

Mime
View raw message