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: A question
Date Fri, 31 Jan 2003 20:20:59 GMT
Hi Tony,

You should have a look at the following FAQ entry:
http://jakarta.apache.org/cactus/faq.html#faq4

Cactus is about unit testing and there is no order of execution of the
JUnit testXXX() methods (same principle as JUnit). You shouldn't rely on
a first call setting up some state. Consequently, Cactus starts a new
Session for each test.

If you need to set up some object in the session, you can do it either
in the setUp() method or at the beginning of your testXXX() method.

Note that in Cactus 1.5, I have added a new API called
WebRequest.getSessionCookie() which allows you to get a cookie before
the test begins as shown below. But this is only to support scenarios
where your server side code is testing for "!session.isNew()" which is
otherwise, not testable...

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


If you really need to set the session cookie before your test starts
(note that I have not found a scenario requiring it apart from the
session.isNew one), then you can also save the returned session cookie
from your first test (you'll need to order your tests - see the JUnit
FAQ for this):

[...]

    public void endVerifyJsessionid(WebResponse theResponse)
    {
         sessionCookie = theResponse.getCookieIgnoreCase("jsessionid");
    }

[...]

Hope it helps,
-Vincent


> -----Original Message-----
> From: Bin Yan (Tony) [mailto:binyanmail@yahoo.com]
> Sent: 31 January 2003 15:29
> To: 'Cactus Users List'
> Subject: RE: A question
> 
> Hi, Vincent:
> 
> Thank you for the reply. I looked up these samples,
> and they both sound resonable for cookies. However, I
> guess I didn't make my question very clear. The
> problem I am having is that I need to store an object
> full of configurations in the session object. And as
> far as I know, the session related to one Client is by
> Cookie/or URL rewriting to be retrievable by server. I
> don't think URL rewriting is something applicable
> here. So the JSESSIONID in cookie should be active for
> a persistent session object for the next request to
> use.
> 
> I tried useing IE or NS to access my 7007 (my cactus
> setting) port with the right URL, I can tell there are
> JSESSIONID and session is persistent. So I guess the
> Server side is okay. But each time the client from
> cactus requests, there are no cookies. I can, of
> course, add cookies as in the samples you gave me. But
> I wonder how I can do it to enable the JSESSIONID
> cookie. After all, it seems each request is
> 'different' from the server's point of view. Correct
> me if I am wrong, I think cactus cookie testing seems
> to limit to per test.
> 
> Thanks again for your prompt reply. I am doing the
> configurations in other ways now (w/o putting in
> session) and I can access DB and do other cactus
> testing successfully. I think cactus is generally a
> great tool.
> 
> Regards,
> 
> TY
> 
> --- Vincent Massol <vmassol@octo.com> wrote:
> > Hi Tony,
> >
> > You should look in the sample application packaged
> > in the cactus
> > distribution. There are tests that demonstrates
> > setting and retrieving
> > cookies. You can view them with viewcvs at:
> >
> >
>
http://cvs.apache.org/viewcvs/jakarta-cactus/sample-servlet/src/test-cac
> > tus/share/org/apache/cactus/unit/TestCookie.java
> >
> > and
> >
> >
>
http://cvs.apache.org/viewcvs/jakarta-cactus/sample-servlet/src/test-cac
> >
> tus/share/org/apache/cactus/sample/TestSampleServlet.java
> >
> > Hope it helps,
> > -Vincent
> >
> > > -----Original Message-----
> > > From: Bin Yan (Tony) [mailto:binyanmail@yahoo.com]
> > > Sent: 30 January 2003 01:06
> > > To: cactus-user@jakarta.apache.org
> > > Subject: A question
> > >
> > > Hi, All:
> > >
> > > I have setup using cactus and I have one problem.
> > In
> > > one of the setUp() method I am trying to get the
> > > cookies from request object. But I got none. I
> > wonder
> > > where I should do some configuration before I can
> > get
> > > the cookies. Please note I got zero cookies from
> > both
> > > HTTP requests (as designed by cactus).
> > >
> > > TIA
> > >
> > > =====
> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >  Tony Yan  binyanmail@yahoo.com
> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >
> > > __________________________________________________
> > > Do you Yahoo!?
> > > Yahoo! Mail Plus - Powerful. Affordable. Sign up
> > now.
> > > http://mailplus.yahoo.com
> > >
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > cactus-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > cactus-user-help@jakarta.apache.org
> >
> >
> 
> 
> =====
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  Tony Yan  binyanmail@yahoo.com
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com
> 
> ---------------------------------------------------------------------
> 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