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

Reply via email to