Skip to content

Commit 82254e3

Browse files
committed
Update smoketests to test isolated actuator object mapper use
See gh-32297 See gh-20291
1 parent 3d2071d commit 82254e3

16 files changed

+453
-9
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleActuatorApplication.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -25,17 +25,14 @@
2525
import org.springframework.boot.actuate.health.HealthContributor;
2626
import org.springframework.boot.actuate.health.HealthIndicator;
2727
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
2829
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
2930
import org.springframework.context.annotation.Bean;
3031

3132
@SpringBootApplication
3233
@ConfigurationPropertiesScan
3334
public class SampleActuatorApplication {
3435

35-
public static void main(String[] args) {
36-
SpringApplication.run(SampleActuatorApplication.class, args);
37-
}
38-
3936
@Bean
4037
public HealthIndicator helloHealthIndicator() {
4138
return createHealthIndicator("world");
@@ -61,4 +58,10 @@ private HealthIndicator createHealthIndicator(String value) {
6158
return () -> Health.up().withDetail("hello", value).build();
6259
}
6360

61+
public static void main(String[] args) {
62+
SpringApplication application = new SpringApplication(SampleActuatorApplication.class);
63+
application.setApplicationStartup(new BufferingApplicationStartup(1024));
64+
application.run(args);
65+
}
66+
6467
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ management.endpoint.health.group.comp.show-details=always
2828

2929
management.endpoints.migrate-legacy-ids=true
3030

31+
management.endpoints.jackson.isolated-object-mapper=true
32+
spring.jackson.visibility.field=any
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.actuator;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
21+
import org.springframework.boot.test.context.SpringBootContextLoader;
22+
23+
class ApplicationStartupSpringBootContextLoader extends SpringBootContextLoader {
24+
25+
@Override
26+
protected SpringApplication getSpringApplication() {
27+
SpringApplication application = new SpringApplication();
28+
application.setApplicationStartup(new BufferingApplicationStartup(1024));
29+
return application;
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.actuator;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.http.HttpStatus;
27+
import org.springframework.http.ResponseEntity;
28+
import org.springframework.test.context.ContextConfiguration;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
32+
/**
33+
* Integration test for WebMVC actuator when using an isolated {@link ObjectMapper}.
34+
*
35+
* @author Phillip Webb
36+
*/
37+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
38+
properties = "management.endpoints.jackson.isolated-object-mapper=false")
39+
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
40+
class SampleActuatorApplicationIsolatedObjectMapperFalseTests {
41+
42+
@Autowired
43+
private TestRestTemplate testRestTemplate;
44+
45+
@Test
46+
void resourceShouldBeAvailableOnMainPort() {
47+
ResponseEntity<String> entity = this.testRestTemplate.withBasicAuth("user", "password")
48+
.getForEntity("/actuator/startup", String.class);
49+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.actuator;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.http.HttpStatus;
27+
import org.springframework.http.ResponseEntity;
28+
import org.springframework.test.context.ContextConfiguration;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
32+
/**
33+
* Integration test for WebMVC actuator when using an isolated {@link ObjectMapper}.
34+
*
35+
* @author Phillip Webb
36+
*/
37+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
38+
properties = "management.endpoints.jackson.isolated-object-mapper=true")
39+
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
40+
class SampleActuatorApplicationIsolatedObjectMapperTrueTests {
41+
42+
@Autowired
43+
private TestRestTemplate testRestTemplate;
44+
45+
@Test
46+
void resourceShouldBeAvailableOnMainPort() {
47+
ResponseEntity<String> entity = this.testRestTemplate.withBasicAuth("user", "password")
48+
.getForEntity("/actuator/startup", String.class);
49+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
50+
assertThat(entity.getBody()).contains("\"timeline\":");
51+
}
52+
53+
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-jersey/src/main/java/smoketest/jersey/SampleJerseyApplication.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
import org.springframework.boot.autoconfigure.SpringBootApplication;
2020
import org.springframework.boot.builder.SpringApplicationBuilder;
21+
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
2122
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
2223

2324
@SpringBootApplication
2425
public class SampleJerseyApplication extends SpringBootServletInitializer {
2526

2627
public static void main(String[] args) {
27-
new SampleJerseyApplication().configure(new SpringApplicationBuilder(SampleJerseyApplication.class)).run(args);
28+
new SampleJerseyApplication().configure(new SpringApplicationBuilder(SampleJerseyApplication.class)
29+
.applicationStartup(new BufferingApplicationStartup(2048))).run(args);
2830
}
2931

3032
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
management.endpoints.web.exposure.include=*
2+
management.endpoints.jackson.isolated-object-mapper=true
3+
spring.jackson.visibility.field=any
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jersey;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
21+
import org.springframework.boot.test.context.SpringBootContextLoader;
22+
23+
class ApplicationStartupSpringBootContextLoader extends SpringBootContextLoader {
24+
25+
@Override
26+
protected SpringApplication getSpringApplication() {
27+
SpringApplication application = new SpringApplication();
28+
application.setApplicationStartup(new BufferingApplicationStartup(1024));
29+
return application;
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jersey;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.boot.test.web.server.LocalManagementPort;
27+
import org.springframework.boot.test.web.server.LocalServerPort;
28+
import org.springframework.http.HttpStatus;
29+
import org.springframework.http.ResponseEntity;
30+
import org.springframework.test.context.ContextConfiguration;
31+
32+
import static org.assertj.core.api.Assertions.assertThat;
33+
34+
/**
35+
* Integration test for Jersey actuator when not using an isolated {@link ObjectMapper}.
36+
*
37+
* @author Phillip Webb
38+
*/
39+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
40+
properties = "management.endpoints.jackson.isolated-object-mapper=false")
41+
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
42+
public class JerseyActuatorIsolatedObjectMapperFalseTests {
43+
44+
@LocalServerPort
45+
private int port;
46+
47+
@LocalManagementPort
48+
private int managementPort;
49+
50+
@Autowired
51+
private TestRestTemplate testRestTemplate;
52+
53+
@Test
54+
void resourceShouldBeAvailableOnMainPort() {
55+
ResponseEntity<String> entity = this.testRestTemplate
56+
.getForEntity("http://localhost:" + this.port + "/actuator/startup", String.class);
57+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
58+
assertThat(entity.getBody())
59+
.contains("Java 8 date/time type `java.time.Clock$SystemClock` not supported by default");
60+
}
61+
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jersey;
18+
19+
import com.fasterxml.jackson.databind.ObjectMapper;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.boot.test.web.server.LocalManagementPort;
27+
import org.springframework.boot.test.web.server.LocalServerPort;
28+
import org.springframework.http.HttpStatus;
29+
import org.springframework.http.ResponseEntity;
30+
import org.springframework.test.context.ContextConfiguration;
31+
32+
import static org.assertj.core.api.Assertions.assertThat;
33+
34+
/**
35+
* Integration test for Jersey actuator when using an isolated {@link ObjectMapper}.
36+
*
37+
* @author Phillip Webb
38+
*/
39+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
40+
properties = "management.endpoints.jackson.isolated-object-mapper=true")
41+
@ContextConfiguration(loader = ApplicationStartupSpringBootContextLoader.class)
42+
public class JerseyActuatorIsolatedObjectMapperTrueTests {
43+
44+
@LocalServerPort
45+
private int port;
46+
47+
@LocalManagementPort
48+
private int managementPort;
49+
50+
@Autowired
51+
private TestRestTemplate testRestTemplate;
52+
53+
@Test
54+
void resourceShouldBeAvailableOnMainPort() {
55+
ResponseEntity<String> entity = this.testRestTemplate
56+
.getForEntity("http://localhost:" + this.port + "/actuator/startup", String.class);
57+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
58+
assertThat(entity.getBody()).contains("\"timeline\":");
59+
}
60+
61+
}

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-webflux/src/main/java/smoketest/webflux/SampleWebFluxApplication.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 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.
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.boot.SpringApplication;
2020
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
2122
import org.springframework.context.annotation.Bean;
2223
import org.springframework.web.reactive.function.server.RouterFunction;
2324
import org.springframework.web.reactive.function.server.ServerResponse;
@@ -29,7 +30,9 @@
2930
public class SampleWebFluxApplication {
3031

3132
public static void main(String[] args) {
32-
SpringApplication.run(SampleWebFluxApplication.class, args);
33+
SpringApplication application = new SpringApplication(SampleWebFluxApplication.class);
34+
application.setApplicationStartup(new BufferingApplicationStartup(1024));
35+
application.run(args);
3336
}
3437

3538
@Bean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
management.endpoints.web.exposure.include=*
2+
management.endpoints.jackson.isolated-object-mapper=true
3+
spring.jackson.visibility.field=any

0 commit comments

Comments
 (0)