I have a session object that is injected into my controller (Spring MVC).
I am having great difficulty writing an integration test for it.
I can configure my WebApplicationContext just fine, but when I try and run my controller test I get the following error
This is how I instantiate my WebApplicationContext.Code:org.springframework.beans.factory.BeanCreationException: Error creating bean with name '__shoppingBasket': Scope 'session' is not active; nested exception is java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter Caused by: java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter at org.springframework.web.context.scope.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:60) at org.springframework.web.context.scope.SessionScope.get(SessionScope.java:77) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:274) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:153) at org.springframework.aop.target.AbstractPrototypeBasedTargetSource.newPrototypeInstance(AbstractPrototypeBasedTargetSource.java:58) at org.springframework.aop.target.PrototypeTargetSource.getTarget(PrototypeTargetSource.java:30) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.getTarget(Cglib2AopProxy.java:673) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:624) at com.au.odin.web.support.ShoppingBasketBean$$EnhancerByCGLIB$$1a85fb85.add(<generated>) at com.au.odin.web.spring.ShoppingBasketController.handleShop(ShoppingBasketController.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:434) at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:372) at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153) at com.au.odin.web.spring.ShoppingBasketControllerTest$1.onRequest(ShoppingBasketControllerTest.java:43) at com.au.commons.test.spring.ControllerTestsHelper.submitRequest(ControllerTestsHelper.java:66) at com.au.commons.test.dbunit.spring.ControllerTests.submitRequest(ControllerTests.java:100) at com.au.commons.test.dbunit.spring.ControllerTests.submitRequest(ControllerTests.java:77) at com.au.commons.test.dbunit.spring.HibernateControllerTests.submitRequest(HibernateControllerTests.java:53) at com.au.odin.web.spring.ShoppingBasketControllerTest.testAddItem(ShoppingBasketControllerTest.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I have discovered the MockFilterConfig but am not sure about how to make the WebApplicationContext aware of it.Code:String path[] = {"applicationContext.xml" }; applicationContext = new XmlWebApplicationContext(); applicationContext.setConfigLocations(path); applicationContext.setServletContext(new MockServletContext("")); applicationContext.refresh();


Reply With Quote
