package .webapp.action; import .; import .webapp.action.BaseControllerTestCase; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.validation.BindException; import org.springframework.validation.Errors; import org.springframework.web.servlet.ModelAndView; public class FormControllerTest extends BaseControllerTestCase { private FormController c = null; private MockHttpServletRequest request; private ModelAndView mv; public void setFormController(FormController form) { this.c = form; } public void testEdit() throws Exception { log.debug("testing edit..."); request = newGet("/edit.html"); request.addParameter("", "1"); mv = c.handleRequest(request, new MockHttpServletResponse()); assertEquals("Form", mv.getViewName()); } public void testSave() throws Exception { request = newGet("/edit.html"); request.addParameter("", "1"); mv = c.handleRequest(request, new MockHttpServletResponse()); = () mv.getModel().get(c.getCommandName()); assertNotNull(); request = newPost("/edit.html"); super.objectToRequestParameters(, request); // update the form's fields and add it back to the request mv = c.handleRequest(request, new MockHttpServletResponse()); Errors errors = (Errors) mv.getModel().get(BindException.MODEL_KEY_PREFIX + ""); if (errors != null) { log.debug(errors); } assertNull(errors); assertNotNull(request.getSession().getAttribute("successMessages")); } public void testRemove() throws Exception { request = newPost("/edit.html"); request.addParameter("delete", ""); request.addParameter("", "2"); mv = c.handleRequest(request, new MockHttpServletResponse()); assertNotNull(request.getSession().getAttribute("successMessages")); } }