pull/18349/head
Phillip Webb 5 years ago
parent 323a78c4b9
commit f1ec810caf

@ -44,11 +44,9 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
@Test @Test
void testCustomErrorPath() { void testCustomErrorPath() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/oops", this.restTemplate.withBasicAuth("user", "password").getForEntity("/oops", Map.class));
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertThat(body.get("error")).isEqualTo("None"); assertThat(body.get("error")).isEqualTo("None");
assertThat(body.get("status")).isEqualTo(999); assertThat(body.get("status")).isEqualTo(999);
@ -56,15 +54,16 @@ class EndpointsPropertiesSampleActuatorApplicationTests {
@Test @Test
void testCustomContextPath() { void testCustomContextPath() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.getForEntity("/admin/health", String.class); .getForEntity("/admin/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\""); assertThat(entity.getBody()).contains("\"status\":\"UP\"");
assertThat(entity.getBody()).contains("\"hello\":\"world\""); assertThat(entity.getBody()).contains("\"hello\":\"world\"");
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -47,21 +47,22 @@ class ManagementAddressActuatorApplicationTests {
@Test @Test
void testHome() { void testHome() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class); new TestRestTemplate().getForEntity("http://localhost:" + this.port, Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
void testHealth() { void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class); .getForEntity("http://localhost:" + this.managementPort + "/admin/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\""); assertThat(entity.getBody()).contains("\"status\":\"UP\"");
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -41,14 +41,10 @@ class ManagementDifferentPortSampleActuatorApplicationTests {
@Test @Test
void linksEndpointShouldBeAvailable() { void linksEndpointShouldBeAvailable() {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/", String.class); .getForEntity("http://localhost:" + this.managementPort + "/", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"_links\""); assertThat(entity.getBody()).contains("\"_links\"");
} }
private String getPassword() {
return "password";
}
} }

@ -43,7 +43,7 @@ class ManagementPathSampleActuatorApplicationTests {
@Test @Test
void testHealth() { void testHealth() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.getForEntity("/admin/health", String.class); .getForEntity("/admin/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\""); assertThat(entity.getBody()).contains("\"status\":\"UP\"");
@ -51,17 +51,15 @@ class ManagementPathSampleActuatorApplicationTests {
@Test @Test
void testHomeIsSecure() { void testHomeIsSecure() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class));
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("error")).isEqualTo("Unauthorized");
Map<String, Object> body = entity.getBody();
assertThat(body.get("error")).isEqualTo("Unauthorized");
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -52,27 +52,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
@Test @Test
void testHome() { void testHome() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) new TestRestTemplate("user", "password").getForEntity("http://localhost:" + this.port, Map.class));
.getForEntity("http://localhost:" + this.port, Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
Map<String, Object> body = entity.getBody();
assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
void testMetrics() { void testMetrics() {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate()
ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
void testHealth() { void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class); .getForEntity("http://localhost:" + this.managementPort + "/admin/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\",\"groups\":[\"live\",\"ready\"]}"); assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\",\"groups\":[\"live\",\"ready\"]}");
@ -82,14 +78,14 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
void testEnvNotFound() { void testEnvNotFound() {
String unknownProperty = "test-does-not-exist"; String unknownProperty = "test-does-not-exist";
assertThat(this.environment.containsProperty(unknownProperty)).isFalse(); assertThat(this.environment.containsProperty(unknownProperty)).isFalse();
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()).getForEntity( ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password").getForEntity(
"http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class); "http://localhost:" + this.managementPort + "/admin/env/" + unknownProperty, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
} }
@Test @Test
void testMissing() { void testMissing() {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class); .getForEntity("http://localhost:" + this.managementPort + "/admin/missing", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertThat(entity.getBody()).contains("\"status\":404"); assertThat(entity.getBody()).contains("\"status\":404");
@ -97,28 +93,23 @@ class ManagementPortAndPathSampleActuatorApplicationTests {
@Test @Test
void testErrorPage() { void testErrorPage() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/error", Map.class));
.getForEntity("http://localhost:" + this.port + "/error", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("status")).isEqualTo(999);
Map<String, Object> body = entity.getBody();
assertThat(body.get("status")).isEqualTo(999);
} }
@Test @Test
void testManagementErrorPage() { void testManagementErrorPage() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("status")).isEqualTo(999);
Map<String, Object> body = entity.getBody();
assertThat(body.get("status")).isEqualTo(999);
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -47,27 +47,23 @@ class ManagementPortSampleActuatorApplicationTests {
@Test @Test
void testHome() { void testHome() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) new TestRestTemplate("user", "password").getForEntity("http://localhost:" + this.port, Map.class));
.getForEntity("http://localhost:" + this.port, Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
Map<String, Object> body = entity.getBody();
assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
void testMetrics() { void testMetrics() {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate()
ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
void testHealth() { void testHealth() {
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", "password")
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class); .getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\""); assertThat(entity.getBody()).contains("\"status\":\"UP\"");
@ -77,17 +73,15 @@ class ManagementPortSampleActuatorApplicationTests {
@Test @Test
void testErrorPage() { void testErrorPage() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(new TestRestTemplate("user", "password")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.managementPort + "/error", Map.class));
.getForEntity("http://localhost:" + this.managementPort + "/error", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("status")).isEqualTo(999);
Map<String, Object> body = entity.getBody();
assertThat(body.get("status")).isEqualTo(999);
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -42,26 +42,23 @@ class NoManagementSampleActuatorApplicationTests {
@Test @Test
void testHome() { void testHome() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class));
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
Map<String, Object> body = entity.getBody();
assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
void testMetricsNotAvailable() { void testMetricsNotAvailable() {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/metrics", this.restTemplate.withBasicAuth("user", "password").getForEntity("/metrics", Map.class));
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -55,62 +55,51 @@ class SampleActuatorApplicationTests {
@Test @Test
void testHomeIsSecure() { void testHomeIsSecure() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/", Map.class));
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("error")).isEqualTo("Unauthorized");
Map<String, Object> body = entity.getBody();
assertThat(body.get("error")).isEqualTo("Unauthorized");
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
} }
@Test @Test
void testMetricsIsSecure() { void testMetricsIsSecure() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class); this.restTemplate.getForEntity("/actuator/metrics", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
entity = this.restTemplate.getForEntity("/actuator/metrics/", Map.class); entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics/", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
entity = this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class); entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics/foo", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
entity = this.restTemplate.getForEntity("/actuator/metrics.json", Map.class); entity = asMapEntity(this.restTemplate.getForEntity("/actuator/metrics.json", Map.class));
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
void testHome() { void testHome() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class));
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("message")).isEqualTo("Hello Phil");
Map<String, Object> body = entity.getBody();
assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@SuppressWarnings("unchecked")
@Test @Test
@SuppressWarnings("unchecked")
void testMetrics() { void testMetrics() {
testHome(); // makes sure some requests have been made testHome(); // makes sure some requests have been made
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/metrics", Map.class));
.getForEntity("/actuator/metrics", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
Map<String, Object> body = entity.getBody(); assertThat(entity.getBody()).containsKey("names");
assertThat(body).containsKey("names"); List<String> names = (List<String>) entity.getBody().get("names");
assertThat((List<String>) body.get("names")).contains("jvm.buffer.count"); assertThat(names).contains("jvm.buffer.count");
} }
@Test @Test
void testEnv() { void testEnv() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/env", Map.class));
.getForEntity("/actuator/env", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody()).containsKey("propertySources");
Map<String, Object> body = entity.getBody();
assertThat(body).containsKey("propertySources");
} }
@Test @Test
@ -133,7 +122,7 @@ class SampleActuatorApplicationTests {
@Test @Test
void testErrorPage() { void testErrorPage() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/foo", ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password").getForEntity("/foo",
String.class); String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
String body = entity.getBody(); String body = entity.getBody();
@ -145,7 +134,7 @@ class SampleActuatorApplicationTests {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
HttpEntity<?> request = new HttpEntity<Void>(headers); HttpEntity<?> request = new HttpEntity<Void>(headers);
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/foo", ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password").exchange("/foo",
HttpMethod.GET, request, String.class); HttpMethod.GET, request, String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
String body = entity.getBody(); String body = entity.getBody();
@ -155,32 +144,26 @@ class SampleActuatorApplicationTests {
@Test @Test
void testErrorPageDirectAccess() { void testErrorPageDirectAccess() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/error", this.restTemplate.withBasicAuth("user", "password").getForEntity("/error", Map.class));
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("error")).isEqualTo("None");
Map<String, Object> body = entity.getBody(); assertThat(entity.getBody().get("status")).isEqualTo(999);
assertThat(body.get("error")).isEqualTo("None");
assertThat(body.get("status")).isEqualTo(999);
} }
@Test @Test
@SuppressWarnings("unchecked")
void testBeans() { void testBeans() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/beans", Map.class));
.getForEntity("/actuator/beans", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).containsOnlyKeys("contexts"); assertThat(entity.getBody()).containsOnlyKeys("contexts");
} }
@SuppressWarnings("unchecked")
@Test @Test
@SuppressWarnings("unchecked")
void testConfigProps() { void testConfigProps() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/configprops", Map.class));
.getForEntity("/actuator/configprops", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
Map<String, Object> contexts = (Map<String, Object>) body.get("contexts"); Map<String, Object> contexts = (Map<String, Object>) body.get("contexts");
@ -191,17 +174,15 @@ class SampleActuatorApplicationTests {
@Test @Test
void testLegacy() { void testLegacy() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/legacy", Map.class));
.getForEntity("/actuator/legacy", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(entity.getBody()).contains(entry("legacy", "legacy"));
Map<String, Object> body = entity.getBody();
assertThat(body).contains(entry("legacy", "legacy"));
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -42,19 +42,16 @@ class ServletPathSampleActuatorApplicationTests {
@Test @Test
void testErrorPath() { void testErrorPath() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) this.restTemplate.withBasicAuth("user", "password").getForEntity("/spring/error", Map.class));
.getForEntity("/spring/error", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked") assertThat(entity.getBody().get("error")).isEqualTo("None");
Map<String, Object> body = entity.getBody(); assertThat(entity.getBody().get("status")).isEqualTo(999);
assertThat(body.get("error")).isEqualTo("None");
assertThat(body.get("status")).isEqualTo(999);
} }
@Test @Test
void testHealth() { void testHealth() {
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()) ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", "password")
.getForEntity("/spring/actuator/health", String.class); .getForEntity("/spring/actuator/health", String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("\"status\":\"UP\""); assertThat(entity.getBody()).contains("\"status\":\"UP\"");
@ -62,17 +59,16 @@ class ServletPathSampleActuatorApplicationTests {
@Test @Test
void testHomeIsSecure() { void testHomeIsSecure() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.getForEntity("/spring/", Map.class));
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/spring/", Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertThat(body.get("error")).isEqualTo("Unauthorized"); assertThat(body.get("error")).isEqualTo("Unauthorized");
assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
} }

@ -47,11 +47,9 @@ class ShutdownSampleActuatorApplicationTests {
@Test @Test
void testHome() { void testHome() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()).getForEntity("/", this.restTemplate.withBasicAuth("user", "password").getForEntity("/", Map.class));
Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertThat(body.get("message")).isEqualTo("Hello Phil"); assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@ -59,17 +57,15 @@ class ShutdownSampleActuatorApplicationTests {
@Test @Test
@DirtiesContext @DirtiesContext
void testShutdown() { void testShutdown() {
@SuppressWarnings("rawtypes") ResponseEntity<Map<String, Object>> entity = asMapEntity(this.restTemplate.withBasicAuth("user", "password")
ResponseEntity<Map> entity = this.restTemplate.withBasicAuth("user", getPassword()) .postForEntity("/actuator/shutdown", null, Map.class));
.postForEntity("/actuator/shutdown", null, Map.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") assertThat(((String) entity.getBody().get("message"))).contains("Shutting down");
Map<String, Object> body = entity.getBody();
assertThat(((String) body.get("message"))).contains("Shutting down");
} }
private String getPassword() { @SuppressWarnings({ "unchecked", "rawtypes" })
return "password"; static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
return (ResponseEntity) entity;
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)

Loading…
Cancel
Save