Search in sources :

Example 11 with MockClientHttpResponse

use of org.springframework.mock.http.client.MockClientHttpResponse in project spring-framework by spring-projects.

the class ResponseCreatorsTests method withStatus.

@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());
}
Also used : MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse) Test(org.junit.Test)

Example 12 with MockClientHttpResponse

use of org.springframework.mock.http.client.MockClientHttpResponse in project spring-framework by spring-projects.

the class ResponseCreatorsTests method badRequest.

@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());
}
Also used : MockClientHttpResponse(org.springframework.mock.http.client.MockClientHttpResponse) Test(org.junit.Test)

Aggregations

MockClientHttpResponse (org.springframework.mock.http.client.MockClientHttpResponse)12 Test (org.junit.Test)9 URI (java.net.URI)2 MockClientHttpRequest (org.springframework.mock.http.client.MockClientHttpRequest)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CustomHttpComponentsClientHttpRequestFactory (org.springframework.boot.test.web.client.TestRestTemplate.CustomHttpComponentsClientHttpRequestFactory)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpStatus (org.springframework.http.HttpStatus)1 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)1 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)1 InterceptingClientHttpRequestFactory (org.springframework.http.client.InterceptingClientHttpRequestFactory)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1 RestTemplate (org.springframework.web.client.RestTemplate)1