Package com.vst.webapp.action

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

package com.vst.webapp.action;

import com.vst.model.QuestionType;
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 QuestionTypeFormControllerTest extends BaseControllerTestCase {
    private QuestionTypeFormController c;
    private MockHttpServletRequest request;
    private ModelAndView mv;

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

    protected void tearDown() {
        c = null;
    }

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

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

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

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

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

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

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

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

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

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.