public void testAdaptedHandleMethods3() throws Exception {
doTestAdaptedHandleMethods(MyAdaptedController3.class);
}
private void doTestAdaptedHandleMethods(final Class<?> controllerClass) throws Exception {
@SuppressWarnings("serial")
DispatcherServlet servlet = new DispatcherServlet() {
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath1.do");
MockHttpServletResponse response = new MockHttpServletResponse();
request.addParameter("param1", "value1");
request.addParameter("param2", "2");
servlet.service(request, response);
assertEquals("test", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/myPath2.do");
request.addParameter("param1", "value1");
request.addParameter("param2", "2");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("test-value1-2", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/myPath3.do");
request.addParameter("param1", "value1");
request.addParameter("param2", "2");
request.addParameter("name", "name1");
request.addParameter("age", "2");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("test-name1-2", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/myPath4.do");
request.addParameter("param1", "value1");
request.addParameter("param2", "2");
request.addParameter("name", "name1");
request.addParameter("age", "value2");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("test-name1-typeMismatch", response.getContentAsString());
}