Package org.springframework.mock.http.client

Examples of org.springframework.mock.http.client.MockClientHttpResponse


*/
public class ResponseCreatorsTests {

  @Test
  public void success() throws Exception {
    MockClientHttpResponse response = (MockClientHttpResponse) MockRestResponseCreators.withSuccess().createResponse(null);

    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue(response.getHeaders().isEmpty());
    assertNull(response.getBody());
  }
View Full Code Here


  }

  @Test
  public void successWithContent() throws Exception {
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withSuccess("foo", MediaType.TEXT_PLAIN);
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertEquals(MediaType.TEXT_PLAIN, response.getHeaders().getContentType());
    assertArrayEquals("foo".getBytes(), FileCopyUtils.copyToByteArray(response.getBody()));
  }
View Full Code Here

  }

  @Test
  public void successWithContentWithoutContentType() throws Exception {
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withSuccess("foo", null);
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertNull(response.getHeaders().getContentType());
    assertArrayEquals("foo".getBytes(), FileCopyUtils.copyToByteArray(response.getBody()));
  }
View Full Code Here

  @Test
  public void created() throws Exception {
    URI location = new URI("/foo");
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withCreatedEntity(location);
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.CREATED, response.getStatusCode());
    assertEquals(location, response.getHeaders().getLocation());
    assertNull(response.getBody());
  }
View Full Code Here

  }

  @Test
  public void noContent() throws Exception {
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withNoContent();
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
    assertTrue(response.getHeaders().isEmpty());
    assertNull(response.getBody());
  }
View Full Code Here

  }

  @Test
  public void badRequest() throws Exception {
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withBadRequest();
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
    assertTrue(response.getHeaders().isEmpty());
    assertNull(response.getBody());
  }
View Full Code Here

  }

  @Test
  public void unauthorized() throws Exception {
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withUnauthorizedRequest();
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
    assertTrue(response.getHeaders().isEmpty());
    assertNull(response.getBody());
  }
View Full Code Here

  }

  @Test
  public void serverError() throws Exception {
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withServerError();
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
    assertTrue(response.getHeaders().isEmpty());
    assertNull(response.getBody());
  }
View Full Code Here

  }

  @Test
  public void withStatus() throws Exception {
    DefaultResponseCreator responseCreator = MockRestResponseCreators.withStatus(HttpStatus.FORBIDDEN);
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

    assertEquals(HttpStatus.FORBIDDEN, response.getStatusCode());
    assertTrue(response.getHeaders().isEmpty());
    assertNull(response.getBody());
  }
View Full Code Here

TOP

Related Classes of org.springframework.mock.http.client.MockClientHttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.