use of org.springframework.http.client.ClientHttpResponse in project spring-cloud-netflix by spring-cloud.
the class RibbonRoutingFilterTests method createClientHttpResponse.
private ClientHttpResponse createClientHttpResponse() {
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() throws IOException {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() throws IOException {
return 200;
}
@Override
public String getStatusText() throws IOException {
return "OK";
}
@Override
public void close() {
}
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream("OK".getBytes());
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return httpHeaders;
}
};
}
use of org.springframework.http.client.ClientHttpResponse in project spring-cloud-netflix by spring-cloud.
the class RibbonRoutingFilterTests method testSetResponseWithNonHttpStatusCode.
@Test
public void testSetResponseWithNonHttpStatusCode() throws Exception {
ClientHttpResponse response = this.createClientHttpResponseWithNonStatus();
this.filter.setResponse(response);
assertThat(517).isEqualTo(this.requestContext.get("responseStatusCode"));
}
use of org.springframework.http.client.ClientHttpResponse in project spring-cloud-netflix by spring-cloud.
the class RibbonCommandCauseFallbackPropagationTest method causeIsProvidedForNewInterface.
@Test
public void causeIsProvidedForNewInterface() throws Exception {
TestFallbackProvider provider = TestFallbackProvider.withResponse(HttpStatus.NOT_FOUND);
RuntimeException exception = new RuntimeException("Failed!");
TestRibbonCommand testCommand = new TestRibbonCommand(new TestClient(exception), provider, context);
ClientHttpResponse response = testCommand.execute();
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
Throwable cause = provider.getCause();
assertThat(cause.getClass()).isEqualTo(exception.getClass());
assertThat(cause.getMessage()).isEqualTo(exception.getMessage());
}
use of org.springframework.http.client.ClientHttpResponse in project spring-cloud-netflix by spring-cloud.
the class RibbonCommandCauseFallbackPropagationTest method timeoutExceptionIsPropagated.
@Test
public void timeoutExceptionIsPropagated() throws Exception {
TestFallbackProvider provider = TestFallbackProvider.withResponse(HttpStatus.CONFLICT);
RuntimeException exception = new RuntimeException("Failed!");
TestRibbonCommand testCommand = new TestRibbonCommand(new TestClient(exception), provider, 1, context) {
@Override
protected ClientRequest createRequest() throws Exception {
Thread.sleep(5);
return super.createRequest();
}
};
ClientHttpResponse response = testCommand.execute();
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CONFLICT);
assertThat(provider.getCause()).isNotNull();
assertThat(provider.getCause().getClass()).isEqualTo(HystrixTimeoutException.class);
}
use of org.springframework.http.client.ClientHttpResponse in project spring-cloud-netflix by spring-cloud.
the class RibbonCommandCauseFallbackPropagationTest method providerIsCalledInCaseOfException.
@Test
public void providerIsCalledInCaseOfException() throws Exception {
FallbackProvider provider = new TestFallbackProvider(getClientHttpResponse(HttpStatus.INTERNAL_SERVER_ERROR));
RuntimeException exception = new RuntimeException("Failed!");
TestRibbonCommand testCommand = new TestRibbonCommand(new TestClient(exception), provider, context);
ClientHttpResponse response = testCommand.execute();
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
Aggregations