jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From BALA KRISHNA <ebalki2...@yahoo.com>
Subject RE: Concatenating two cactus tests?
Date Sat, 23 Feb 2002 00:59:16 GMT
Hi Vincent,


>In your test for testB, you need to add the cookie to
>the request, in
>beginXXX(). It is all about unit testing, i.e. about
>testing in
>isolation. You know the cookie name and you know
>values with which you
>wan to test. Thus, you can set the cookie in beginXXX

>Do you have a use case in mind where this would not
>work ?

An example wouldbe what I have given in my previous
email. Let me explain better this time by filling the
skeleton code of yours.

beginTestLogin(...)
{
  // set what is needed WRT the HTTP request
...
  req.addParameter("user", "test");
  req.addParameter("pwd", "test123");
}

testTestLogin()
{
  // set what is need WRT container objects
...  
  Authenticator auth = new Authenticator();
  // Execute the test
  // This method will read user and pwd parameters, 
  // creates a custom sessionid and stores it as a 
  // cookie in the response. It also stores it in the 
  // database.

  auth.login(request, response);
...
  // Assert server side objects
...
}

endTestLogin(...)
{
  // Assert HTTP related response values
...
  String sid = response.getCookie().getValue();
  // When I go to another page on the site, this   
  // cookie is required to validate the session and 
  // display the information. Authenticator class 
  // therefore has another API called validate that 
  // needs this cookie obtained in the response here.
  // Therefore, I store it as a system property as I 
  // dont know other way of accessing this information

  // in next test.

  System.setProperty("sid", sid);
}

// Now the test that I am interested in - validate

beginTestValidate (...)
{
  // I need to set a valid session id obtained on   
  // logging in to the application in the cookie of  
  // this request. Therefore, I read that cookie from 
  // previous test. If I dont pass a valid session id,
  // I cannot test this method because this method 
  // returns information only if it can find the 
  // session id passed in the cookie to already exist 
  // in the database (inserted during login).

  String sid = System.getProperty("sid");
  request.addCookie("sid", sid);
}

testTestValidate()
{
  Authenticator auth = new Authenticator();
  // Execute the test
  // This method will read sid cookie, 
  // and returns true if validated.

  Boolean sidExists = auth.login(request, response);

  // I want to create a test where I sid already
exists
  // so that following assert will not fail.
  assertTrue("Could not validate", sidExists);

}

Now, if I dont save the result from a previous test or
use Method 2 where I use HttpUnit in beginTestValidate
to get a valid session id, how can I get
testTestValidate to work?

beginXXX using Method 2: (I havnt tried this though)

beginTestValidate (...)
{

  WebConversation conversation = new
WebConversation();
  PostMethodWebRequest request2 = new
PostMethodWebRequest("http://localhost:8080/test/login.jsp");
  request2.setParameter( "user", "test" );
  request2.setParameter( "pwd", "test123" );
  WebResponse response2 = conversation.getResponse(
request2 );
  String sid = response2.getNewCookieValue("sid");
  request.addCookie("sid",sid);

}

Thanks,
balki


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

--
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