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

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

Introduction

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

Prototype

@Override
    public int getStatus() 

Source Link

Usage

From source file:com.vmware.identity.openidconnect.server.LoginTest.java

private static void assertErrorResponseUsingPersonUserCert(String certHeader, Object certAttribute,
        Cookie cookie, String expectedError) throws Exception {
    Pair<ModelAndView, MockHttpServletResponse> result = doRequestUsingPersonUserCert(certHeader, certAttribute,
            cookie);//from w  w w.  j av  a2 s .c om
    ModelAndView modelView = result.getLeft();
    MockHttpServletResponse response = result.getRight();

    Assert.assertNull("modelView", modelView);
    Assert.assertNull("sessionCookie", response.getCookie(SESSION_COOKIE_NAME));
    Assert.assertEquals("status", 401, response.getStatus());
    Assert.assertNotNull("errorResponseHeader", response.getHeader("CastleError"));
    Assert.assertEquals("errorMessage", expectedError, response.getErrorMessage());
}

From source file:com.vmware.identity.openidconnect.server.LoginTest.java

private static void assertErrorResponse(String loginString, String authzHeader, String expectedError,
        String expectedAuthzResponseHeader, String expectedAuthenticateHeader, CasIdmClient idmClient)
        throws Exception {
    Pair<ModelAndView, MockHttpServletResponse> result = doRequest(loginString, authzHeader,
            null /* sessionCookie */, idmClient);
    ModelAndView modelView = result.getLeft();
    MockHttpServletResponse response = result.getRight();
    Assert.assertNull("modelView", modelView);
    Assert.assertNull("sessionCookie", response.getCookie(SESSION_COOKIE_NAME));
    Assert.assertEquals("status", 401, response.getStatus());
    Object errorResponseHeader = response.getHeader("CastleError");
    Assert.assertNotNull("errorResponseHeader", errorResponseHeader);
    Assert.assertEquals("errorMessage", expectedError, response.getErrorMessage());

    if (expectedAuthzResponseHeader != null) {
        Object authzResponseHeader = response.getHeader("CastleAuthorization");
        Assert.assertNotNull("authzResponseHeader", authzResponseHeader);
        Assert.assertEquals("expectedAuthzResponseHeader", expectedAuthzResponseHeader,
                authzResponseHeader.toString());
    }/*  w  w  w  . jav a  2 s.  c om*/

    if (expectedAuthenticateHeader != null) {
        Object wwwAuthenticateHeader = response.getHeader("WWW-Authenticate");
        Assert.assertNotNull("wwwAuthenticateHeader", wwwAuthenticateHeader);
        Assert.assertEquals("expectedAuthenticateHeader", expectedAuthenticateHeader,
                wwwAuthenticateHeader.toString());
    }
}

From source file:com.thoughtworks.go.server.controller.actions.JsonActionTest.java

@Test
public void shouldReturnJsonConflictInNormalConflict() throws Exception {
    when(configValidity.isType(GoConfigValidity.VT_CONFLICT)).thenReturn(true);
    JsonAction action = JsonAction.jsonByValidity(jsonAware, configValidity);
    MockHttpServletResponse response = new MockHttpServletResponse();
    action.respond(response);//w  ww .j  a  v a  2  s  .  c o m
    assertThat(response.getStatus(), is(SC_CONFLICT));
    verify(configValidity).isType(GoConfigValidity.VT_CONFLICT);
}

From source file:com.thoughtworks.go.server.controller.actions.JsonActionTest.java

@Test
public void shouldReturnJsonConflictInCaseOfConfigMergeConflict() throws Exception {
    when(configValidity.isType(GoConfigValidity.VT_MERGE_OPERATION_ERROR)).thenReturn(true);
    JsonAction action = JsonAction.jsonByValidity(jsonAware, configValidity);
    MockHttpServletResponse response = new MockHttpServletResponse();
    action.respond(response);/*  w w w .j  a  v  a 2 s . c  o  m*/
    assertThat(response.getStatus(), is(SC_CONFLICT));
    verify(configValidity).isType(GoConfigValidity.VT_MERGE_OPERATION_ERROR);
}

From source file:com.thoughtworks.go.server.controller.actions.JsonActionTest.java

@Test
public void shouldReturnJsonConflictInCaseOfPostMergeValidationError() throws Exception {
    when(configValidity.isType(GoConfigValidity.VT_MERGE_POST_VALIDATION_ERROR)).thenReturn(true);
    JsonAction action = JsonAction.jsonByValidity(jsonAware, configValidity);
    MockHttpServletResponse response = new MockHttpServletResponse();
    action.respond(response);/*from   ww w  .ja  v  a 2  s. c  o m*/
    assertThat(response.getStatus(), is(SC_CONFLICT));
    verify(configValidity).isType(GoConfigValidity.VT_MERGE_POST_VALIDATION_ERROR);
}

From source file:com.thoughtworks.go.server.controller.actions.JsonActionTest.java

@Test
public void shouldReturnJsonConflictInCaseOfPreMergeValidationError() throws Exception {
    when(configValidity.isType(GoConfigValidity.VT_MERGE_PRE_VALIDATION_ERROR)).thenReturn(true);
    JsonAction action = JsonAction.jsonByValidity(jsonAware, configValidity);
    MockHttpServletResponse response = new MockHttpServletResponse();
    action.respond(response);/* w  w w  .  ja va2  s  . c om*/
    assertThat(response.getStatus(), is(SC_CONFLICT));
    verify(configValidity).isType(GoConfigValidity.VT_MERGE_PRE_VALIDATION_ERROR);
}

From source file:com.thoughtworks.go.server.functional.helpers.CSVResponse.java

public CSVResponse(MockHttpServletResponse response) throws UnsupportedEncodingException {
    this(response.getContentAsString(), response.getStatus(), response.getContentType());
}

From source file:de.codecentric.boot.admin.actuate.LogfileMvcEndpointTest.java

@Test
public void logfile_noProperty() throws IOException {
    assertEquals(HttpStatus.NOT_FOUND, controller.available().getStatusCode());

    MockHttpServletResponse response = new MockHttpServletResponse();
    controller.invoke(response);/*from   w w w.  j  a  va 2 s.c  o  m*/
    assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatus());
}

From source file:de.codecentric.boot.admin.actuate.LogfileMvcEndpointTest.java

@Test
public void logfile_noFile() throws IOException {
    controller.setLogfile("does_not_exist.log");

    assertEquals(HttpStatus.NOT_FOUND, controller.available().getStatusCode());

    MockHttpServletResponse response = new MockHttpServletResponse();
    controller.invoke(response);/*w ww . jav  a2s .  co  m*/
    assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatus());
}

From source file:de.codecentric.boot.admin.actuate.LogfileMvcEndpointTest.java

@Test
public void logfile() throws IOException {
    try {// w w w  .  j a  va  2s. c  o m
        FileCopyUtils.copy("--TEST--".getBytes(), new File("test.log"));
        controller.setLogfile("test.log");

        assertEquals(HttpStatus.OK, controller.available().getStatusCode());

        MockHttpServletResponse response = new MockHttpServletResponse();
        controller.invoke(response);
        assertEquals(HttpStatus.OK.value(), response.getStatus());
        assertEquals("--TEST--", response.getContentAsString());
    } finally {
        new File("test.log").delete();
    }
}