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

Reply via email to