|
| 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 | +package org.springframework.boot.actuate.autoconfigure.web.server; |
| 17 | + |
| 18 | +import org.junit.Rule; |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; |
| 22 | +import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration; |
| 23 | +import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration; |
| 24 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 25 | +import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; |
| 26 | +import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
| 27 | +import org.springframework.boot.test.rule.OutputCapture; |
| 28 | +import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext; |
| 29 | + |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | + |
| 32 | +/** |
| 33 | + * Tests for {@link ManagementContextAutoConfiguration}. |
| 34 | + * |
| 35 | + * @author Madhura Bhave |
| 36 | + */ |
| 37 | +public class ManagementContextAutoConfigurationTests { |
| 38 | + |
| 39 | + private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() |
| 40 | + .withConfiguration( |
| 41 | + AutoConfigurations.of(ManagementContextAutoConfiguration.class, |
| 42 | + ServletManagementContextAutoConfiguration.class)); |
| 43 | + |
| 44 | + @Rule |
| 45 | + public OutputCapture output = new OutputCapture(); |
| 46 | + |
| 47 | + @Test |
| 48 | + public void managementServerPortShouldBeIgnoredForNonEmbeddedServer() { |
| 49 | + this.contextRunner.withPropertyValues("management.server.port=8081") |
| 50 | + .run((context) -> { |
| 51 | + assertThat(context.getStartupFailure()).isNull(); |
| 52 | + assertThat(this.output.toString()) |
| 53 | + .contains("Could not start embedded management container on " |
| 54 | + + "different port (management endpoints are still available through JMX)"); |
| 55 | + }); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void childManagementContextShouldStartForEmbeddedServer() { |
| 60 | + WebApplicationContextRunner contextRunner = new WebApplicationContextRunner( |
| 61 | + AnnotationConfigServletWebServerApplicationContext::new) |
| 62 | + .withConfiguration(AutoConfigurations.of( |
| 63 | + ManagementContextAutoConfiguration.class, |
| 64 | + ServletWebServerFactoryAutoConfiguration.class, |
| 65 | + ServletManagementContextAutoConfiguration.class, |
| 66 | + WebEndpointAutoConfiguration.class, |
| 67 | + EndpointAutoConfiguration.class)); |
| 68 | + contextRunner.withPropertyValues("management.server.port=8081") |
| 69 | + .run((context) -> assertThat(this.output.toString()).doesNotContain( |
| 70 | + "Could not start embedded management container on " |
| 71 | + + "different port (management endpoints are still available through JMX)")); |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments