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));
});
}
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));
});
}
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"));
}
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());
});
}
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);
});
}
Aggregations