package com.vst.webapp.action;
import com.vst.model.Parameter;
import com.vst.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 ParameterFormControllerTest extends BaseControllerTestCase {
private ParameterFormController c;
private MockHttpServletRequest request;
private ModelAndView mv;
protected void setUp() throws Exception {
// needed to initialize a user
super.setUp();
c = (ParameterFormController) ctx.getBean("parameterFormController");
}
protected void tearDown() {
c = null;
}
public void testEdit() throws Exception {
log.debug("testing edit...");
request = newGet("/editParameter.html");
request.addParameter("parameterId", "1");
mv = c.handleRequest(request, new MockHttpServletResponse());
assertEquals("parameterForm", mv.getViewName());
}
public void testSave() throws Exception {
request = newGet("/editParameter.html");
request.addParameter("parameterId", "1");
mv = c.handleRequest(request, new MockHttpServletResponse());
Parameter parameter = (Parameter) mv.getModel().get(c.getCommandName());
assertNotNull(parameter);
request = newPost("/editParameter.html");
super.objectToRequestParameters(parameter, 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 + "parameter");
if (errors != null) {
log.debug(errors);
}
assertNull(errors);
assertNotNull(request.getSession().getAttribute("successMessages"));
}
public void testRemove() throws Exception {
request = newPost("/editParameter.html");
request.addParameter("delete", "");
request.addParameter("parameterId", "2");
mv = c.handleRequest(request, new MockHttpServletResponse());
assertNotNull(request.getSession().getAttribute("successMessages"));
}
}