Search in sources :

Example 16 with WebApplicationContextRunner

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

the class MappingsEndpointTests method servletWebMappings.

@Test
void servletWebMappings() {
    Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier();
    new WebApplicationContextRunner(contextSupplier).withUserConfiguration(EndpointConfiguration.class, ServletWebConfiguration.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)

Example 17 with WebApplicationContextRunner

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

the class MappingsEndpointTests method servletWebMappingsWithAdditionalDispatcherServlets.

@Test
void servletWebMappingsWithAdditionalDispatcherServlets() {
    Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier();
    new WebApplicationContextRunner(contextSupplier).withUserConfiguration(EndpointConfiguration.class, ServletWebConfiguration.class, CustomDispatcherServletConfiguration.class).run((context) -> {
        ContextMappings contextMappings = contextMappings(context);
        Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(contextMappings, "dispatcherServlets");
        assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet", "customDispatcherServletRegistration", "anotherDispatcherServletRegistration");
        assertThat(dispatcherServlets.get("dispatcherServlet")).hasSize(1);
        assertThat(dispatcherServlets.get("customDispatcherServletRegistration")).hasSize(1);
        assertThat(dispatcherServlets.get("anotherDispatcherServletRegistration")).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) ContextMappings(org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 18 with WebApplicationContextRunner

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

the class JettyMetricsAutoConfigurationTests method autoConfiguresThreadPoolMetricsWithEmbeddedServletJetty.

@Test
void autoConfiguresThreadPoolMetricsWithEmbeddedServletJetty() {
    new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(JettyMetricsAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(ServletWebServerConfiguration.class, MeterRegistryConfiguration.class).run((context) -> {
        context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
        assertThat(context).hasSingleBean(JettyServerThreadPoolMetricsBinder.class);
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        assertThat(registry.find("jetty.threads.config.min").meter()).isNotNull();
    });
}
Also used : ServletWebServerFactoryAutoConfiguration(org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.jupiter.api.Test)

Example 19 with WebApplicationContextRunner

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

the class JettyMetricsAutoConfigurationTests method autoConfiguresConnectionMetricsWithEmbeddedServletJetty.

@Test
void autoConfiguresConnectionMetricsWithEmbeddedServletJetty() {
    new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(JettyMetricsAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(ServletWebServerConfiguration.class, MeterRegistryConfiguration.class).run((context) -> {
        context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
        assertThat(context).hasSingleBean(JettyConnectionMetricsBinder.class);
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        assertThat(registry.find("jetty.connections.messages.in").meter()).isNotNull();
    });
}
Also used : ServletWebServerFactoryAutoConfiguration(org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Test(org.junit.jupiter.api.Test)

Example 20 with WebApplicationContextRunner

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

the class JettyMetricsAutoConfigurationTests method autoConfiguresSslHandshakeMetricsWithEmbeddedServletJetty.

@Test
void autoConfiguresSslHandshakeMetricsWithEmbeddedServletJetty() {
    new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(JettyMetricsAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(ServletWebServerConfiguration.class, MeterRegistryConfiguration.class).withPropertyValues("server.ssl.enabled: true", "server.ssl.key-store: src/test/resources/test.jks", "server.ssl.key-store-password: secret", "server.ssl.key-password: password").run((context) -> {
        context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
        assertThat(context).hasSingleBean(JettySslHandshakeMetricsBinder.class);
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        assertThat(registry.find("jetty.ssl.handshakes").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)

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