You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by rr...@aep.com on 2003/06/10 22:31:06 UTC

I have a jsp that does a redirect, can I test the resulted redirected page?

I love your production but I have a question.

I have a JSP that does a redirect to another JSP.  I want to beable to 
test that I did in fact get a re-direct.  I noticed in the Cactus logs 
there was in fact a redirect, but I can't find any method in the 
response/request/session objects that would return if this happend.

The HTML that I get back is the HTML for the JSP I am testing. 

Here is a code snipet of the JSP I am testing:


<% userID = (String) request.getParameter ("user"); 
    if (userID != null) {
        userID = userID.toUpperCase ();
    }

    loginUser = ldapServices.findPerson (new String ("cn=" + userID));
    if (loginUser == null){
        loginUser = new Member ();
        loginUser.setDisplayName ("Undefined");
    }
    session.setAttribute (OMACProperties.SESSION_LOGIN_USER, loginUser);
    omacRequestID = (String) request.getParameter ("OMACRequestID");
%>

....


  <body>
<%  if (omacRequestID == null) {
        if (userID.length () == 0)
            response.sendRedirect("TerminalErrorPage.jsp?msg=Anonymous 
access to the OMAC is not allowed.  Please close the browser and log into 
the network with a valid user ID");
        else
            response.sendRedirect("Menu.jsp");
    } else {
        if (userID.length () == 0)
            response.sendRedirect("TerminalErrorPage.jsp?msg=Anonymous 
access to the OMAC is not allowed.  Please close the browser and log into 
the network with a valid user ID");
        else
            response.sendRedirect("Update.jsp?OMACRequestID=" + 
omacRequestID);
    }%>

Re: I have a jsp that does a redirect, can I test the resulted redirected page?

Posted by Christopher Lenz <cm...@gmx.de>.
Hi,

you should be able to assert the redirection in the endXXX() method:

   public void endXXX(WebResponse response) {
     assertEquals(302, response.getConnection().getResponseCode());
     assertEquals([YourRedirectURL],
         response.getConnection().getHeaderField("Location"));
   }

Or something similar... not sure if the URL in the Location header is 
absolute or relative.

-chris

rrbrandt@aep.com wrote:
> 
> I love your production but I have a question.
> 
> I have a JSP that does a redirect to another JSP.  I want to beable to 
> test that I did in fact get a re-direct.  I noticed in the Cactus logs 
> there was in fact a redirect, but I can't find any method in the 
> response/request/session objects that would return if this happend.
> 
> The HTML that I get back is the HTML for the JSP I am testing.  
> 
> Here is a code snipet of the JSP I am testing:
> 
> 
> <% userID = (String) request.getParameter ("user");
>     if (userID != null) {
>         userID = userID.toUpperCase ();
>     }
> 
>     loginUser = ldapServices.findPerson (new String ("cn=" + userID));
>     if (loginUser == null){
>         loginUser = new Member ();
>         loginUser.setDisplayName ("Undefined");
>     }
>     session.setAttribute (OMACProperties.SESSION_LOGIN_USER, loginUser);
>     omacRequestID = (String) request.getParameter ("OMACRequestID");
> %>
> 
> ....
> 
> 
>   <body>
> <%  if (omacRequestID == null) {
>         if (userID.length () == 0)
>             response.sendRedirect("TerminalErrorPage.jsp?msg=Anonymous 
> access to the OMAC is not allowed.  Please close the browser and log 
> into the network with a valid user ID");
>         else
>             response.sendRedirect("Menu.jsp");
>     } else {
>         if (userID.length () == 0)
>             response.sendRedirect("TerminalErrorPage.jsp?msg=Anonymous 
> access to the OMAC is not allowed.  Please close the browser and log 
> into the network with a valid user ID");
>         else
>             response.sendRedirect("Update.jsp?OMACRequestID=" + 
> omacRequestID);
>     }%>