jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Massol" <vmas...@octo.com>
Subject RE: Error accessing same http session across test methods
Date Sun, 24 Nov 2002 13:42:30 GMT
Hi Avinash,

Nick is right: Cactus creates a new HTTP Session for each testXXX().
Unless you specify not to create one
(WebRequest.setAutomaticSession(false)).

That said, there are cases when you need to be able to unit test methods
that expect an HTTP Session to exist. A method that tests for
Session.isNew() is such a case...

In order to be able to test this, Cactus 1.5 (it is not present in
Cactus 1.4) has introduced a new method:

WebRequest.getSessionCookie()

See
http://cvs.apache.org/viewcvs/jakarta-cactus/documentation/docs/xdocs/ch
anges.xml?rev=1.57&content-type=text/vnd.viewcvs-markup (search for
"HTTP Session")

Here is the test that is included in the Cactus test suite:

public void beginCreateSessionCookie(WebRequest theRequest)
{
    HttpSessionCookie sessionCookie = theRequest.getSessionCookie();
    theRequest.addCookie(sessionCookie);
}

public void testCreateSessionCookie()
{
    assertTrue("A session should have been created prior to "
        + "this request", !session.isNew());
}

You need to get a nightly build
(http://cvs.apache.org/builds/jakarta-cactus/nightly/2002-11-16/).

Cheers,
-Vincent

> -----Original Message-----
> From: Avinash Chugh [mailto:avi_chugh@hotmail.com]
> Sent: 21 November 2002 12:57
> To: cactus-user@jakarta.apache.org
> Subject: Error accessing same http session across test methods
> 
> Environment: Weblogic 7, Win2k, Cactus 1.4.1
> 
> I have a ServletTestCase with two test methods - testLogin(),
> testLogout().
> 
> testlogin calls a doPost() on a servlet which logs in user using HTTP
> request parameters, and places an object in session. When I test
> assertNotNull for that session attribute, the test succeeds.
> 
> testlogout() calls another doPost() which logs out the earlier user
and
> invalidate the session. But when I do assertNotNull() for the same
> session attribute (before the actual call to servlet), the test
fails..
> 
> I am using the same servlet...and session.isNew() always returns true
> 
> This leads me to believe..
> The HTTPSession created by testLogin() can nolonger be accessed by
> subsequent test method(s) ??
> 
> This is a bug..right ??
> 
> Regards,
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>


Mime
View raw message