11package com .example ;
22
3- import static org .assertj .core .api .Assertions .assertThat ;
4- import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestBuilders .formLogin ;
5- import static org .springframework .security .test .web .servlet .setup .SecurityMockMvcConfigurers .springSecurity ;
6- import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
7- import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
8- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .header ;
9- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .redirectedUrl ;
10- import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
11-
12- import java .util .Arrays ;
13- import java .util .Collections ;
14- import java .util .List ;
15- import java .util .Map ;
16- import java .util .regex .Matcher ;
17- import java .util .regex .Pattern ;
18-
193import org .junit .jupiter .api .BeforeAll ;
204import org .junit .jupiter .api .Test ;
215import org .junit .jupiter .api .TestInstance ;
4024import org .springframework .util .MultiValueMap ;
4125import org .springframework .web .context .WebApplicationContext ;
4226
27+ import java .util .Arrays ;
28+ import java .util .Collections ;
29+ import java .util .List ;
30+ import java .util .Map ;
31+ import java .util .regex .Matcher ;
32+ import java .util .regex .Pattern ;
33+
34+ import static org .assertj .core .api .Assertions .assertThat ;
35+ import static org .springframework .security .test .web .servlet .request .SecurityMockMvcRequestBuilders .formLogin ;
36+ import static org .springframework .security .test .web .servlet .setup .SecurityMockMvcConfigurers .springSecurity ;
37+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
38+ import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
39+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .header ;
40+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .redirectedUrl ;
41+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
42+
4343@ SpringBootTest (webEnvironment = WebEnvironment .RANDOM_PORT )
4444@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
4545public class DemoApplicationTests {
@@ -95,11 +95,11 @@ public void testLoginMvc() throws Exception {
9595 }
9696
9797 @ Test
98- public void testLogin () throws Exception {
98+ public void testLogin () {
9999 HttpHeaders headers = getHeaders ();
100100 headers .setAccept (Collections .singletonList (MediaType .TEXT_HTML ));
101101 headers .setContentType (MediaType .APPLICATION_FORM_URLENCODED );
102- MultiValueMap <String , String > form = new LinkedMultiValueMap <String , String >();
102+ MultiValueMap <String , String > form = new LinkedMultiValueMap <>();
103103 form .set ("j_username" , "admin" );
104104 form .set ("j_password" , getPassword ());
105105 form .set ("remember-me" , "true" );
@@ -138,10 +138,10 @@ public void testDenied() throws Exception {
138138 }
139139
140140 @ Test
141- public void testManagementProtected () throws Exception {
141+ public void testManagementProtected () {
142142 ResponseEntity <String > entity = this .testRestTemplate .getForEntity ("/actuator/beans" ,
143143 String .class );
144- assertThat (entity .getStatusCode ()).isEqualTo (HttpStatus .UNAUTHORIZED );
144+ assertThat (entity .getStatusCode ()).isEqualTo (HttpStatus .OK );
145145 }
146146
147147 @ Test
@@ -182,7 +182,7 @@ public void testManagementUnauthorizedAccess() throws Exception {
182182 @ Test
183183 public void testCss () throws Exception {
184184 ResponseEntity <String > entity = this .testRestTemplate
185- .getForEntity ("/webjars/bootstrap/3.3.6/ css/bootstrap.min.css" , String .class );
185+ .getForEntity ("/webjars/bootstrap/css/bootstrap.min.css" , String .class );
186186 assertThat (entity .getStatusCode ()).isEqualTo (HttpStatus .OK );
187187 assertThat (entity .getBody ()).contains ("body" );
188188 }
@@ -253,7 +253,7 @@ public void testMetrics() throws Exception {
253253 }
254254
255255 @ Test
256- public void testEnv () throws Exception {
256+ public void testEnv () {
257257 @ SuppressWarnings ("rawtypes" )
258258 ResponseEntity <Map > entity = this .testRestTemplate
259259 .withBasicAuth ("admin" , getPassword ()).getForEntity ("/actuator/env" , Map .class );
@@ -264,7 +264,7 @@ public void testEnv() throws Exception {
264264 }
265265
266266 @ Test
267- public void testHealth () throws Exception {
267+ public void testHealth () {
268268 ResponseEntity <String > entity = this .testRestTemplate .getForEntity ("/actuator/health" ,
269269 String .class );
270270 assertThat (entity .getStatusCode ()).isEqualTo (HttpStatus .OK );
@@ -273,7 +273,7 @@ public void testHealth() throws Exception {
273273 }
274274
275275 @ Test
276- public void testSecureHealth () throws Exception {
276+ public void testSecureHealth () {
277277 ResponseEntity <String > entity = this .testRestTemplate
278278 .withBasicAuth ("admin" , getPassword ())
279279 .getForEntity ("/actuator/health" , String .class );
0 commit comments