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.jasig.cas.services.web.ManageRegisteredServicesMultiActionControllerTests.java

public void testDeleteService() {
    final RegisteredServiceImpl r = new RegisteredServiceImpl();
    r.setId(1200);//  ww w  .  j  ava 2s.  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.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationEntryPointTest.java

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    authenticationEntryPoint = new KeycloakAuthenticationEntryPoint(adapterDeploymentContext);
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    when(applicationContext.getBean(eq(AdapterDeploymentContext.class))).thenReturn(adapterDeploymentContext);
    when(adapterDeploymentContext.resolveDeployment(any(HttpFacade.class))).thenReturn(keycloakDeployment);
    when(keycloakDeployment.isBearerOnly()).thenReturn(Boolean.FALSE);
}

From source file:org.esupportail.dining.web.controllers.WebWidgetController.java

private String renderView(HttpServletRequest request, String viewName, Model model) throws Exception {
    View resolvedView = viewResolver.resolveViewName(viewName, Locale.US);
    MockHttpServletResponse mockResp = new MockHttpServletResponse();
    resolvedView.render(model.asMap(), request, mockResp);
    return mockResp.getContentAsString();
}

From source file:org.openmrs.module.feedback.web.AddFeedbackFormControllerTest.java

@Before
public void setUp() throws Exception {

    /* executed before the test is run */
    this.service = Context.getService(FeedbackService.class);
    this.controller = new FeedbackAdminListController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();

    /* this file is in the same folder of test resources where the hibernate mapping file is located */
    initializeInMemoryDatabase();/*from  w ww  .  j  a  v  a  2s  .  c  o  m*/
    executeDataSet("FeedbackDataset.xml");

    /* Sample data is loaded into the system */
    authenticate();
}

From source file:org.jasig.cas.web.view.Cas10ResponseViewTests.java

public void testFailureView() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    this.view.setSuccessResponse(false);
    this.view.render(this.model, new MockHttpServletRequest(), response);
    assertEquals("no\n\n", response.getContentAsString());
}

From source file:com.ge.predix.acs.commons.web.RestErrorHandlerTest.java

@Test
public void testIllegalArgumentException() {
    RestErrorHandler errorHandler = new RestErrorHandler();

    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    Exception e = new IllegalArgumentException("Descriptive Error Message");

    ModelAndView errorResponse = errorHandler.createApiErrorResponse(e, request, response);

    // The default error status code for IllegalArgumentException is 400
    Assert.assertEquals(response.getStatus(), HttpStatus.BAD_REQUEST.value());

    Assert.assertNotNull(errorResponse);
    Assert.assertNotNull(errorResponse.getModel().get("ErrorDetails"));

    // Response payload with default error code and the
    // IllegalArgumentException's message
    assertRestApiErrorResponse(errorResponse, "FAILED", "Descriptive Error Message");
}

From source file:ch.silviowangler.dox.web.DocumentControllerTest.java

@Test
public void getTheDocumentContent()
        throws DocumentNotFoundException, DocumentNotInStoreException, UnsupportedEncodingException {

    MockHttpServletResponse response = new MockHttpServletResponse();

    PhysicalDocument physicalDocument = new PhysicalDocument(new DocumentClass("hhh"), "hello".getBytes(), null,
            "hello.txt");
    physicalDocument.setMimeType("aaa/bbb");
    when(documentService.findPhysicalDocument(1L)).thenReturn(physicalDocument);

    controller.getDocument(1L, response);

    assertThat(response.getStatus(), is(SC_OK));
    assertThat(response.getContentAsString(), is("hello"));
    assertThat(response.getContentType(), is("aaa/bbb"));
    assertThat(response.getHeader("Content-Disposition"), is("inline; filename=\"hello.txt\""));
}

From source file:com.mtt.myapp.home.controller.HomeControllerTest.java

@Test
public void testHealthCheck() {
    MockHttpServletResponse res = new MockHttpServletResponse();
    homeController.healthCheck(res);/*from w w w.  j av  a2 s . co  m*/
    HttpEntity<String> message = homeController.healthCheckSlowly(500, res);
    assertThat(message.getBody()).contains("NONE");
}

From source file:com.test.spring.SpringHelloBenchmark.java

@Setup(Level.Iteration)
public void request() throws Exception {
    request = new MockHttpServletRequest("GET", "/hello");
    response = new MockHttpServletResponse();
}

From source file:org.ngrinder.home.controller.HomeControllerTest.java

@Test
public void testHealthCheck() {
    MockHttpServletResponse res = new MockHttpServletResponse();
    homeController.healthCheck(res);/*from  w  ww. j a v  a2 s  .co  m*/
    HttpEntity<String> message = homeController.healthCheckSlowly(500, res);
    assertThat(message.getBody(), containsString("NONE"));
}