Package org.springframework.mock.http.client

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


  }

  @Test
  public void unauthorized() throws Exception {
    DefaultResponseCreator responseCreator = ResponseCreators.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 = ResponseCreators.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 = ResponseCreators.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

*/
public class ResponseCreatorsTests {

  @Test
  public void success() throws Exception {
    MockClientHttpResponse response = (MockClientHttpResponse) ResponseCreators.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 = ResponseCreators.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 = ResponseCreators.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 = ResponseCreators.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 = ResponseCreators.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 = ResponseCreators.withBadRequest();
    MockClientHttpResponse response = (MockClientHttpResponse) responseCreator.createResponse(null);

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

    Assert.notNull(statusCode);
    this.statusCode = statusCode;
  }

  public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException {
    MockClientHttpResponse response;
    if (this.contentResource != null ){
      InputStream stream = this.contentResource.getInputStream();
      response = new MockClientHttpResponse(stream, this.statusCode);
    }
    else {
      response = new MockClientHttpResponse(this.content, this.statusCode);
    }
    response.getHeaders().putAll(this.headers);
    return response;
  }
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.