Ok, I got around the exception. The problem was that MockServletContext was created everytime. Since there's only a single instance the exception is gone. But there's still my origin problem. The ActionBeanContext is always empty in my tested ActionBeans. Here's what I'm trying in my test:
this.mockSession = new MockHttpSession(getMockContext()); MockRoundtrip trip = new MockRoundtrip(getMockContext(), Bean1.class, this.mockSession); trip.setParameter(...); trip.execute(); MockRoundtrip trip = new MockRoundtrip(getMockContext(), Bean2.class, this.mockSession); trip.setParameter(...); trip.execute(); getMockContext() always returns the same instance. Bean2 relies on information set in ActionBeanContext by Bean1. Since the ActionBeanContext is empty the test fails. Has anybody an idea what's going wrong? Bye Strunker -------- Original Message -------- 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: stripes-users@lists.sourceforge.net > 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 > Stripes-users@lists.sourceforge.net > 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 > Stripes-users@lists.sourceforge.net > 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 Stripes-users@lists.sourceforge.net 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 Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users