Here's how I create a MockContext:

 protected MockServletContext createMockContext() {

        MockServletContext mockContext = new MockServletContext("/");
        Map<String, String> filterParams = new HashMap<String, String>();
        filterParams.put("ActionResolver.Packages", "de.strunk.web");
        filterParams.put("ActionBeanContext.Class", 
TestApplicationContext.class.getCanonicalName());
        mockContext.addFilter(StripesFilter.class, "StripesFilter", 
filterParams);
        mockContext.setServlet(DispatcherServlet.class, 
"StripesDispatcher", null);

       return mockContext;
}

I've upgrade to Stripes 1.5 Development Snapshot, July 1st 2008, but 
that didn't change anything.


Newman, John W wrote:
> need to see the code for createMockContext.
>
> Are you following section 2 of 
> http://stripesframework.org/display/stripes/Unit+Testing ?
>
>
> ________________________________________
> From: [EMAIL PROTECTED] [EMAIL PROTECTED] On Behalf Of Karsten Strunk [EMAIL 
> PROTECTED]
> Sent: Thursday, July 31, 2008 4:36 PM
> To: Stripes Users List
> Subject: Re: [Stripes-users] ActionBeanContext and MockRoundtrip
>
> Hi,
>
> Ah, I unterstand. If I use a mock to prepare the data in HTTP session
> mocking my test class should work.
>
> But unfortunately a new session is created with every new trip although
> I pass the MockHttpSession instance to each new mock.
> Maybe this exception I get is the cause of the problem:
>
> net.sourceforge.stripes.exception.StripesRuntimeException: Something is
> trying to access the current Stripes configuration but the current
> request was never routed through the StripesFilter! As a result the
> appropriate Configuration object cannot be located. Please take a look
> at the exact URL in your browser's address bar and ensure that any
> requests to that URL will be filtered through the StripesFilter
> according to the filter mappings in your web.xml.
>     at
> net.sourceforge.stripes.controller.StripesFilter.getConfiguration(StripesFilter.java:160)
>     at net.sourceforge.stripes.util.CryptoUtil.encrypt(CryptoUtil.java:123)
>     at
> net.sourceforge.stripes.mock.MockRoundtrip.setSourcePage(MockRoundtrip.java:184)
>     at
> net.sourceforge.stripes.mock.MockRoundtrip.<init>(MockRoundtrip.java:119)
>     at
> net.sourceforge.stripes.mock.MockRoundtrip.<init>(MockRoundtrip.java:88)
>     at
> net.sourceforge.stripes.mock.MockRoundtrip.<init>(MockRoundtrip.java:74)
>
>
> Here's what I'm doing:
>
>         // Login user
>         MockServletContext mockContext = createMockContext();
>         MockRoundtrip trip = new MockRoundtrip(mockContext,
> LoginActionBean.class);
>         trip.setParameter("username", "username");
>         trip.setParameter("password", "password");
>         trip.execute();
>         MockHttpSession mockSession = (MockHttpSession)
> trip.getRequest().getSession();
>
>         // Perform password change
>         MockRoundtrip trip = new MockRoundtrip(mockContext,
> ChangePasswordActionBean.class, mockSession);
>         trip.setParameter("username", "username");
>         trip.setParameter("oldPassword", "password");
>         trip.setParameter("newPassword", "newPassword");
>         trip.setParameter("newPasswordRep", "newPassword");
>         trip.execute();
>
>
> Any ideas?
>
>
> Newman, John W wrote:
>   
>> How do you fill the action bean context outside of the tests?  Make a mock 
>> trip to that event handler first, then pull the http session out of that 
>> trip, and pass it over to a new trip.  The MockRoundTrip constructor with 
>> the HttpSession argument is what you want.
>>
>> i.e. we have
>>
>>
>> class SomeTest extends SecureTestFixture<User>  {
>>
>>         public void testBody()  {
>>                 MockRoundTrip trip = createSecureTrip(SomeAction.class);
>>                 trip.execute();
>>         }
>> }
>>
>> class SecureTestFixture<User extends BaseUser<?>>  {
>>
>>         protected MockRoundtrip createSecureTrip(
>>                         Class<? extends ActionBean> beanClass,
>>                         String loginName) {
>>                 return new MockRoundtrip(getMockContext(), beanClass, 
>> getSecureSession(loginName));
>>         }
>>
>>         protected MockHttpSession getSecureSession(String loginName) {
>>                 MockRoundtrip trip = 
>> createInSecureTrip(getTestLoginActionBeanClass());
>>                 trip.addParameter("potentialUser.loginName", loginName);
>>                 trip.addParameter("potentialUser.password", "fakepassword");
>>                 try {
>>                         trip.execute(Events.LOGIN_LOGIN);
>>                 } catch (Exception e) {
>>                         throw new IllegalStateException(e);
>>                 }
>>                 return (MockHttpSession) trip.getRequest().getSession();
>>         }
>>
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Karsten Strunk
>> Sent: Thursday, July 31, 2008 1:13 PM
>> To: [email protected]
>> Subject: [Stripes-users] ActionBeanContext and MockRoundtrip
>>
>> Hi,
>>
>> I'm trying to implement JUnit tests for my Stripes actions. But there
>> I've a problem.
>>
>> As described in the Stripes State Management article my ActionBeans use
>> a subclass of ActionBeanContext to store application wide data instead
>> of accessing the HttpSession directly. The problem is now how to prepare
>> the ActionBeanContext with data my actions rely on?
>> I tried:
>>
>>         MockServletContext ctx = createMockContext();
>>         MockRoundtrip trip = new MockRoundtrip(ctx, MyActionBean.class);
>>         ActionBeanContext actionBeanContext =
>> trip.getActionBean(MyActionBean.class).getContext();
>>
>> But actionBeanContext is null until I call
>>
>>        trip.execute()
>>
>> So how can I prefill my context before(!) executing an ActionBean?
>>
>> Hope somebody can help me here!
>>
>> Best regards,
>> Karsten
>>
>>
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
>> Build the coolest Linux based applications with Moblin SDK & win great prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> Stripes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
>> Build the coolest Linux based applications with Moblin SDK & win great prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> Stripes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>>     
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>   



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to