Search in sources :

Example 21 with WebApplicationContextRunner

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

the class JettyMetricsAutoConfigurationTests method allowsCustomJettyConnectionMetricsBinderToBeUsed.

@Test
void allowsCustomJettyConnectionMetricsBinderToBeUsed() {
    new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(JettyMetricsAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(ServletWebServerConfiguration.class, CustomJettyConnectionMetricsBinder.class, MeterRegistryConfiguration.class).run((context) -> {
        context.publishEvent(createApplicationStartedEvent(context.getSourceApplicationContext()));
        assertThat(context).hasSingleBean(JettyConnectionMetricsBinder.class).hasBean("customJettyConnectionMetricsBinder");
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        assertThat(registry.find("jetty.connections.messages.in").tag("custom-tag-name", "custom-tag-value").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) JettyConnectionMetricsBinder(org.springframework.boot.actuate.metrics.web.jetty.JettyConnectionMetricsBinder) Test(org.junit.jupiter.api.Test)

Example 22 with WebApplicationContextRunner

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

the class JettyMetricsAutoConfigurationTests method allowsCustomJettySslHandshakeMetricsBinderToBeUsed.

@Test
void allowsCustomJettySslHandshakeMetricsBinderToBeUsed() {
    new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(JettyMetricsAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(ServletWebServerConfiguration.class, CustomJettySslHandshakeMetricsBinder.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).hasBean("customJettySslHandshakeMetricsBinder");
        SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class);
        assertThat(registry.find("jetty.ssl.handshakes").tag("custom-tag-name", "custom-tag-value").meter()).isNotNull();
    });
    new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(JettyMetricsAutoConfiguration.class)).withUserConfiguration(CustomJettySslHandshakeMetricsBinder.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) -> assertThat(context).hasSingleBean(JettySslHandshakeMetricsBinder.class).hasBean("customJettySslHandshakeMetricsBinder"));
}
Also used : JettySslHandshakeMetricsBinder(org.springframework.boot.actuate.metrics.web.jetty.JettySslHandshakeMetricsBinder) 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 23 with WebApplicationContextRunner

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

the class MappingsEndpointAutoConfigurationTests method whenEndpointIsAvailableThenEndpointAndDescriptionProvidersAreCreated.

@Test
void whenEndpointIsAvailableThenEndpointAndDescriptionProvidersAreCreated() {
    new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(MappingsEndpointAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class, DispatcherServletAutoConfiguration.class, EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class, WebMvcEndpointManagementContextConfiguration.class, PropertyPlaceholderAutoConfiguration.class)).withPropertyValues("management.endpoints.web.exposure.include=mappings").run((context) -> {
        assertThat(context).hasSingleBean(MappingsEndpoint.class);
        assertThat(context.getBeansOfType(MappingDescriptionProvider.class)).hasSize(3);
    });
}
Also used : WebMvcAutoConfiguration(org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration) HttpMessageConvertersAutoConfiguration(org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) EndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration) WebEndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) DispatcherServletAutoConfiguration(org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration) WebMvcEndpointManagementContextConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.web.servlet.WebMvcEndpointManagementContextConfiguration) JacksonAutoConfiguration(org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration) WebEndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 24 with WebApplicationContextRunner

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

the class ManagementContextAutoConfigurationTests method givenSamePortManagementServerWhenManagementServerAddressIsConfiguredThenContextRefreshFails.

@Test
void givenSamePortManagementServerWhenManagementServerAddressIsConfiguredThenContextRefreshFails() {
    WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class, ServletManagementContextAutoConfiguration.class, WebEndpointAutoConfiguration.class, EndpointAutoConfiguration.class, DispatcherServletAutoConfiguration.class));
    contextRunner.withPropertyValues("server.port=0", "management.server.address=127.0.0.1").run((context) -> assertThat(context).getFailure().hasMessageStartingWith("Management-specific server address cannot be configured"));
}
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) DispatcherServletAutoConfiguration(org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration) WebEndpointAutoConfiguration(org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 25 with WebApplicationContextRunner

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

the class WebMvcEndpointExposureIntegrationTests method singleWebEndpointCanBeExcluded.

@Test
void singleWebEndpointCanBeExcluded() {
    WebApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=*", "management.endpoints.web.exposure.exclude=shutdown");
    contextRunner.run((context) -> {
        WebTestClient client = createClient(context);
        assertThat(isExposed(client, HttpMethod.GET, "beans")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "conditions")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "configprops")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "custommvc")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "customservlet")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "env")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "health")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "info")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "mappings")).isTrue();
        assertThat(isExposed(client, HttpMethod.POST, "shutdown")).isFalse();
        assertThat(isExposed(client, HttpMethod.GET, "threaddump")).isTrue();
        assertThat(isExposed(client, HttpMethod.GET, "httptrace")).isTrue();
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) 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