SPR-7591 - HttpStatusCodeException should contain response body

This commit is contained in:
Arjen Poutsma
2010-09-24 10:06:52 +00:00
parent 6e516b7281
commit 70cb81b4b5
5 changed files with 122 additions and 13 deletions

View File

@@ -145,14 +145,30 @@ public class RestTemplateIntegrationTests {
assertEquals("Invalid content", helloWorld, s);
}
@Test(expected = HttpClientErrorException.class)
@Test
public void notFound() {
template.execute(URI + "/errors/notfound", HttpMethod.GET, null, null);
try {
template.execute(URI + "/errors/notfound", HttpMethod.GET, null, null);
fail("HttpClientErrorException expected");
}
catch (HttpClientErrorException ex) {
assertEquals(HttpStatus.NOT_FOUND, ex.getStatusCode());
assertNotNull(ex.getStatusText());
assertNotNull(ex.getResponseBodyAsString());
}
}
@Test(expected = HttpServerErrorException.class)
@Test
public void serverError() {
template.execute(URI + "/errors/server", HttpMethod.GET, null, null);
try {
template.execute(URI + "/errors/server", HttpMethod.GET, null, null);
fail("HttpServerErrorException expected");
}
catch (HttpServerErrorException ex) {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, ex.getStatusCode());
assertNotNull(ex.getStatusText());
assertNotNull(ex.getResponseBodyAsString());
}
}
@Test