On Fri, Oct 14, 2011 at 6:29 PM, Maurizio Cucchiara
<[email protected]> wrote:
> Christian,
> I'm not sure I understand, Did you solve your issue?

No. Just the second message is crap. The first one still applies.
This is still true:

>>> On Fri, Oct 14, 2011 at 5:54 PM, Christian Grobmeier
>>> <[email protected]> wrote:
>>>> Guys,
>>>> its getting complicated. But I digged out a nasty thing in Junit
>>>> testing. I know whats wrong but looking for advise to fix the correct
>>>> place in Struts.
>>>>
>>>> Imagine:
>>>>
>>>> @RunWith(SpringJUnit4ClassRunner.class)
>>>> @ContextConfiguration(locations = {"classpath*:applicationContext.xml"})
>>>> public class MyClass extends StrutsSpringJUnit4TestCase<MyAction> {
>>>>
>>>> @Test public void testMyStuff() {
>>>>       this.executeAction("/login.action");
>>>>       this.executeAction("/dostuff.action");
>>>>       Assert.assertEquals(1, this.getAction().methodFromMyAction());
>>>> }
>>>> }
>>>>
>>>>
>>>> So imagine what happens when I call getAction() which is MyAction for
>>>> the compiler?
>>>> Its a ClassCastException. Because actually its coming a LoginAction
>>>> from the first call back
>>>>
>>>> Here is how you can bring it to fly, in my special case:
>>>>
>>>> this.executeAction('/login.action');
>>>>
>>>> SessionMap session =
>>>> (SessionMap)ServletActionContext.getValueStack(request).getContext().get("session");
>>>> SessionUser sUser = (SessionUser)session.get("myuser");
>>>>
>>>> // Reinit request stuff
>>>> this.request = new MockHttpServletRequest();
>>>> this.response = new MockHttpServletResponse();
>>>> this.pageContext = new MockPageContext(servletContext, request, response);
>>>>
>>>> // Put stuff back into session what you need
>>>>  this.request.getSession().setAttribute("tabuser", sUser);
>>>>
>>>> // now it works:
>>>> this.executeAction("/dostuff.action");
>>>> Assert.assertEquals(1, this.getAction().methodFromMyAction());
>>>>
>>>>
>>>> So far so good - it seems like the first calls meta data like session
>>>> is somehow stored somewhere. To make it all work you'll need to reinit
>>>> the whole StrutsJUnit4TestCase mock objects - but then you'll loose
>>>> your session data you probably need for the second call.
>>>>
>>>> If we don't fix it, people can only use this for one test class = one
>>>> actions tests. But then how do you make tests for action flows?
>>>>
>>>> Now I need some good ideas how a potential test can look like- ideas 
>>>> welcome.
>>>>
>>>> In addition I would like to open an issue for that.
>>>>
>>>> Cheers
>>>> Christian
>>>>
>>>>
>>>> --
>>>> http://www.grobmeier.de
>>>>
>>>
>>>
>>>
>>> --
>>> http://www.grobmeier.de
>>>
>>
>>
>>
>> --
>> http://www.grobmeier.de
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>



-- 
http://www.grobmeier.de

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to