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

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

Introduction

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

Prototype

public MockHttpServletRequest() 

Source Link

Document

Create a new MockHttpServletRequest with a default MockServletContext .

Usage

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

@Before
public void before() throws Exception {
    this.service = Context.getHL7Service();
    this.controller = new HL7MessageController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    executeDataSet(datasetFilename);//from   w  ww  .  java  2s  .co  m
}

From source file:org.jasig.cas.services.web.ManageRegisteredServicesMultiActionControllerTests.java

public void testDeleteService() {
    final RegisteredServiceImpl r = new RegisteredServiceImpl();
    r.setId(1200);/*from  w  ww  . ja v  a 2 s. c  o  m*/
    r.setName("name");
    r.setServiceId("serviceId");
    r.setEvaluationOrder(1);

    this.servicesManager.save(r);

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("id", "1200");

    final ModelAndView modelAndView = this.controller.deleteRegisteredService(request,
            new MockHttpServletResponse());

    assertNotNull(modelAndView);
    assertNull(this.servicesManager.findServiceBy(1200));
    assertEquals("deleted", modelAndView.getModel().get("status"));
    assertEquals("name", modelAndView.getModelMap().get("serviceName"));
}

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

private MockHttpServletRequest emptyRequest() {
    return new MockHttpServletRequest();
}

From source file:org.openmrs.module.idgen.web.controller.IdentifierSourceControllerTest.java

@Test
public void exportIdentifiers_shouldReturnJson() throws Exception {
    Mockito.stub(iss.generateIdentifiers(Mockito.any(IdentifierSource.class), Mockito.any(Integer.class),
            Mockito.any(String.class))).toReturn(Arrays.asList("1", "2", "3"));

    SequentialIdentifierGenerator generator = new SequentialIdentifierGenerator();

    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    controller.exportIdentifiers(null, mockRequest, mockResponse, generator, 3, "Mirebalais", null, null);

    Assert.assertEquals("{\"identifiers\":[\"1\",\"2\",\"3\"]}", mockResponse.getContentAsString());
}

From source file:org.craftercms.security.authorization.impl.AccessDeniedHandlerImplTest.java

@Test
public void testSendError() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response);

    handler.handle(context, new AccessDeniedException(""));

    assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
    assertTrue(response.isCommitted());//from  ww w .j  a v  a  2 s.  c o m
}

From source file:org.jasig.cas.web.support.CookieRetrievingCookieGeneratorTests.java

public void testCookieAddWithoutRememberMe() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();

    this.g.addCookie(request, response, "test");

    final Cookie c = response.getCookie("test");
    assertEquals(5, c.getMaxAge());// w ww .j a  v a  2  s. c om
    assertEquals("test", c.getValue());
}

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

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

From source file:com.expedia.common.controller.WeatherControllerTest.java

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    handlerAdapter = applicationContext.getBean(HandlerAdapter.class);
}

From source file:com.google.api.server.spi.IoUtilTest.java

@Test
public void testGetRequestInputStream_emptyStream() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setContent(new byte[0]);
    request.addHeader("Content-Encoding", "gzip");
    InputStream stream = IoUtil.getRequestInputStream(request);
    assertThat(stream).isNotInstanceOf(GZIPInputStream.class);
    assertThat(IoUtil.readStream(stream)).isEqualTo("");
}

From source file:com.enonic.cms.framework.util.HttpServletRangeUtilTest.java

@Test
public void test_bad_symbols_in_range() throws Exception {
    final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    httpServletRequest.setMethod("GET");
    httpServletRequest.setPathInfo("/input.dat");
    httpServletRequest.addHeader(HttpHeaders.RANGE, "bytes=bad");

    final MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
    HttpServletRangeUtil.processRequest(httpServletRequest, mockHttpServletResponse, "input.dat",
            "application/pdf", INPUT_FILE, false);

    assertEquals("", mockHttpServletResponse.getContentAsString());

    assertEquals(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE, mockHttpServletResponse.getStatus());
}