struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: ActionContext.getContext().getSession return null when I test Struts2 action by JUnit.
Date Fri, 01 Feb 2008 16:59:26 GMT
For completeness: you could also re-work your action to implement 
SessionAware instead of using ActionContext.getContext().getSession(). 
Unit testing would then simply involve calling setSession() on the 
action under test. The SessionAware interface exists, in part, to make 
testing easier by decoupling your actions from their execution context.

L.

Joey wrote:
> I found it . like this.
> 
>         Map param = new HashMap();
>         ActionContext.getContext().setSession(param);
> 
> Thanks for your help
> 
> On Feb 1, 2008 4:53 PM, Joey <joey.information@gmail.com> wrote:
>> Thanks,  I just checked testing class in Struts2 package,  but I am a
>> newbie for Struts2. I cannot understant Struts2 very well, so if you
>> don't mind, pls tell me which testing class I can learn from.
>>
>> Thanks again
>>
>>
>> On Feb 1, 2008 4:31 PM, Nils-Helge Garli Hegvik <nilsga@gmail.com> wrote:
>>> You need to initialize the ActionContext in your unit tests. Take a
>>> look at the Struts 2 tests how it is solved there.
>>>
>>> Nils-H
>>>
>>>
>>> On Feb 1, 2008 9:28 AM, Joey Watson <joey.information@gmail.com> wrote:
>>>> Hi everybody.
>>>>
>>>> I want to test a action class (Struts2) by JUnit. and then method in
>>>> this action need a value in session, then when I run my JUnit test
>>>> class,  ActionContext.getContext().getSession return null. (not
>>>> ActionContext.getContext().getSession().get("XXX") return null).
>>>> this action class is working fine in browser.
>>>>
>>>>
>>>> thanks for any help
>>>>
>>>> Joey
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>


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


Mime
View raw message