use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.
the class WebMvcEndpointExposureIntegrationTests method singleWebEndpointCanBeExposed.
@Test
void singleWebEndpointCanBeExposed() {
WebApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=beans");
contextRunner.run((context) -> {
WebTestClient client = createClient(context);
assertThat(isExposed(client, HttpMethod.GET, "beans")).isTrue();
assertThat(isExposed(client, HttpMethod.GET, "conditions")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "configprops")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "custommvc")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "customservlet")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "env")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "health")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "info")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "mappings")).isFalse();
assertThat(isExposed(client, HttpMethod.POST, "shutdown")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "threaddump")).isFalse();
assertThat(isExposed(client, HttpMethod.GET, "httptrace")).isFalse();
});
}
use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.
the class WebMvcEndpointExposureIntegrationTests method webEndpointsCanBeExposed.
@Test
void webEndpointsCanBeExposed() {
WebApplicationContextRunner contextRunner = this.contextRunner.withPropertyValues("management.endpoints.web.exposure.include=*");
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();
});
}
use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.
the class HttpMessageConvertersAutoConfigurationTests method whenEncodingCharsetIsConfiguredThenStringMessageConverterUsesSpecificCharset.
@Test
void whenEncodingCharsetIsConfiguredThenStringMessageConverterUsesSpecificCharset() {
new WebApplicationContextRunner().withConfiguration(AutoConfigurations.of(HttpMessageConvertersAutoConfiguration.class)).withPropertyValues("server.servlet.encoding.charset=UTF-16").run((context) -> {
assertThat(context).hasSingleBean(StringHttpMessageConverter.class);
assertThat(context.getBean(StringHttpMessageConverter.class).getDefaultCharset()).isEqualTo(StandardCharsets.UTF_16);
});
}
use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.
the class ServletWebServerFactoryAutoConfigurationTests method tomcatProtocolHandlerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.
@Test
void tomcatProtocolHandlerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationTomcatProtocolHandlerCustomizerConfiguration.class).withPropertyValues("server.port: 0");
runner.run((context) -> {
TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class);
TomcatProtocolHandlerCustomizer<?> customizer = context.getBean("protocolHandlerCustomizer", TomcatProtocolHandlerCustomizer.class);
assertThat(factory.getTomcatProtocolHandlerCustomizers()).contains(customizer);
then(customizer).should().customize(any());
});
}
use of org.springframework.boot.test.context.runner.WebApplicationContextRunner in project spring-boot by spring-projects.
the class ServletWebServerFactoryAutoConfigurationTests method tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.
@Test
void tomcatContextCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationTomcatContextCustomizerConfiguration.class).withPropertyValues("server.port: 0");
runner.run((context) -> {
TomcatServletWebServerFactory factory = context.getBean(TomcatServletWebServerFactory.class);
TomcatContextCustomizer customizer = context.getBean("contextCustomizer", TomcatContextCustomizer.class);
assertThat(factory.getTomcatContextCustomizers()).contains(customizer);
then(customizer).should().customize(any(Context.class));
});
}
Aggregations