[ 
http://www.stripesframework.org/jira/browse/STS-582?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12200#comment-12200
 ] 

Nikolaos commented on STS-582:
------------------------------

I ran into this issue as well... however in looking at:
http://www.stripesframework.org/jira/browse/STS-325

I was inspired to try to obtain the message another way... and came up with 
this solution:

     MockRoundtrip trip = new MockRoundtrip(...);
     MockHttpServletRequest request = trip.getRequest();
     ...
     List<Message> beanMessages = (List<Message>) 
request.getAttribute(StripesConstants.REQ_ATTR_MESSAGES);

And voila the messages are available.

Unfortunately as Tim explains in STS-325 it does not appear that the FlashScope 
related code can ever work b/c of how Stripes works w.r.t. FlashScope.

As such, I think this work around is just as good moreover IMO we should close 
this issue.

--Nikolaos

> NPE in MockRoundTrip getting Messages
> -------------------------------------
>
>                 Key: STS-582
>                 URL: http://www.stripesframework.org/jira/browse/STS-582
>             Project: Stripes
>          Issue Type: Bug
>          Components: Context Management
>    Affects Versions: Release 1.4.3
>         Environment: JDK 1.6 Stripes 1.4.3 TestNG 5.8
>            Reporter: Melloware
>
> When executing a MockRoundTrip test like the following:
>    @Test(description="Test handler to logout of application")
>    public void logoutTest() throws Exception {
>        // Setup the servlet engine
>        MockServletContext ctx = StripesTestFixture.getServletContext();
>        MockRoundtrip trip = new MockRoundtrip(ctx, LogoutActionBean.class);
>        trip.execute();
>        LogoutActionBean bean = trip.getActionBean(LogoutActionBean.class);
>        Assert.assertNotNull(bean.getContext().getMessages());
>        Assert.assertEquals(trip.getDestination(), 
> LogoutActionBean.LOGOUT_PAGE);
>    }
> The call to bean.getContext.getMessages() throws an NPE because when tracing 
> the code the FlashScope is being returned null in the ActionBeanContext found 
> in this method of the ActionBeanContext
> public List<Message> getMessages(String key) {
>         FlashScope scope = FlashScope.getCurrent(getRequest(), true);
>         List<Message> messages = (List<Message>) scope.get(key);
>         if (messages == null) {
>             messages = new ArrayList<Message>();
>             scope.put(key, messages);
>         }
>         return messages;
>     }
> The second line where it calls scope.get(key) is throwing the NPE because 
> scope is somehow null.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to