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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save