Search in sources :

Example 11 with WebApplicationContextRunner

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

the class ServletWebServerFactoryAutoConfigurationTests method jettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void jettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationJettyServerCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        JettyServletWebServerFactory factory = context.getBean(JettyServletWebServerFactory.class);
        JettyServerCustomizer customizer = context.getBean("serverCustomizer", JettyServerCustomizer.class);
        assertThat(factory.getServerCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Server.class));
    });
}
Also used : JettyServerCustomizer(org.springframework.boot.web.embedded.jetty.JettyServerCustomizer) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) Server(org.eclipse.jetty.server.Server) HttpServer(reactor.netty.http.server.HttpServer) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) JettyServletWebServerFactory(org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 12 with WebApplicationContextRunner

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

the class ServletWebServerFactoryAutoConfigurationTests method tomcatConnectorCustomizerBeanIsAddedToFactory.

@Test
void tomcatConnectorCustomizerBeanIsAddedToFactory() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(TomcatConnectorCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class);
        TomcatConnectorCustomizer customizer = context.getBean("connectorCustomizer", TomcatConnectorCustomizer.class);
        assertThat(factory.getTomcatConnectorCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Connector.class));
    });
}
Also used : Connector(org.apache.catalina.connector.Connector) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) TomcatConnectorCustomizer(org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer) Test(org.junit.jupiter.api.Test)

Example 13 with WebApplicationContextRunner

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

the class ConditionalOnWarDeploymentTests method embeddedServletWebApplicationShouldNotMatch.

@Test
void embeddedServletWebApplicationShouldNotMatch() {
    WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(AnnotationConfigServletWebApplicationContext::new);
    contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> assertThat(context).doesNotHaveBean("forWar"));
}
Also used : ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 14 with WebApplicationContextRunner

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

the class CompositUtilsTests method getCompositeTypeListFails.

@Test
public void getCompositeTypeListFails() {
    thrown.expect(IllegalStateException.class);
    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[2].uri:file:///./target/repos/svn-config-repo", "spring.cloud.config.server.composite[2].type:svn").run(context -> {
        CompositeUtils.getCompositeTypeList(context.getEnvironment());
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) Test(org.junit.Test)

Example 15 with WebApplicationContextRunner

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

the class MappingsEndpointTests method servletWebMappingsWithPathPatternParser.

@Test
void servletWebMappingsWithPathPatternParser() {
    Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier();
    new WebApplicationContextRunner(contextSupplier).withUserConfiguration(EndpointConfiguration.class, ServletWebConfiguration.class, PathPatternParserConfiguration.class).run((context) -> {
        ContextMappings contextMappings = contextMappings(context);
        assertThat(contextMappings.getParentId()).isNull();
        assertThat(contextMappings.getMappings()).containsOnlyKeys("dispatcherServlets", "servletFilters", "servlets");
        Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(contextMappings, "dispatcherServlets");
        assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
        List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets.get("dispatcherServlet");
        assertThat(handlerMappings).hasSize(1);
        List<ServletRegistrationMappingDescription> servlets = mappings(contextMappings, "servlets");
        assertThat(servlets).hasSize(1);
        List<FilterRegistrationMappingDescription> filters = mappings(contextMappings, "servletFilters");
        assertThat(filters).hasSize(1);
    });
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) FilterRegistrationMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.FilterRegistrationMappingDescription) DispatcherServletMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.DispatcherServletMappingDescription) ContextMappings(org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings) ServletRegistrationMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.ServletRegistrationMappingDescription) List(java.util.List) 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