Commit a325b13d authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Auto-configure a ResourceConfig for Jersey endpoints if needed"

Closes gh-11948
parent bb2864ad
...@@ -31,30 +31,29 @@ import org.springframework.context.annotation.Configuration; ...@@ -31,30 +31,29 @@ import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link JerseyWebEndpointManagementContextConfiguration}.
*
* @author Michael Simons * @author Michael Simons
*/ */
public class JerseyWebEndpointManagementContextConfigurationTests { public class JerseyWebEndpointManagementContextConfigurationTests {
private final WebApplicationContextRunner runner = new WebApplicationContextRunner() private final WebApplicationContextRunner runner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(WebEndpointAutoConfiguration.class, JerseyWebEndpointManagementContextConfiguration.class)); .withConfiguration(AutoConfigurations.of(WebEndpointAutoConfiguration.class,
JerseyWebEndpointManagementContextConfiguration.class));
@Test @Test
public void contextShouldContainSingleResourceConfig() { public void resourceConfigIsAutoConfiguredWhenNeeded() {
this.runner this.runner.withUserConfiguration(WebEndpointsSupplierConfig.class).run(
.withUserConfiguration(WebEndpointsSupplierConfig.class) (context) -> assertThat(context).hasSingleBean(ResourceConfig.class));
.run(context -> assertThat(context).hasSingleBean(ResourceConfig.class));
} }
@Test @Test
public void contextWhenResourceConfigExistsShouldContainSingleResourceConfig() { public void existingResourceConfigIsUsedWhenAvailable() {
this.runner this.runner.withUserConfiguration(WebEndpointsSupplierConfig.class,
.withUserConfiguration( ConfigWithResourceConfig.class).run((context) -> {
WebEndpointsSupplierConfig.class, assertThat(context).hasSingleBean(ResourceConfig.class);
ConfigWithResourceConfig.class) assertThat(context).hasBean("customResourceConfig");
.run(context -> { });
assertThat(context).hasSingleBean(ResourceConfig.class);
assertThat(context).hasBean("customResourceConfig");
});
} }
@Configuration @Configuration
...@@ -64,6 +63,7 @@ public class JerseyWebEndpointManagementContextConfigurationTests { ...@@ -64,6 +63,7 @@ public class JerseyWebEndpointManagementContextConfigurationTests {
public WebEndpointsSupplier webEndpointsSupplier() { public WebEndpointsSupplier webEndpointsSupplier() {
return () -> Collections.emptyList(); return () -> Collections.emptyList();
} }
} }
@Configuration @Configuration
...@@ -73,5 +73,7 @@ public class JerseyWebEndpointManagementContextConfigurationTests { ...@@ -73,5 +73,7 @@ public class JerseyWebEndpointManagementContextConfigurationTests {
public ResourceConfig customResourceConfig() { public ResourceConfig customResourceConfig() {
return new ResourceConfig(); return new ResourceConfig();
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment