Add convention based status error pages

Update `spring-boot-sample-web-mustache` to show how convention based
status error pages can be used.

See gh-2691
This commit is contained in:
Phillip Webb
2016-04-29 10:43:10 -07:00
parent 0bf025af7b
commit 6d069de79f
5 changed files with 91 additions and 3 deletions

View File

@@ -63,14 +63,48 @@ public class SampleWebMustacheApplicationTests {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> responseEntity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET,
requestEntity, String.class);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(responseEntity.getBody())
.contains("Something went wrong: 404 Not Found");
}
@Test
public void test503HtmlResource() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/serviceUnavailable", HttpMethod.GET,
requestEntity, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
assertThat(entity.getBody()).contains("I'm a 503");
}
@Test
public void test5xxHtmlResource() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/bang", HttpMethod.GET, requestEntity,
String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(entity.getBody()).contains("I'm a 5xx");
}
@Test
public void test507Template() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/insufficientStorage", HttpMethod.GET,
requestEntity, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INSUFFICIENT_STORAGE);
assertThat(entity.getBody()).contains("I'm a 507");
}
}