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