Polish "Add more WebEndpointAutoConfiguration tests"

Closes gh-11754
pull/11764/head
Phillip Webb 7 years ago
parent d8527a9708
commit 3bd940baaa

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -34,41 +34,40 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link WebEndpointAutoConfiguration}. * Tests for {@link WebEndpointAutoConfiguration}.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Yunkun Huang
*/ */
public class WebEndpointAutoConfigurationTests { public class WebEndpointAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class,
WebEndpointAutoConfiguration.class));
@Test @Test
public void webApplicationConfiguresEndpointMediaTypes() { public void webApplicationConfiguresEndpointMediaTypes() {
new WebApplicationContextRunner().withConfiguration(AutoConfigurations this.contextRunner.run((context) -> {
.of(EndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class))
.run((context) -> {
EndpointMediaTypes endpointMediaTypes = context EndpointMediaTypes endpointMediaTypes = context
.getBean(EndpointMediaTypes.class); .getBean(EndpointMediaTypes.class);
assertThat(endpointMediaTypes.getConsumed()).containsExactly( assertThat(endpointMediaTypes.getConsumed())
ActuatorMediaType.V2_JSON, "application/json"); .containsExactly(ActuatorMediaType.V2_JSON, "application/json");
}); });
} }
@Test @Test
public void webApplicationConfiguresPathMapper() { public void webApplicationConfiguresPathMapper() {
new WebApplicationContextRunner() this.contextRunner
.withPropertyValues("management.endpoints.web.path-mapping.health=healthcheck") .withPropertyValues(
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class, "management.endpoints.web.path-mapping.health=healthcheck")
WebEndpointAutoConfiguration.class))
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(PathMapper.class); assertThat(context).hasSingleBean(PathMapper.class);
String pathMapping = context.getBean(PathMapper.class).getRootPath("health"); String pathMapping = context.getBean(PathMapper.class)
.getRootPath("health");
assertThat(pathMapping).isEqualTo("healthcheck"); assertThat(pathMapping).isEqualTo("healthcheck");
}); });
} }
@Test @Test
public void webApplicationConfiguresEndpointDiscoverer() { public void webApplicationConfiguresEndpointDiscoverer() {
new WebApplicationContextRunner() this.contextRunner.run((context) -> {
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class,
WebEndpointAutoConfiguration.class))
.run((context) -> {
assertThat(context).hasSingleBean(ControllerEndpointDiscoverer.class); assertThat(context).hasSingleBean(ControllerEndpointDiscoverer.class);
assertThat(context).hasSingleBean(WebEndpointDiscoverer.class); assertThat(context).hasSingleBean(WebEndpointDiscoverer.class);
}); });
@ -76,14 +75,10 @@ public class WebEndpointAutoConfigurationTests {
@Test @Test
public void webApplicationConfiguresExposeExcludePropertyEndpointFilter() { public void webApplicationConfiguresExposeExcludePropertyEndpointFilter() {
new WebApplicationContextRunner() this.contextRunner.run((context) -> {
.withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class, assertThat(context).getBeans(ExposeExcludePropertyEndpointFilter.class)
WebEndpointAutoConfiguration.class)) .containsKeys("webIncludeExcludePropertyEndpointFilter",
.run((context) -> { "controllerIncludeExcludePropertyEndpointFilter");
assertThat(context).getBeans(ExposeExcludePropertyEndpointFilter.class).containsKeys(
"webIncludeExcludePropertyEndpointFilter",
"controllerIncludeExcludePropertyEndpointFilter"
);
}); });
} }

Loading…
Cancel
Save