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:org.openmrs.contrib.metadatarepository.webapp.controller.PackageFormControllerTest.java

@Test
public void testSave() throws Exception {
    request = newGet("/packageform");
    request.addParameter("id", "1");
    pkg = form.showForm(1L);/*from w  w  w.  ja v  a2s .  co  m*/
    assertNotNull(pkg);

    request = newPost("/packageform");

    request.setRemoteUser("admin");
    pkg = form.showForm(1L);
    // update required fields

    BindingResult errors = new DataBinder(pkg).getBindingResult();
    form.onSubmit(pkg, errors, request, new MockHttpServletResponse(), new ModelMap());
    assertFalse(errors.hasErrors());
    assertNotNull(request.getSession().getAttribute("successMessages"));
}

From source file:org.openmrs.module.clinicalsummary.web.service.PatientSearchControllerTest.java

/**
 * @verifies should return patients with name search term
 * @see org.openmrs.module.clinicalsummary.web.controller.service.PatientSearchController#searchPatient(String, String, String, javax.servlet.http.HttpServletResponse)
 *///  w w  w .j a  v  a2s .  c o m
@Test
public void searchPatient_shouldReturnPatientsWithNameSearchTerm() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/module/clinicalsummary/service/patient/search");
    request.setParameter("term", "Collet");
    request.setParameter("username", "admin");
    request.setParameter("password", "test");

    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerAdapter handlerAdapter = new AnnotationMethodHandlerAdapter();
    handlerAdapter.handle(request, response, controller);

    Assert.assertTrue(StringUtils.isNotEmpty(response.getContentAsString()));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "Collet Test Chebaskwony"));
    Assert.assertTrue(StringUtils.contains(response.getContentAsString(), "6TS-4"));
}

From source file:org.openmrs.contrib.metadatarepository.webapp.controller.UserFormControllerTest.java

@Test
public void testAddWithoutPermission() throws Exception {
    log.debug("testing add new user...");
    request = newGet("/userform.html");
    request.addParameter("method", "Add");

    try {//w w w. j a va2 s.c  om
        c.showForm(request, new MockHttpServletResponse());
        fail("AccessDeniedException not thrown...");
    } catch (AccessDeniedException ade) {
        assertNotNull(ade.getMessage());
    }
}

From source file:nl.surfnet.coin.selfservice.filter.SabEntitlementsFilterTest.java

@Before
public void setUp() throws Exception {
    filter = new SabEntitlementsFilter();

    filter.setAdminSurfConextIdPRole(ROLE_DASHBOARD_ADMIN.name());
    filter.setViewerSurfConextIdPRole(ROLE_DASHBOARD_VIEWER.name());

    MockitoAnnotations.initMocks(this);

    request = new MockHttpServletRequest("GET", "/anyUrl");
    response = new MockHttpServletResponse();

    SecurityContextHolder.getContext().setAuthentication(null);

}

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);//ww  w . j a v a2s  .c  o  m
}

From source file:org.craftercms.security.processors.impl.UrlAccessRestrictionCheckingProcessorTest.java

@Test
public void testAllowedAccess() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", URL);
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response);
    RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class);

    Profile profile = new Profile();
    profile.setRoles(SetUtils.asSet(ADMIN_ROLE));

    SecurityUtils.setAuthentication(request, new DefaultAuthentication(new ObjectId().toString(), profile));

    processor.processRequest(context, chain);

    verify(chain).processRequest(context);
}

From source file:fragment.web.LogoControllerTest.java

@Test
public void testGetTenantLogo() {

    logoController.getTenantLogo("a667305a-1345-46bc-83d4-a6f3adcf33aa", map, response);
    checkCorrectnessForNullPath();/*from  w w w .java  2 s. co  m*/

    response = new MockHttpServletResponse();
    logoController.getTenantLogo("dfc84388-d44d-4d8e-9d6a-a62c1c16b7e4", map, response);
    checkCorrectnessOfMethod(response);
}

From source file:git.irbis.spring3.controllerusageexample.customers.web.ListCustomersControllerTest.java

/**
 * Test of request: show all customers./*from   w ww  . j  av  a 2s  .c o m*/
 */
@Test
public void testListCustomers() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    ListCustomersController listCustomersController = new ListCustomersController(
            new CustomerRepositoryMockImpl());
    request.setMethod("GET");
    request.setRequestURI("/listcustomers");

    try {
        ModelAndView mv = new AnnotationMethodHandlerAdapter().handle(request, response,
                listCustomersController);

        ModelAndViewAssert.assertViewName(mv, "listcustomers");
        List<Customer> customers = (List<Customer>) mv.getModel().get("customers");

        assertNotNull(customers);
        assertEquals(5, customers.size());
    } catch (Exception ex) {
        fail();
    }
}

From source file:cherry.foundation.download.TableDownloadTemplateTest.java

@Test
public void testDownloadCsvNoHeader() throws IOException {
    // //w  w w .jav a  2s.c  o m
    MockHttpServletResponse response = new MockHttpServletResponse();
    // 
    tableDownloadOperation.downloadCsv(response, StandardCharsets.UTF_8, "test_{0}.csv",
            new LocalDateTime(2015, 1, 23, 12, 34, 56), null, createCommonClause(), createOrderByClause(),
            constant("TEST00"));
    // 
    assertEquals("text/csv", response.getContentType());
    assertEquals("UTF-8", response.getCharacterEncoding());
    assertEquals("text/csv;charset=UTF-8", response.getHeader("Content-Type"));
    assertEquals("attachment; filename=\"test_20150123123456.csv\"", response.getHeader("Content-Disposition"));
    assertEquals("\"TEST00\"\r\n", response.getContentAsString());
}

From source file:de.otto.jsonhome.registry.controller.RegistryJsonHomeControllerTest.java

@Test
public void shouldReturnJsonHome() throws IOException {
    // given:/*  w  w w .jav a2 s. c om*/
    final RegistryJsonHomeController jsonHomeController = new RegistryJsonHomeController();
    jsonHomeController.setRegistryJsonHomeSource(getJsonHomeSource());
    registriesController.putRegistry("test", registryLiveWithSingleLinkTo("foo"),
            new MockHttpServletResponse());
    // when:
    final Map<String, ?> json = jsonHomeController.getAsApplicationJson("test", new MockHttpServletResponse());
    // then:
    assertNotNull(json);
    assertTrue(json.containsKey("resources"));
    final Object resources = getFrom(json, "resources");
    assertEquals(((Map) resources).size(), 1);
    final Object resource = getFrom(resources, "http://example.org/rel/foo");
    assertNotNull(resource);
    final Object href = getFrom(resource, "href");
    assertEquals(href, "http://example.org/fooResource");
}