Skip to content

Commit 15eaa46

Browse files
committed
Merge branch '3.5.x'
2 parents eea1621 + 10477ba commit 15eaa46

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

module/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializerAotTests.java

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import org.springframework.boot.WebApplicationType;
2929
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
3030
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
31-
import org.springframework.boot.autoconfigure.AutoConfigurations;
32-
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
3331
import org.springframework.boot.test.system.CapturedOutput;
3432
import org.springframework.boot.test.system.OutputCaptureExtension;
3533
import org.springframework.boot.test.util.TestPropertyValues;
@@ -47,6 +45,7 @@
4745
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
4846
import org.springframework.core.test.tools.TestCompiler;
4947
import org.springframework.javapoet.ClassName;
48+
import org.springframework.mock.env.MockEnvironment;
5049
import org.springframework.util.StringUtils;
5150

5251
import static org.assertj.core.api.Assertions.assertThat;
@@ -64,28 +63,26 @@ class ChildManagementContextInitializerAotTests {
6463
@CompileWithForkedClassLoader
6564
@SuppressWarnings("unchecked")
6665
void aotContributedInitializerStartsManagementContext(CapturedOutput output) {
67-
WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(
68-
AnnotationConfigServletWebServerApplicationContext::new)
69-
.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class,
70-
WebEndpointAutoConfiguration.class, EndpointAutoConfiguration.class))
71-
.withUserConfiguration(WebServerConfiguration.class, TestServletManagementContextConfiguration.class);
72-
contextRunner.withPropertyValues("server.port=0", "management.server.port=0").prepare((context) -> {
73-
TestGenerationContext generationContext = new TestGenerationContext(TestTarget.class);
74-
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(
75-
(GenericApplicationContext) context.getSourceApplicationContext(), generationContext);
76-
generationContext.writeGeneratedContent();
77-
TestCompiler compiler = TestCompiler.forSystem();
78-
compiler.with(generationContext).compile((compiled) -> {
79-
ServletWebServerApplicationContext freshApplicationContext = new ServletWebServerApplicationContext();
80-
TestPropertyValues.of("server.port=0", "management.server.port=0").applyTo(freshApplicationContext);
81-
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
82-
.getInstance(ApplicationContextInitializer.class, className.toString());
83-
initializer.initialize(freshApplicationContext);
84-
assertThat(output).satisfies(numberOfOccurrences("WebServer started", 0));
85-
TestPropertyValues.of(AotDetector.AOT_ENABLED + "=true")
86-
.applyToSystemProperties(freshApplicationContext::refresh);
87-
assertThat(output).satisfies(numberOfOccurrences("WebServer started", 2));
88-
});
66+
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
67+
context.register(ManagementContextAutoConfiguration.class, WebEndpointAutoConfiguration.class,
68+
EndpointAutoConfiguration.class);
69+
context.register(WebServerConfiguration.class, TestServletManagementContextConfiguration.class);
70+
context.setEnvironment(
71+
new MockEnvironment().withProperty("server.port", "0").withProperty("management.server.port", "0"));
72+
TestGenerationContext generationContext = new TestGenerationContext(TestTarget.class);
73+
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext);
74+
generationContext.writeGeneratedContent();
75+
TestCompiler compiler = TestCompiler.forSystem();
76+
compiler.with(generationContext).compile((compiled) -> {
77+
ServletWebServerApplicationContext freshApplicationContext = new ServletWebServerApplicationContext();
78+
TestPropertyValues.of("server.port=0", "management.server.port=0").applyTo(freshApplicationContext);
79+
ApplicationContextInitializer<GenericApplicationContext> initializer = compiled
80+
.getInstance(ApplicationContextInitializer.class, className.toString());
81+
initializer.initialize(freshApplicationContext);
82+
assertThat(output).satisfies(numberOfOccurrences("WebServer started", 0));
83+
TestPropertyValues.of(AotDetector.AOT_ENABLED + "=true")
84+
.applyToSystemProperties(freshApplicationContext::refresh);
85+
assertThat(output).satisfies(numberOfOccurrences("WebServer started", 2));
8986
});
9087
}
9188

0 commit comments

Comments
 (0)