|
|
@ -65,7 +65,7 @@ public class DefaultResponseErrorHandlerTests { |
|
|
|
given(response.getRawStatusCode()).willReturn(HttpStatus.NOT_FOUND.value()); |
|
|
|
given(response.getRawStatusCode()).willReturn(HttpStatus.NOT_FOUND.value()); |
|
|
|
given(response.getStatusText()).willReturn("Not Found"); |
|
|
|
given(response.getStatusText()).willReturn("Not Found"); |
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
given(response.getBody()).willReturn(new ByteArrayInputStream("Hello World".getBytes("UTF-8"))); |
|
|
|
given(response.getBody()).willReturn(new ByteArrayInputStream("Hello World".getBytes(StandardCharsets.UTF_8))); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
handler.handleError(response); |
|
|
|
handler.handleError(response); |
|
|
@ -101,8 +101,20 @@ public class DefaultResponseErrorHandlerTests { |
|
|
|
handler.handleError(response); |
|
|
|
handler.handleError(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-16108
|
|
|
|
|
|
|
|
public void hasErrorForUnknownStatusCode() throws Exception { |
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
given(response.getRawStatusCode()).willReturn(999); |
|
|
|
|
|
|
|
given(response.getStatusText()).willReturn("Custom status code"); |
|
|
|
|
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(handler.hasError(response)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = UnknownHttpStatusCodeException.class) // SPR-9406
|
|
|
|
@Test(expected = UnknownHttpStatusCodeException.class) // SPR-9406
|
|
|
|
public void unknownStatusCode() throws Exception { |
|
|
|
public void handleErrorUnknownStatusCode() throws Exception { |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
|
|
|
|
|
|
|
@ -113,16 +125,52 @@ public class DefaultResponseErrorHandlerTests { |
|
|
|
handler.handleError(response); |
|
|
|
handler.handleError(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-16108
|
|
|
|
@Test // SPR-17461
|
|
|
|
public void hasErrorForUnknownStatusCode() throws Exception { |
|
|
|
public void hasErrorForCustomClientError() throws Exception { |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
|
|
|
|
|
|
|
|
given(response.getRawStatusCode()).willReturn(999); |
|
|
|
given(response.getRawStatusCode()).willReturn(499); |
|
|
|
given(response.getStatusText()).willReturn("Custom status code"); |
|
|
|
given(response.getStatusText()).willReturn("Custom status code"); |
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
|
|
|
|
|
|
|
|
assertFalse(handler.hasError(response)); |
|
|
|
assertTrue(handler.hasError(response)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = UnknownHttpStatusCodeException.class) |
|
|
|
|
|
|
|
public void handleErrorForCustomClientError() throws Exception { |
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
given(response.getRawStatusCode()).willReturn(499); |
|
|
|
|
|
|
|
given(response.getStatusText()).willReturn("Custom status code"); |
|
|
|
|
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler.handleError(response); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-17461
|
|
|
|
|
|
|
|
public void hasErrorForCustomServerError() throws Exception { |
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
given(response.getRawStatusCode()).willReturn(599); |
|
|
|
|
|
|
|
given(response.getStatusText()).willReturn("Custom status code"); |
|
|
|
|
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(handler.hasError(response)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = UnknownHttpStatusCodeException.class) |
|
|
|
|
|
|
|
public void handleErrorForCustomServerError() throws Exception { |
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
|
|
headers.setContentType(MediaType.TEXT_PLAIN); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
given(response.getRawStatusCode()).willReturn(599); |
|
|
|
|
|
|
|
given(response.getStatusText()).willReturn("Custom status code"); |
|
|
|
|
|
|
|
given(response.getHeaders()).willReturn(headers); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler.handleError(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-16604
|
|
|
|
@Test // SPR-16604
|
|
|
|