|
|
|
@ -49,64 +49,50 @@ public class SampleTomcatDeployApplicationIT {
|
|
|
|
|
public void testHealth() throws Exception {
|
|
|
|
|
String url = "http://localhost:" + this.port + "/bootapp/actuator/health";
|
|
|
|
|
System.out.println(url);
|
|
|
|
|
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url,
|
|
|
|
|
String.class);
|
|
|
|
|
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(url, String.class);
|
|
|
|
|
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
|
|
|
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse()
|
|
|
|
|
throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.ALL,
|
|
|
|
|
MediaType.APPLICATION_JSON);
|
|
|
|
|
public void errorFromExceptionForRequestAcceptingAnythingProducesAJsonResponse() throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.ALL, MediaType.APPLICATION_JSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse()
|
|
|
|
|
throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/exception",
|
|
|
|
|
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
|
|
|
|
|
public void errorFromExceptionForRequestAcceptingJsonProducesAJsonResponse() throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.APPLICATION_JSON,
|
|
|
|
|
MediaType.APPLICATION_JSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse()
|
|
|
|
|
throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.TEXT_HTML,
|
|
|
|
|
MediaType.TEXT_HTML);
|
|
|
|
|
public void errorFromExceptionForRequestAcceptingHtmlProducesAnHtmlResponse() throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/exception", MediaType.TEXT_HTML, MediaType.TEXT_HTML);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void sendErrorForRequestAcceptingAnythingProducesAJsonResponse()
|
|
|
|
|
throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.ALL,
|
|
|
|
|
MediaType.APPLICATION_JSON);
|
|
|
|
|
public void sendErrorForRequestAcceptingAnythingProducesAJsonResponse() throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.ALL, MediaType.APPLICATION_JSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void sendErrorForRequestAcceptingJsonProducesAJsonResponse() throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/send-error",
|
|
|
|
|
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.APPLICATION_JSON,
|
|
|
|
|
MediaType.APPLICATION_JSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse()
|
|
|
|
|
throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.TEXT_HTML,
|
|
|
|
|
MediaType.TEXT_HTML);
|
|
|
|
|
public void sendErrorForRequestAcceptingHtmlProducesAnHtmlResponse() throws Exception {
|
|
|
|
|
assertThatPathProducesExpectedResponse("/bootapp/send-error", MediaType.TEXT_HTML, MediaType.TEXT_HTML);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void assertThatPathProducesExpectedResponse(String path, MediaType accept,
|
|
|
|
|
MediaType contentType) {
|
|
|
|
|
RequestEntity<Void> request = RequestEntity
|
|
|
|
|
.get(URI.create("http://localhost:" + this.port + path)).accept(accept)
|
|
|
|
|
.build();
|
|
|
|
|
private void assertThatPathProducesExpectedResponse(String path, MediaType accept, MediaType contentType) {
|
|
|
|
|
RequestEntity<Void> request = RequestEntity.get(URI.create("http://localhost:" + this.port + path))
|
|
|
|
|
.accept(accept).build();
|
|
|
|
|
ResponseEntity<String> response = this.rest.exchange(request, String.class);
|
|
|
|
|
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
assertThat(contentType.isCompatibleWith(response.getHeaders().getContentType()))
|
|
|
|
|
.as("%s is compatible with %s", contentType,
|
|
|
|
|
response.getHeaders().getContentType())
|
|
|
|
|
.isTrue();
|
|
|
|
|
.as("%s is compatible with %s", contentType, response.getHeaders().getContentType()).isTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|