Wednesday, April 20, 2005

StrutsTestCase and Tokens

How does one get around the usage of Struts tokens when unit testing using StrutsTestCase? If the action class under tests for duplicate submissions using tokens,

if(isTokenValid(request) == false) {
// don't perform the action and route the user
// to an appropriate location
}

it'll always fail. This is because, the token is set in the request by the tag and of course when running a StrutsTestCase, the JSP isn't involved.

The application functions correctly, however, I cannot run my unit tests :(

1 comment:

  1. add the following before your test :

    addRequestParameter(Constants.TOKEN_KEY, "testToken");

    getSession().setAttribute(Globals.TRANSACTION_TOKEN_KEY, "testToken");

    ReplyDelete

Tweety thoughts

    follow me on Twitter