struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Haroon Rafique <haroon.rafi...@utoronto.ca>
Subject Re: unit testing Struts2 application (with Spring and Hibernate)
Date Mon, 20 Jul 2009 22:02:50 GMT
On Today at 4:32pm, DC=>Dimitrios Christodoulakis <dimi.chr@gmail.com> wrote:

DC> Thanks Haroon for the handy advice. That seems to do the trick as far 
DC> as the session object is concerned. The test passes now.
DC> 

Glad it worked out.

DC> 
DC> Would it be easy for someone to extend your code to include actions 
DC> that implement the -aware interfaces? If I wanted to take a shot at 
DC> that, is there a particular point you would suggest I start with?
DC> 

Did you add that code in your Test class? I was actually suggesting that 
you modify the code inside BaseStrutsTestCase. So, I would recommend 
adding a private static HashMap variable called sessionMap in 
BaseStrutsTestCase. And then in the createAction method, issue the 
statement:
    proxy.getInvocation().getInvocationContext().setSession(sessionMap);

Hope that helps.

The only other fringe case that I have dealth with in our code, is when we 
have actions that implement Preparable and are used with a 
ParamsPrepareParams interceptor. I created a method to allow action 
parameters to be set.

/** 
  * Sets the action parameters 
  * @param parameters Parameters to set 
  */ 
protected void setActionParameters(Map<String, String> 
parameters) { 
   proxy.getInvocation().getInvocationContext(). 
           setParameters(parameters); 
}

Then inside my Action Test class, I can issue:
  proxy.setActionParameters(...);
before:
  proxy.execute();

Cheers,
--
Haroon Rafique
<haroon.rafique@utoronto.ca>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message