Package com.vst.webapp.action

Source Code of com.vst.webapp.action.ObjectConstructionFormControllerTest

package com.vst.webapp.action;

import com.vst.model.ObjectConstruction;
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 ObjectConstructionFormControllerTest extends BaseControllerTestCase {
    private ObjectConstructionFormController c;
    private MockHttpServletRequest request;
    private ModelAndView mv;

    protected void setUp() throws Exception {
        // needed to initialize a user
        super.setUp();
        c = (ObjectConstructionFormController) ctx.getBean("objectConstructionFormController");
    }

    protected void tearDown() {
        c = null;
    }

    public void testEdit() throws Exception {
        log.debug("testing edit...");
        request = newGet("/editObjectConstruction.html");
        request.addParameter("typeId", "1");

        mv = c.handleRequest(request, new MockHttpServletResponse());

        assertEquals("objectConstructionForm", mv.getViewName());
    }

    public void testSave() throws Exception {
        request = newGet("/editObjectConstruction.html");
        request.addParameter("typeId", "1");

        mv = c.handleRequest(request, new MockHttpServletResponse());

        ObjectConstruction objectConstruction = (ObjectConstruction) mv.getModel().get(c.getCommandName());
        assertNotNull(objectConstruction);
        request = newPost("/editObjectConstruction.html");
        super.objectToRequestParameters(objectConstruction, 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 + "objectConstruction");

        if (errors != null) {
            log.debug(errors);
        }
        assertNull(errors);
        assertNotNull(request.getSession().getAttribute("successMessages"));       
    }

    public void testRemove() throws Exception {
        request = newPost("/editObjectConstruction.html");
        request.addParameter("delete", "");
        request.addParameter("typeId", "2");
        mv = c.handleRequest(request, new MockHttpServletResponse());
        assertNotNull(request.getSession().getAttribute("successMessages"));
    }
}
TOP

Related Classes of com.vst.webapp.action.ObjectConstructionFormControllerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.