|
|
|
@ -57,14 +57,14 @@ class ExtractingResponseErrorHandlerTests { |
|
|
|
HttpMessageConverter<Object> converter = new JacksonJsonHttpMessageConverter(); |
|
|
|
HttpMessageConverter<Object> converter = new JacksonJsonHttpMessageConverter(); |
|
|
|
this.errorHandler = new ExtractingResponseErrorHandler(List.of(converter)); |
|
|
|
this.errorHandler = new ExtractingResponseErrorHandler(List.of(converter)); |
|
|
|
|
|
|
|
|
|
|
|
this.errorHandler.setStatusMapping(Map.of(HttpStatus.I_AM_A_TEAPOT, MyRestClientException.class)); |
|
|
|
this.errorHandler.setStatusMapping(Map.of(HttpStatus.EXPECTATION_FAILED, MyRestClientException.class)); |
|
|
|
this.errorHandler.setSeriesMapping(Map.of(HttpStatus.Series.SERVER_ERROR, MyRestClientException.class)); |
|
|
|
this.errorHandler.setSeriesMapping(Map.of(HttpStatus.Series.SERVER_ERROR, MyRestClientException.class)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void hasError() throws Exception { |
|
|
|
void hasError() throws Exception { |
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT); |
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.EXPECTATION_FAILED); |
|
|
|
assertThat(this.errorHandler.hasError(this.response)).isTrue(); |
|
|
|
assertThat(this.errorHandler.hasError(this.response)).isTrue(); |
|
|
|
|
|
|
|
|
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR); |
|
|
|
@ -78,7 +78,7 @@ class ExtractingResponseErrorHandlerTests { |
|
|
|
void hasErrorOverride() throws Exception { |
|
|
|
void hasErrorOverride() throws Exception { |
|
|
|
this.errorHandler.setSeriesMapping(Collections.singletonMap(HttpStatus.Series.CLIENT_ERROR, null)); |
|
|
|
this.errorHandler.setSeriesMapping(Collections.singletonMap(HttpStatus.Series.CLIENT_ERROR, null)); |
|
|
|
|
|
|
|
|
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT); |
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.EXPECTATION_FAILED); |
|
|
|
assertThat(this.errorHandler.hasError(this.response)).isTrue(); |
|
|
|
assertThat(this.errorHandler.hasError(this.response)).isTrue(); |
|
|
|
|
|
|
|
|
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.NOT_FOUND); |
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.NOT_FOUND); |
|
|
|
@ -90,7 +90,7 @@ class ExtractingResponseErrorHandlerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void handleErrorStatusMatch() throws Exception { |
|
|
|
void handleErrorStatusMatch() throws Exception { |
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.I_AM_A_TEAPOT); |
|
|
|
given(this.response.getStatusCode()).willReturn(HttpStatus.EXPECTATION_FAILED); |
|
|
|
HttpHeaders responseHeaders = new HttpHeaders(); |
|
|
|
HttpHeaders responseHeaders = new HttpHeaders(); |
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_JSON); |
|
|
|
responseHeaders.setContentType(MediaType.APPLICATION_JSON); |
|
|
|
given(this.response.getHeaders()).willReturn(responseHeaders); |
|
|
|
given(this.response.getHeaders()).willReturn(responseHeaders); |
|
|
|
|