assertEquals("mySurpriseView", response.getContentAsString());
}
@Test
public void postMethodNameDispatchingController() throws Exception {
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller",
new RootBeanDefinition(MyPostMethodNameDispatchingController.class));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myHandle.do");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(405, response.getStatus());
request = new MockHttpServletRequest("POST", "/myUnknownHandle.do");
request.addParameter("myParam", "myValue");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(404, response.getStatus());
request = new MockHttpServletRequest("POST", "/myHandle.do");
request.addParameter("myParam", "myValue");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("myView", response.getContentAsString());
request = new MockHttpServletRequest("POST", "/myOtherHandle.do");
request.addParameter("myParam", "myValue");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("myOtherView", response.getContentAsString());
request = new MockHttpServletRequest("POST", "/myLangHandle.do");
request.addParameter("myParam", "myValue");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("myLangView", response.getContentAsString());
request = new MockHttpServletRequest("POST", "/mySurpriseHandle.do");
request.addParameter("myParam", "myValue");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("mySurpriseView", response.getContentAsString());
}