Example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse.

Prototype

MockHttpServletResponse

Source Link

Usage

From source file:com.amashchenko.struts2.actionflow.ActionFlowAwareTest.java

/** Initializes servlet mock objects but preserves session. */
private void initServletMockObjectsPreserveSession() {
    servletContext = new MockServletContext(resourceLoader);
    response = new MockHttpServletResponse();

    // preserve session
    HttpSession session = null;//  ww  w.j  a  va  2s  . c  o m
    if (request != null && request.getSession() != null) {
        session = request.getSession();
    }
    request = new MockHttpServletRequest();
    request.setSession(session);

    pageContext = new MockPageContext(servletContext, request, response);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.ConceptDatatypeControllerTest.java

@Before
public void before() {
    this.service = Context.getConceptService();
    this.controller = new ConceptDatatypeController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
}

From source file:ch.rasc.extclassgenerator.ModelGeneratorBeanWithGenericValidationTest.java

@Test
public void testWriteModelHttpServletRequestHttpServletResponseClassOfQOutputFormatBoolean()
        throws IOException {
    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithGenericValidation.class,
            OutputFormat.EXTJS4, IncludeValidation.ALL, true);
    GeneratorTestUtil.compareExtJs4Code("BeanWithGenericValidation", response.getContentAsString(), true,
            false);//from ww w .j  a  va 2 s.  co  m

    response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithGenericValidation.class,
            OutputFormat.TOUCH2, IncludeValidation.ALL, false);
    GeneratorTestUtil.compareTouch2Code("BeanWithGenericValidation", response.getContentAsString(), false,
            false);

    response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithGenericValidation.class,
            OutputFormat.EXTJS4, IncludeValidation.ALL, true);
    GeneratorTestUtil.compareExtJs4Code("BeanWithGenericValidation", response.getContentAsString(), true,
            false);

    response = new MockHttpServletResponse();
    ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithGenericValidation.class,
            OutputFormat.TOUCH2, IncludeValidation.ALL, true);
    GeneratorTestUtil.compareTouch2Code("BeanWithGenericValidation", response.getContentAsString(), true,
            false);
}

From source file:com.cognicap.site.web.controllers.ReservationControllerTest.java

@Test
public void testSubmitForm() {

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("GET");

    ModelAndView mav = null;// w  ww.  ja  v a 2s .c  o  m
    try {
        mav = controller.onSubmit(request, response, registration, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    LOGGER.debug(mav.getViewName());
    assertEquals("confirmationReception", mav.getViewName());
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.PersonAttributeControllerTest.java

@Before
public void before() throws Exception {
    this.service = Context.getPersonService();
    this.controller = new PersonAttributeController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
}

From source file:org.openmrs.web.controller.patient.PatientIdentifierTypeFormControllerTest.java

@Before
public void setup() throws Exception {
    executeDataSet("org/openmrs/web/patient/include/PatientIdentifierTypeFormControllerTest.xml");
    controller = (PatientIdentifierTypeFormController) applicationContext.getBean("patientIdentifierTypeForm");
    controller.setFormView("index.htm");
    controller.setSuccessView("patientIdentifierType.form");

    request = new MockHttpServletRequest("POST",
            "/admin/patients/patientIdentifierType.form?patientIdentifierTypeId=1");
    request.setSession(new MockHttpSession(null));
    request.setContentType("application/x-www-form-urlencoded");
    request.addParameter("name", "TRUNK");
    response = new MockHttpServletResponse();
}

From source file:nl.dtls.fairdatapoint.api.controller.DataAccessorControllerTest.java

/**
 * Check unsupported accept header./*from   w w w .  j av  a2 s  .c  om*/
 * 
 * @throws Exception 
 */
@Test(expected = Exception.class)
public void unsupportedAcceptHeader() throws Exception {
    MockHttpServletRequest request;
    MockHttpServletResponse response;
    Object handler;

    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    request.setMethod("GET");
    request.addHeader(HttpHeaders.ACCEPT, "application/trig");
    request.setRequestURI("/textmining/gene-disease-association_lumc/sparql");
    handler = handlerMapping.getHandler(request).getHandler();
    handlerAdapter.handle(request, response, handler);
    assertEquals(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, response.getStatus());
}

From source file:org.openmrs.module.webservices.rest19ext.web.v1_0.controller.VisitTypeControllerTest.java

@Before
public void before() {
    this.service = Context.getVisitService();
    this.controller = new VisitTypeController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
}

From source file:net.shibboleth.idp.cas.flow.AbstractFlowTest.java

/**
 * Initialize HTTP request, response, and flow context.
 *///from   w w  w  .  j a  v  a  2 s .  c  o  m
@BeforeMethod
public void initialize() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    externalContext = new MockExternalContext();
    externalContext.setNativeRequest(request);
    externalContext.setNativeResponse(response);
    HttpServletRequestResponseContext.loadCurrent(request, response);
}

From source file:org.araneaframework.tests.framework.router.StandardTopServiceRouterServiceTests.java

public void setUp() throws Exception {
    service = new StandardTopServiceRouterService();
    map = new HashMap();

    child1 = new MockEventfulStandardService();
    child2 = new MockEventfulStandardService();

    req = new MockHttpServletRequest();
    res = new MockHttpServletResponse();

    input = new StandardServletInputData(req);
    output = new StandardServletOutputData(req, res);

    map.put("child1", child1);
    map.put("child2", child2);

    service.setServiceMap(map);/*from  w  ww . j  a  v  a 2  s.com*/
    service._getComponent().init(MockUtil.getEnv());

    service.setDefaultServiceId("child1");
}