21
21
import org .junit .Test ;
22
22
import org .junit .runner .RunWith ;
23
23
24
+ import org .springframework .beans .factory .annotation .Autowired ;
24
25
import org .springframework .boot .actuate .autoconfigure .LocalManagementPort ;
26
+ import org .springframework .boot .autoconfigure .security .SecurityProperties ;
25
27
import org .springframework .boot .test .context .SpringBootTest ;
26
28
import org .springframework .boot .test .context .SpringBootTest .WebEnvironment ;
27
29
import org .springframework .boot .test .web .client .TestRestTemplate ;
44
46
@ DirtiesContext
45
47
public class SampleActuatorUiApplicationPortTests {
46
48
49
+ @ Autowired
50
+ private SecurityProperties security ;
51
+
47
52
@ LocalServerPort
48
53
private int port = 9010 ;
49
54
@@ -61,16 +66,23 @@ public void testHome() throws Exception {
61
66
public void testMetrics () throws Exception {
62
67
@ SuppressWarnings ("rawtypes" )
63
68
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 );
65
71
assertThat (entity .getStatusCode ()).isEqualTo (HttpStatus .UNAUTHORIZED );
66
72
}
67
73
68
74
@ Test
69
75
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 );
72
80
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 ();
74
86
}
75
87
76
88
}
0 commit comments