|
| 1 | +/* |
| 2 | + * Copyright 2012-2018 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.actuate.autoconfigure.endpoint.web.jersey; |
| 18 | + |
| 19 | +import java.util.Collections; |
| 20 | + |
| 21 | +import org.glassfish.jersey.server.ResourceConfig; |
| 22 | +import org.junit.Test; |
| 23 | + |
| 24 | +import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration; |
| 25 | +import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier; |
| 26 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 27 | +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
| 28 | +import org.springframework.context.annotation.Bean; |
| 29 | +import org.springframework.context.annotation.Configuration; |
| 30 | + |
| 31 | +import static org.assertj.core.api.Assertions.assertThat; |
| 32 | + |
| 33 | +/** |
| 34 | + * Tests for {@link JerseyWebEndpointManagementContextConfiguration}. |
| 35 | + * |
| 36 | + * @author Michael Simons |
| 37 | + */ |
| 38 | +public class JerseyWebEndpointManagementContextConfigurationTests { |
| 39 | + |
| 40 | + private final WebApplicationContextRunner runner = new WebApplicationContextRunner() |
| 41 | + .withConfiguration(AutoConfigurations.of(WebEndpointAutoConfiguration.class, |
| 42 | + JerseyWebEndpointManagementContextConfiguration.class)); |
| 43 | + |
| 44 | + @Test |
| 45 | + public void resourceConfigIsAutoConfiguredWhenNeeded() { |
| 46 | + this.runner.withUserConfiguration(WebEndpointsSupplierConfig.class).run( |
| 47 | + (context) -> assertThat(context).hasSingleBean(ResourceConfig.class)); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void existingResourceConfigIsUsedWhenAvailable() { |
| 52 | + this.runner.withUserConfiguration(WebEndpointsSupplierConfig.class, |
| 53 | + ConfigWithResourceConfig.class).run((context) -> { |
| 54 | + assertThat(context).hasSingleBean(ResourceConfig.class); |
| 55 | + assertThat(context).hasBean("customResourceConfig"); |
| 56 | + }); |
| 57 | + } |
| 58 | + |
| 59 | + @Configuration |
| 60 | + static class WebEndpointsSupplierConfig { |
| 61 | + |
| 62 | + @Bean |
| 63 | + public WebEndpointsSupplier webEndpointsSupplier() { |
| 64 | + return () -> Collections.emptyList(); |
| 65 | + } |
| 66 | + |
| 67 | + } |
| 68 | + |
| 69 | + @Configuration |
| 70 | + static class ConfigWithResourceConfig { |
| 71 | + |
| 72 | + @Bean |
| 73 | + public ResourceConfig customResourceConfig() { |
| 74 | + return new ResourceConfig(); |
| 75 | + } |
| 76 | + |
| 77 | + } |
| 78 | + |
| 79 | +} |
0 commit comments