Where ever you're creating a new MockRoundTrip(), there's an additional constructor to attach an existing http session. Looks like you're prebuilding a session w/ your spring beans injected, but are you passing that session into any trips? Maybe post the code for one of the unit tests.
Just curious, what are you using spring http session beans for? -----Original Message----- From: paulsjv [mailto:paul...@gmail.com] Sent: Friday, December 18, 2009 12:57 PM To: stripes-users@lists.sourceforge.net Subject: [Stripes-users] Unit Testing Mock Object & Spring Beans Hi everyone, I’m a new user to Stripes and so far I’m really enjoying my experience. So thanks for a great framework! My question has to do with unit testing with the Stripes mock objects and the injection of Spring beans into my action beans. We currently have a couple of Spring beans that are session scoped (they are defined scope=”session” in the applicationContext.xml). This leads to the following error (see stack trace below). We were able to get around this scoping issue within the application by adding the RequestContextLister to our web.xml file (see below). I tried to duplicate what was in our web.xml in a BaseTest class to setup all the mock objects but that doesn’t seem to be working (see code below). Any ideas or tips would be appreciated! Thanks, Jay public class BaseTest { protected static MockServletContext mockServletContext; protected static MockHttpSession mockSession; protected static MockHttpServletRequest mockHttpServletRequest; @Before public void setUpMock() throws Exception { mockServletContext = new MockServletContext("inspector_test"); mockHttpServletRequest = new MockHttpServletRequest(mockServletContext.getContextPath(), getServletPath()); Map<String, String> params = new HashMap<String, String>(); params.put("ActionResolver.Packages", "com.initiatesystems.accessibility.actions"); params.put("Interceptor.Classes", "net.sourceforge.stripes.integration.spring.SpringInterceptor"); params.put("LocalizationBundleFactory.FieldNameBundle", "Application"); params.put("PopulationStrategy.Class", "net.sourceforge.stripes.tag.BeanFirstPopulationStrategy"); params.put("LocalizationBundleFactory.ErrorMessageBundle", "Application"); mockServletContext.addFilter(StripesFilter.class, "StripesFilter", params); // my guess is the realitive path is /WEB-INF/classes hence the ../ mockServletContext.addInitParameter("contextConfigLocation", "../applicationContext.xml,../spring-servlet.xml"); ContextLoaderListener springContextLoader = new ContextLoaderListener(); springContextLoader.contextInitialized(new ServletContextEvent(mockServletContext)); RequestContextListener springRequestContextListener = new RequestContextListener(); springRequestContextListener.requestInitialized(new ServletRequestEvent(mockServletContext, mockHttpServletRequest)); mockServletContext.setServlet(DispatcherServlet.class, "DispatcherServlet", null); } /** * Hook to set the servlet path for the creation of a * MockHttpServletReqest object in the @BeforeClass * /actionType/foo.action * @return */ protected String getServletPath() { return null; } } Web.xml <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> SEVERE: 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:161) at net.sourceforge.stripes.util.CryptoUtil.encrypt(CryptoUtil.java:123) at net.sourceforge.stripes.mock.MockRoundtrip.setSourcePage(MockRoundtrip.java:234) at net.sourceforge.stripes.mock.MockRoundtrip.<init>(MockRoundtrip.java:160) at net.sourceforge.stripes.mock.MockRoundtrip.<init>(MockRoundtrip.java:105) at com.initiatesystems.accessibility.actions.TaskSearhActionBeanTest.testFailBeginEndDates(TaskSearhActionBeanTest.java:135) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99) at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75) at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45) at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71) at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Dec 18, 2009 8:57:58 AM net.sourceforge.stripes.util.Log warn WARNING: Found unique SpringBean with type [com.initiatesystems.web.inspector.controller.InspectorInitController]. Matching on type is a little risky so watch out! Dec 18, 2009 8:57:58 AM net.sourceforge.stripes.util.Log warn WARNING: Unhandled exception caught by the Stripes default exception handler. net.sourceforge.stripes.exception.StripesRuntimeException: Exception while trying to lookup and inject a Spring bean into a bean of type TaskSearchActionBean using field access on field protected com.initiatesystems.web.common.spring.LoginBean com.initiatesystems.accessibility.actions.BaseActionBean.loginBean at net.sourceforge.stripes.integration.spring.SpringHelper.injectBeans(SpringHelper.java:132) at net.sourceforge.stripes.integration.spring.SpringHelper.injectBeans(SpringHelper.java:93) at net.sourceforge.stripes.integration.spring.SpringHelper.injectBeans(SpringHelper.java:81) at net.sourceforge.stripes.integration.spring.SpringInterceptor.intercept(SpringInterceptor.java:67) at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155) at net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113) at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155) at net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74) at net.sourceforge.stripes.controller.DispatcherHelper.resolveActionBean(DispatcherHelper.java:102) at net.sourceforge.stripes.controller.DispatcherServlet.resolveActionBean(DispatcherServlet.java:238) at net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:141) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at net.sourceforge.stripes.mock.MockFilterChain.doFilter(MockFilterChain.java:66) at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:247) at net.sourceforge.stripes.mock.MockFilterChain.doFilter(MockFilterChain.java:63) at net.sourceforge.stripes.mock.MockServletContext.acceptRequest(MockServletContext.java:255) at net.sourceforge.stripes.mock.MockRoundtrip.execute(MockRoundtrip.java:245) at net.sourceforge.stripes.mock.MockRoundtrip.execute(MockRoundtrip.java:257) at com.initiatesystems.accessibility.actions.TaskSearhActionBeanTest.testFailBeginEndDates(TaskSearhActionBeanTest.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99) at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75) at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45) at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71) at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.IllegalArgumentException: Session must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.web.util.WebUtils.getSessionMutex(WebUtils.java:327) at org.springframework.web.context.request.ServletRequestAttributes.getSessionMutex(ServletRequestAttributes.java:191) at org.springframework.web.context.request.SessionScope.get(SessionScope.java:88) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:285) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:737) at net.sourceforge.stripes.integration.spring.SpringHelper.findSpringBean(SpringHelper.java:258) at net.sourceforge.stripes.integration.spring.SpringHelper.injectBeans(SpringHelper.java:128) ... 38 more -- View this message in context: http://old.nabble.com/Unit-Testing-Mock-Object---Spring-Beans-tp26845824p26845824.html Sent from the stripes-users mailing list archive at Nabble.com. ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ 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 Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Stripes-users mailing list Stripes-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/stripes-users