Search in sources :

Example 1 with WebApplicationContextRunner

use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-cloud-config by spring-cloud.

the class CompositUtilsTests method getCompositeTypeListWorks.

@Test
public void getCompositeTypeListWorks() {
    new WebApplicationContextRunner().withUserConfiguration(ConfigServerApplication.class).withPropertyValues("spring.profiles.active:test,composite", "spring.config.name:compositeconfigserver", "spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo", "spring.cloud.config.server.composite[0].type:git", "spring.cloud.config.server.composite[1].uri:file:///./target/repos/svn-config-repo", "spring.cloud.config.server.composite[1].type:svn").run(context -> {
        List<String> types = CompositeUtils.getCompositeTypeList(context.getEnvironment());
        assertThat(types).containsExactly("git", "svn");
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) Test(org.junit.Test)

Example 2 with WebApplicationContextRunner

use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.

the class TomcatMetricsAutoConfigurationTests method autoConfiguresTomcatMetricsWithEmbeddedServletTomcat.

@Test
void autoConfiguresTomcatMetricsWithEmbeddedServletTomcat() {
    resetTomcatState();
    new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(TomcatMetricsAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(ServletWebServerConfiguration.class, MeterRegistryConfiguration.class).withPropertyValues("server.tomcat.mbeanregistry.enabled=true").run((context) -> {
        context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
        assertThat(context).hasSingleBean(TomcatMetricsBinder.class);
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        assertThat(registry.find("tomcat.sessions.active.max").meter()).isNotNull();
        assertThat(registry.find("tomcat.threads.current").meter()).isNotNull();
    });
}
Also used : ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.jupiter.api.Test)

Example 3 with WebApplicationContextRunner

use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.

the class ManagementContextAutoConfigurationTests method childManagementContextShouldStartForEmbeddedServer.

@Test
void childManagementContextShouldStartForEmbeddedServer(CapturedOutput output) {
    WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class, ServletManagementContextAutoConfiguration.class, WebEndpointAutoConfiguration.class, EndpointAutoConfiguration.class));
    contextRunner.withPropertyValues("server.port=0", "management.server.port=0").run((context) -> assertThat(output).satisfies(numberOfOccurrences("Tomcat started on port", 2)));
}
Also used : ServletWebServerFactoryAutoConfiguration(org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) ServletManagementContextAutoConfiguration(org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration) EndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration) WebEndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration) ServletManagementContextAutoConfiguration(org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration) WebEndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with WebApplicationContextRunner

use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method undertowBuilderCustomizerBeanIsAddedToFactory.

@Test
void undertowBuilderCustomizerBeanIsAddedToFactory() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(UndertowBuilderCustomizerConfiguration.class).withPropertyValues("server.port:0");
    runner.run((context) -> {
        UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
        assertThat(factory.getBuilderCustomizers()).hasSize(1);
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 5 with WebApplicationContextRunner

use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationUndertowBuilderCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
        UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer", UndertowBuilderCustomizer.class);
        assertThat(factory.getBuilderCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Builder.class));
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) UndertowBuilderCustomizer(org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) Builder(io.undertow.Undertow.Builder) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Aggregations

WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)36 Test (org.junit.jupiter.api.Test)34 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)14 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)12 FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)8 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)6 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)6 ServletWebServerFactoryAutoConfiguration (org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration)5 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)4 Filter (jakarta.servlet.Filter)3 List (java.util.List)3 EndpointAutoConfiguration (org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration)3 WebEndpointAutoConfiguration (org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration)3 ContextMappings (org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings)3 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)3 WebTestClient (org.springframework.test.web.reactive.server.WebTestClient)3 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)3 ServletContext (jakarta.servlet.ServletContext)2 Context (org.apache.catalina.Context)2 Connector (org.apache.catalina.connector.Connector)2