Add tests for WebEndpointAutoConfiguration

Closes gh-11754
See gh-11684
This commit is contained in:
Yunkun Huang
2018-01-24 19:34:22 +08:00
committed by Phillip Webb
parent 093ca0a687
commit d8527a9708

View File

@@ -19,8 +19,12 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.endpoint.ExposeExcludePropertyEndpointFilter;
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
import org.springframework.boot.actuate.endpoint.web.PathMapper;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointDiscoverer;
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
@@ -45,4 +49,42 @@ public class WebEndpointAutoConfigurationTests {
});
}
@Test
public void webApplicationConfiguresPathMapper() {
new WebApplicationContextRunner()
.withPropertyValues("management.endpoints.web.path-mapping.health=healthcheck")
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class,
WebEndpointAutoConfiguration.class))
.run((context) -> {
assertThat(context).hasSingleBean(PathMapper.class);
String pathMapping = context.getBean(PathMapper.class).getRootPath("health");
assertThat(pathMapping).isEqualTo("healthcheck");
});
}
@Test
public void webApplicationConfiguresEndpointDiscoverer() {
new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class,
WebEndpointAutoConfiguration.class))
.run((context) -> {
assertThat(context).hasSingleBean(ControllerEndpointDiscoverer.class);
assertThat(context).hasSingleBean(WebEndpointDiscoverer.class);
});
}
@Test
public void webApplicationConfiguresExposeExcludePropertyEndpointFilter() {
new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class,
WebEndpointAutoConfiguration.class))
.run((context) -> {
assertThat(context).getBeans(ExposeExcludePropertyEndpointFilter.class).containsKeys(
"webIncludeExcludePropertyEndpointFilter",
"controllerIncludeExcludePropertyEndpointFilter"
);
});
}
}