Skip to content

Commit 52536dc

Browse files
committed
Update Actuator UI sample test to adapt to sensitivity removal
See spring-projectsgh-9924
1 parent bb55f49 commit 52536dc

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
2323

24+
import org.springframework.beans.factory.annotation.Autowired;
2425
import org.springframework.boot.actuate.autoconfigure.LocalManagementPort;
26+
import org.springframework.boot.autoconfigure.security.SecurityProperties;
2527
import org.springframework.boot.test.context.SpringBootTest;
2628
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2729
import org.springframework.boot.test.web.client.TestRestTemplate;
@@ -44,6 +46,9 @@
4446
@DirtiesContext
4547
public class SampleActuatorUiApplicationPortTests {
4648

49+
@Autowired
50+
private SecurityProperties security;
51+
4752
@LocalServerPort
4853
private int port = 9010;
4954

@@ -61,16 +66,23 @@ public void testHome() throws Exception {
6166
public void testMetrics() throws Exception {
6267
@SuppressWarnings("rawtypes")
6368
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
64-
"http://localhost:" + this.managementPort + "/application//metrics", Map.class);
69+
"http://localhost:" + this.managementPort + "/application/metrics",
70+
Map.class);
6571
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
6672
}
6773

6874
@Test
6975
public void testHealth() throws Exception {
70-
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
71-
"http://localhost:" + this.managementPort + "/application//health", String.class);
76+
ResponseEntity<String> entity = new TestRestTemplate()
77+
.withBasicAuth("user", getPassword()).getForEntity(
78+
"http://localhost:" + this.managementPort + "/application/health",
79+
String.class);
7280
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
73-
assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}");
81+
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
82+
}
83+
84+
private String getPassword() {
85+
return this.security.getUser().getPassword();
7486
}
7587

7688
}

0 commit comments

Comments
 (0)