Skip to content

Commit 9d28238

Browse files
committed
Update formatting of spring-boot-samples
1 parent da1d4b8 commit 9d28238

File tree

167 files changed

+745
-1172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+745
-1172
lines changed

spring-boot-samples/spring-boot-sample-actuator-custom-security/src/main/java/sample/actuator/customsecurity/SecurityConfiguration.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,10 +33,9 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
3333
@Bean
3434
public InMemoryUserDetailsManager inMemoryUserDetailsManager() {
3535
return new InMemoryUserDetailsManager(
36-
User.withDefaultPasswordEncoder().username("user").password("password")
37-
.authorities("ROLE_USER").build(),
38-
User.withDefaultPasswordEncoder().username("beans").password("beans")
39-
.authorities("ROLE_BEANS").build(),
36+
User.withDefaultPasswordEncoder().username("user").password("password").authorities("ROLE_USER")
37+
.build(),
38+
User.withDefaultPasswordEncoder().username("beans").password("beans").authorities("ROLE_BEANS").build(),
4039
User.withDefaultPasswordEncoder().username("admin").password("admin")
4140
.authorities("ROLE_ACTUATOR", "ROLE_USER").build());
4241
}

spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/CorsSampleActuatorApplicationTests.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -55,37 +55,31 @@ public class CorsSampleActuatorApplicationTests {
5555
@Before
5656
public void setUp() {
5757
RestTemplateBuilder builder = new RestTemplateBuilder();
58-
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(
59-
this.applicationContext.getEnvironment(), "http");
58+
LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(this.applicationContext.getEnvironment(),
59+
"http");
6060
builder = builder.uriTemplateHandler(handler);
6161
this.testRestTemplate = new TestRestTemplate(builder);
6262
}
6363

6464
@Test
6565
public void endpointShouldReturnUnauthorized() {
66-
ResponseEntity<?> entity = this.testRestTemplate.getForEntity("/actuator/env",
67-
Map.class);
66+
ResponseEntity<?> entity = this.testRestTemplate.getForEntity("/actuator/env", Map.class);
6867
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
6968
}
7069

7170
@Test
7271
public void preflightRequestToEndpointShouldReturnOk() throws Exception {
7372
RequestEntity<?> healthRequest = RequestEntity.options(new URI("/actuator/env"))
74-
.header("Origin", "http://localhost:8080")
75-
.header("Access-Control-Request-Method", "GET").build();
76-
ResponseEntity<?> exchange = this.testRestTemplate.exchange(healthRequest,
77-
Map.class);
73+
.header("Origin", "http://localhost:8080").header("Access-Control-Request-Method", "GET").build();
74+
ResponseEntity<?> exchange = this.testRestTemplate.exchange(healthRequest, Map.class);
7875
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK);
7976
}
8077

8178
@Test
82-
public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden()
83-
throws Exception {
79+
public void preflightRequestWhenCorsConfigInvalidShouldReturnForbidden() throws Exception {
8480
RequestEntity<?> entity = RequestEntity.options(new URI("/actuator/env"))
85-
.header("Origin", "http://localhost:9095")
86-
.header("Access-Control-Request-Method", "GET").build();
87-
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity,
88-
byte[].class);
81+
.header("Origin", "http://localhost:9095").header("Access-Control-Request-Method", "GET").build();
82+
ResponseEntity<byte[]> exchange = this.testRestTemplate.exchange(entity, byte[].class);
8983
assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
9084
}
9185

spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/ManagementPortAndPathSampleActuatorApplicationTests.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
*/
3939
@RunWith(SpringRunner.class)
4040
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
41-
properties = { "management.server.port=0",
42-
"management.server.servlet.context-path=/management" })
41+
properties = { "management.server.port=0", "management.server.servlet.context-path=/management" })
4342
public class ManagementPortAndPathSampleActuatorApplicationTests {
4443

4544
@LocalServerPort
@@ -58,26 +57,23 @@ public void testHome() {
5857

5958
@Test
6059
public void testSecureActuator() {
61-
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
62-
"http://localhost:" + this.managementPort + "/management/actuator/env",
63-
String.class);
60+
ResponseEntity<String> entity = new TestRestTemplate()
61+
.getForEntity("http://localhost:" + this.managementPort + "/management/actuator/env", String.class);
6462
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
6563
}
6664

6765
@Test
6866
public void testInsecureActuator() {
69-
ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
70-
"http://localhost:" + this.managementPort + "/management/actuator/health",
71-
String.class);
67+
ResponseEntity<String> entity = new TestRestTemplate()
68+
.getForEntity("http://localhost:" + this.managementPort + "/management/actuator/health", String.class);
7269
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
7370
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
7471
}
7572

7673
@Test
7774
public void testMissing() {
7875
ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
79-
.getForEntity("http://localhost:" + this.managementPort
80-
+ "/management/actuator/missing", String.class);
76+
.getForEntity("http://localhost:" + this.managementPort + "/management/actuator/missing", String.class);
8177
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
8278
assertThat(entity.getBody()).contains("\"status\":404");
8379
}

spring-boot-samples/spring-boot-sample-actuator-custom-security/src/test/java/sample/actuator/customsecurity/SampleActuatorCustomSecurityApplicationTests.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,90 +61,81 @@ public void testInsecureApplicationPath() {
6161
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
6262
@SuppressWarnings("unchecked")
6363
Map<String, Object> body = entity.getBody();
64-
assertThat((String) body.get("message"))
65-
.contains("Expected exception in controller");
64+
assertThat((String) body.get("message")).contains("Expected exception in controller");
6665
}
6766

6867
@Test
6968
public void testInsecureStaticResources() {
70-
ResponseEntity<String> entity = restTemplate()
71-
.getForEntity("/css/bootstrap.min.css", String.class);
69+
ResponseEntity<String> entity = restTemplate().getForEntity("/css/bootstrap.min.css", String.class);
7270
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
7371
assertThat(entity.getBody()).contains("body");
7472
}
7573

7674
@Test
7775
public void actuatorInsecureEndpoint() {
78-
ResponseEntity<String> entity = restTemplate().getForEntity("/actuator/health",
79-
String.class);
76+
ResponseEntity<String> entity = restTemplate().getForEntity("/actuator/health", String.class);
8077
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
8178
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
8279
}
8380

8481
@Test
8582
public void actuatorLinksIsSecure() {
86-
ResponseEntity<Object> entity = restTemplate().getForEntity("/actuator",
87-
Object.class);
83+
ResponseEntity<Object> entity = restTemplate().getForEntity("/actuator", Object.class);
8884
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
8985
entity = adminRestTemplate().getForEntity("/actuator", Object.class);
9086
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
9187
}
9288

9389
@Test
9490
public void actuatorSecureEndpointWithAnonymous() {
95-
ResponseEntity<Object> entity = restTemplate().getForEntity("/actuator/env",
96-
Object.class);
91+
ResponseEntity<Object> entity = restTemplate().getForEntity("/actuator/env", Object.class);
9792
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
9893
}
9994

10095
@Test
10196
public void actuatorSecureEndpointWithUnauthorizedUser() {
102-
ResponseEntity<Object> entity = userRestTemplate().getForEntity("/actuator/env",
103-
Object.class);
97+
ResponseEntity<Object> entity = userRestTemplate().getForEntity("/actuator/env", Object.class);
10498
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
10599
}
106100

107101
@Test
108102
public void actuatorSecureEndpointWithAuthorizedUser() {
109-
ResponseEntity<Object> entity = adminRestTemplate().getForEntity("/actuator/env",
110-
Object.class);
103+
ResponseEntity<Object> entity = adminRestTemplate().getForEntity("/actuator/env", Object.class);
111104
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
112105
}
113106

114107
@Test
115108
public void actuatorCustomMvcSecureEndpointWithAnonymous() {
116-
ResponseEntity<String> entity = restTemplate()
117-
.getForEntity("/actuator/example/echo?text={t}", String.class, "test");
109+
ResponseEntity<String> entity = restTemplate().getForEntity("/actuator/example/echo?text={t}", String.class,
110+
"test");
118111
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
119112
}
120113

121114
@Test
122115
public void actuatorCustomMvcSecureEndpointWithUnauthorizedUser() {
123-
ResponseEntity<String> entity = userRestTemplate()
124-
.getForEntity("/actuator/example/echo?text={t}", String.class, "test");
116+
ResponseEntity<String> entity = userRestTemplate().getForEntity("/actuator/example/echo?text={t}", String.class,
117+
"test");
125118
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
126119
}
127120

128121
@Test
129122
public void actuatorCustomMvcSecureEndpointWithAuthorizedUser() {
130-
ResponseEntity<String> entity = adminRestTemplate()
131-
.getForEntity("/actuator/example/echo?text={t}", String.class, "test");
123+
ResponseEntity<String> entity = adminRestTemplate().getForEntity("/actuator/example/echo?text={t}",
124+
String.class, "test");
132125
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
133126
assertThat(entity.getBody()).isEqualTo("test");
134127
assertThat(entity.getHeaders().getFirst("echo")).isEqualTo("test");
135128
}
136129

137130
@Test
138131
public void actuatorExcludedFromEndpointRequestMatcher() {
139-
ResponseEntity<Object> entity = userRestTemplate()
140-
.getForEntity("/actuator/mappings", Object.class);
132+
ResponseEntity<Object> entity = userRestTemplate().getForEntity("/actuator/mappings", Object.class);
141133
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
142134
}
143135

144136
@Test
145137
public void mvcMatchersCanBeUsedToSecureActuators() {
146-
ResponseEntity<Object> entity = beansRestTemplate()
147-
.getForEntity("/actuator/beans", Object.class);
138+
ResponseEntity<Object> entity = beansRestTemplate().getForEntity("/actuator/beans", Object.class);
148139
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
149140
entity = beansRestTemplate().getForEntity("/actuator/beans/", Object.class);
150141
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -167,8 +158,7 @@ private TestRestTemplate beansRestTemplate() {
167158
}
168159

169160
private TestRestTemplate configure(TestRestTemplate restTemplate) {
170-
restTemplate
171-
.setUriTemplateHandler(new LocalHostUriTemplateHandler(this.environment));
161+
restTemplate.setUriTemplateHandler(new LocalHostUriTemplateHandler(this.environment));
172162
return restTemplate;
173163
}
174164

spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorLog4J2ApplicationTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,8 +48,7 @@
4848
@AutoConfigureMockMvc
4949
public class SampleActuatorLog4J2ApplicationTests {
5050

51-
private static final Logger logger = LogManager
52-
.getLogger(SampleActuatorLog4J2ApplicationTests.class);
51+
private static final Logger logger = LogManager.getLogger(SampleActuatorLog4J2ApplicationTests.class);
5352

5453
@Rule
5554
public OutputCapture output = new OutputCapture();
@@ -65,12 +64,9 @@ public void testLogger() {
6564

6665
@Test
6766
public void validateLoggersEndpoint() throws Exception {
68-
this.mvc.perform(
69-
get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol")
70-
.header("Authorization", "Basic " + getBasicAuth()))
71-
.andExpect(status().isOk())
72-
.andExpect(content().string(equalTo("{\"configuredLevel\":\"WARN\","
73-
+ "\"effectiveLevel\":\"WARN\"}")));
67+
this.mvc.perform(get("/actuator/loggers/org.apache.coyote.http11.Http11NioProtocol").header("Authorization",
68+
"Basic " + getBasicAuth())).andExpect(status().isOk()).andExpect(
69+
content().string(equalTo("{\"configuredLevel\":\"WARN\"," + "\"effectiveLevel\":\"WARN\"}")));
7470
}
7571

7672
private String getBasicAuth() {

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
* @author Dave Syer
3939
*/
4040
@RunWith(SpringRunner.class)
41-
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
42-
properties = { "management.server.port:0" })
41+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "management.server.port:0" })
4342
public class SampleActuatorUiApplicationPortTests {
4443

4544
@LocalServerPort
@@ -50,26 +49,23 @@ public class SampleActuatorUiApplicationPortTests {
5049

5150
@Test
5251
public void testHome() {
53-
ResponseEntity<String> entity = new TestRestTemplate()
54-
.getForEntity("http://localhost:" + this.port, String.class);
52+
ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:" + this.port,
53+
String.class);
5554
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
5655
}
5756

5857
@Test
5958
public void testMetrics() {
6059
@SuppressWarnings("rawtypes")
61-
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
62-
"http://localhost:" + this.managementPort + "/actuator/metrics",
63-
Map.class);
60+
ResponseEntity<Map> entity = new TestRestTemplate()
61+
.getForEntity("http://localhost:" + this.managementPort + "/actuator/metrics", Map.class);
6462
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
6563
}
6664

6765
@Test
6866
public void testHealth() {
69-
ResponseEntity<String> entity = new TestRestTemplate()
70-
.withBasicAuth("user", getPassword()).getForEntity(
71-
"http://localhost:" + this.managementPort + "/actuator/health",
72-
String.class);
67+
ResponseEntity<String> entity = new TestRestTemplate().withBasicAuth("user", getPassword())
68+
.getForEntity("http://localhost:" + this.managementPort + "/actuator/health", String.class);
7369
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
7470
assertThat(entity.getBody()).contains("\"status\":\"UP\"");
7571
}

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,36 +52,32 @@ public class SampleActuatorUiApplicationTests {
5252
public void testHome() {
5353
HttpHeaders headers = new HttpHeaders();
5454
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
55-
ResponseEntity<String> entity = this.restTemplate
56-
.withBasicAuth("user", getPassword()).exchange("/", HttpMethod.GET,
57-
new HttpEntity<Void>(headers), String.class);
55+
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/",
56+
HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
5857
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
5958
assertThat(entity.getBody()).contains("<title>Hello");
6059
}
6160

6261
@Test
6362
public void testCss() {
64-
ResponseEntity<String> entity = this.restTemplate
65-
.getForEntity("/css/bootstrap.min.css", String.class);
63+
ResponseEntity<String> entity = this.restTemplate.getForEntity("/css/bootstrap.min.css", String.class);
6664
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
6765
assertThat(entity.getBody()).contains("body");
6866
}
6967

7068
@Test
7169
public void testMetrics() {
7270
@SuppressWarnings("rawtypes")
73-
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics",
74-
Map.class);
71+
ResponseEntity<Map> entity = this.restTemplate.getForEntity("/actuator/metrics", Map.class);
7572
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
7673
}
7774

7875
@Test
7976
public void testError() {
8077
HttpHeaders headers = new HttpHeaders();
8178
headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));
82-
ResponseEntity<String> entity = this.restTemplate
83-
.withBasicAuth("user", getPassword()).exchange("/error", HttpMethod.GET,
84-
new HttpEntity<Void>(headers), String.class);
79+
ResponseEntity<String> entity = this.restTemplate.withBasicAuth("user", getPassword()).exchange("/error",
80+
HttpMethod.GET, new HttpEntity<Void>(headers), String.class);
8581
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
8682
assertThat(entity.getBody()).contains("<html>").contains("<body>")
8783
.contains("Please contact the operator with the above information");

spring-boot-samples/spring-boot-sample-actuator/src/main/java/sample/actuator/SampleController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,8 +45,7 @@ public SampleController(HelloWorldService helloWorldService) {
4545
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
4646
@ResponseBody
4747
public Map<String, String> hello() {
48-
return Collections.singletonMap("message",
49-
this.helloWorldService.getHelloMessage());
48+
return Collections.singletonMap("message", this.helloWorldService.getHelloMessage());
5049
}
5150

5251
@PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)

0 commit comments

Comments
 (0)