Browse Source

Polish

3.4.x
Stéphane Nicoll 2 days ago
parent
commit
34e51dc63f
  1. 19
      spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ChildManagementContextInitializerAotTests.java

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

@ -26,9 +26,7 @@ import org.springframework.aot.test.generate.TestGenerationContext;
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
@ -41,6 +39,7 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.test.tools.CompileWithForkedClassLoader; import org.springframework.core.test.tools.CompileWithForkedClassLoader;
import org.springframework.core.test.tools.TestCompiler; import org.springframework.core.test.tools.TestCompiler;
import org.springframework.javapoet.ClassName; import org.springframework.javapoet.ClassName;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -58,15 +57,14 @@ class ChildManagementContextInitializerAotTests {
@CompileWithForkedClassLoader @CompileWithForkedClassLoader
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
void aotContributedInitializerStartsManagementContext(CapturedOutput output) { void aotContributedInitializerStartsManagementContext(CapturedOutput output) {
WebApplicationContextRunner contextRunner = new WebApplicationContextRunner( AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
AnnotationConfigServletWebServerApplicationContext::new) context.register(ManagementContextAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class,
.withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class, ServletManagementContextAutoConfiguration.class, WebEndpointAutoConfiguration.class,
ServletWebServerFactoryAutoConfiguration.class, ServletManagementContextAutoConfiguration.class, EndpointAutoConfiguration.class);
WebEndpointAutoConfiguration.class, EndpointAutoConfiguration.class)); context.setEnvironment(
contextRunner.withPropertyValues("server.port=0", "management.server.port=0").prepare((context) -> { new MockEnvironment().withProperty("server.port", "0").withProperty("management.server.port", "0"));
TestGenerationContext generationContext = new TestGenerationContext(TestTarget.class); TestGenerationContext generationContext = new TestGenerationContext(TestTarget.class);
ClassName className = new ApplicationContextAotGenerator().processAheadOfTime( ClassName className = new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext);
(GenericApplicationContext) context.getSourceApplicationContext(), generationContext);
generationContext.writeGeneratedContent(); generationContext.writeGeneratedContent();
TestCompiler compiler = TestCompiler.forSystem(); TestCompiler compiler = TestCompiler.forSystem();
compiler.with(generationContext).compile((compiled) -> { compiler.with(generationContext).compile((compiled) -> {
@ -80,7 +78,6 @@ class ChildManagementContextInitializerAotTests {
.applyToSystemProperties(freshApplicationContext::refresh); .applyToSystemProperties(freshApplicationContext::refresh);
assertThat(output).satisfies(numberOfOccurrences("Tomcat started on port", 2)); assertThat(output).satisfies(numberOfOccurrences("Tomcat started on port", 2));
}); });
});
} }
private <T extends CharSequence> Consumer<T> numberOfOccurrences(String substring, int expectedCount) { private <T extends CharSequence> Consumer<T> numberOfOccurrences(String substring, int expectedCount) {

Loading…
Cancel
Save