Please include me in any response anyone has time for as I am not on the
cactus developer list, only user. Thank you.
Kyle Willkomm
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Vincent Massol" <[EMAIL PROTECTED]>
Sent: Thursday, September 20, 2001 5:10 PM
Subject: Re: How does cactus simulate a session?
>
> Actually I think my question should probably go to the cactus developer
> group.
yes. I am ccing the list.
> I was wondering how Cactus is able to simulate a client of the
> webapp. Specifically, how the Cactus code is able to send an http
request
> to the webapp and maintain a session id over several requests of a test
> suite.
It does not. You need to set up the correct environment (including cookies)
for each test (however, you can factor the settings of cookies in a
dedicated method if you wish).
> A test of my application is meaningless unless several requests to
> the servlets come in succession with the same session id.
That's something I had thought of in the early stages of Cactus. And
somehow, it escaped the todo list ... Thinking about it, I can see a few
use
case where it would be useful to be able to have access to a valid session
id from the client side (i.e. in beginXXX()) :
* if the code to test is using HttpServletRequest.getRequestedSessionId()
and does something with the returned id,
* if you're using session ID encoded in the URL and thus need to construct
a
URL with the session in it
Good point ! Thanks for asking this question ! I'll add that to the TODO
list.
Here is what we could do :
* By default, the Cactus redirector does not create any session.
* Remove the WebRequest.setAutomaticSession() and instead add
WebRequest.createCookieSession(String cookieName). This API would call the
redirector which would create a session on the server side, return it and
create a cookie that will be sent on the next request.
* Add a WebRequest.createURLSession(String paramName). This API would call
the redirector which would create a session on the server side and will
append an HTTP parameter with this name in the next request to the server
* Use it in the following way :
// For sessions in cookies
public void beginXXX(WebRequest theRequest)
{
theRequest.createCookieSession("jessionid");
}
public void testXXX()
{
// Provided the container is set up to accept cookie sessions (usually
the
default)
assert(request.getSession(false) = null);
}
// For sessions in URL
public void beginXXX(WebRequest theRequest)
{
theRequest.createURLSession("jessionid");
}
public void testXXX()
{
// Provided the container is set up to accept URL sessions (usually need
to turn on a parameter in container configuration)
assert(request.getSession(false) = null);
}
Now, you're going to tell me that it does not resolve the issue of sending
the _same_ id on several requests. You can easily do this by saving the
returned session id. The createCookieSession() and createURLSession() need
to return the id, which can be saved for later reuse. I don't like it too
much because each unit test is supposed to be independent of another and it
means you need to order the tests or check if the id has already been set
and if not, then create it ...
Why would you need to use the same id ? In can only think of cases when
you'll have saved the id to persisent storage and would need to compare
against that. Are there other cases ? If not, then lets answer the
persistent storage cases.
There are 2 schools here :
* School 1 (which is the Mock Object school) : your unit test need to be
isolated from its surrounding environment, meaning you need to provide mock
objects for your persistent store. That would solve the problem as you
could
then use any id. This is something that you can do with Cactus.
* School 2 : You consider Cactus to be an integration framework and you
want
to use it to verify that everything works till the storage. In that case,
the only simple solution is probably the one highlighted above.
Any other ideas ?
>
> Thanks anyway though.
well, thank to you for finding this good TODO item ... :-)
Want to help ? :-)
-Vincent
>
>
>
>
>
>
> "Vincent Massol"
> <[EMAIL PROTECTED]> To:
<[EMAIL PROTECTED]>
> cc:
> 09/20/2001 09:49 AM Subject: Re: How does cactus
simulate a session?
> Please respond to
> "Vincent Massol"
>
>
>
>
>
>
> Hi Kyle,
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, September 20, 2001 3:05 PM
> Subject: How does cactus simulate a session?
>
>
> >
> > Hello,
> >
> > I am trying to find out how Cactus simulates a session. I am trying to
> > build a test tool similar to Cactus to test our web application. I
can't
> > seem to find the code that maintains the user's session. For instance
if
> I
> > have a client (browser), the thing that makes our web app tick is the
> > session. And the fact that all the requests to the server come from
the
> > same session. How does Cactus simulate this series of requests with
the
> > same session id. Specifically, in its repeated requests to the webapp;
> how
> > does it pass the same session id with its request each time? Any help
> > would be appreciated, thanks for everyone's time.
> >
>
> First, Cactus is made for performing unit tests, meaning you don't test a
> full test case with Cactus (this is an acceptance test that must be done
> with another tool). What you would do in Cactus, is break down a use case
> in
> different steps and more specifically different method calls. In a given
> test, you need to set up the correct environment parameters (in addition
to
> the parameters being passed to the method). Your question is very true
for
> the case when inside your code to test you verify for example that a
> session
> has already been set up. If not, you might do something and if yes you do
> something else. Your question is now : how do you test that ?
>
> Let's write it ! Imagine we have the following code to test :
>
> public int someMethod(HttpServletRequest theRequest)
> {
> if (theRequest.getSession(false)) {
> return 1;
> } else {
> return 2;
> }
> }
>
> The corresponding test cases would be :
>
> public void beginSomeMethodNoSession(WebRequest theRequest)
> {
> theRequest.setAutomaticSession(false);
> }
>
> public void testSomeMethodNoSession()
> {
> MyClassToTest c = new MyClassToTest();
> int result = c.someMethod(request);
> assertEquals(2, result);
> }
>
> public void testSomeMethodSession()
> {
> MyClassToTest c = new MyClassToTest();
> int result = c.someMethod(request);
> assertEquals(1, result);
> }
>
> Note that for the testSomeMethodSession() test, we do not need a beginXXX
> method because the default behaviour of Cactus is to create a session for
> the test.
>
> Anything that I might be missing ?
> Thanks and hope it helps.
>
> > Kyle Willkomm
> -Vincent Massol
>
>
>
>
>
> This message is for the designated recipient only and may contain
> privileged or confidential information. If you have received it in
error,
> please notify the sender immediately and delete the original. Any other
> use of the email by you is prohibited.
>
>
This message is for the designated recipient only and may contain
privileged or confidential information. If you have received it in error,
please notify the sender immediately and delete the original. Any other
use of the email by you is prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]