I have the following code I am testing my controller with a Junit testcase if i run the testcase it runs with the following error
"ApplicationObjectSupport instance [BasicController@13f210f] does not run in an ApplicationContext "
But when I comment the following line
inside BasicController file my testcase runs successfully...Code:ApplicationContext context = this.getApplicationContext();
Please help what i am doing wrong I need that Context for checking the layout...
How can i test this what changees need to be done inside testCase file..
Please Help..
Regards
BuntyIndia
BasicController
testBasicControllerCode:public class BasicController extends UrlFilenameViewController { protected ModelAndView handleRequestInternal(HttpServletRequest aRequest, HttpServletResponse aResponse) { ModelAndView mv = super.handleRequestInternal(aRequest, aResponse); mv.getModel().put("b", mv.getViewName() + ".jsp"); ApplicationContext context = this.getApplicationContext(); /**Do Some thing with the Context and return MV with layout**/ return mv; }
Code:public class testBasicController extends TestCase { public void testGettingIndexPage() throws Exception { BasicController controller = new BasicController(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.setMethod("GET"); request.setContextPath("/POC"); request.setRequestURI("/index.htm"); ModelAndView modelAndView = controller.handleRequest(request, response); assertEquals("Should get Index page", modelAndView.getModel().get("b") , "index.jsp"); } }


Reply With Quote