|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
24 | 24 | import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointAutoConfiguration;
|
25 | 25 | import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementContextAutoConfiguration;
|
26 | 26 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
| 27 | +import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; |
27 | 28 | import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
|
28 | 29 | import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
29 | 30 | import org.springframework.boot.test.system.CapturedOutput;
|
@@ -54,6 +55,19 @@ void childManagementContextShouldStartForEmbeddedServer(CapturedOutput output) {
|
54 | 55 | .run((context) -> assertThat(output).satisfies(numberOfOccurrences("Tomcat started on port", 2)));
|
55 | 56 | }
|
56 | 57 |
|
| 58 | + @Test |
| 59 | + void givenSamePortManagementServerWhenManagementServerAddressIsConfiguredThenContextRefreshFails() { |
| 60 | + WebApplicationContextRunner contextRunner = new WebApplicationContextRunner( |
| 61 | + AnnotationConfigServletWebServerApplicationContext::new) |
| 62 | + .withConfiguration(AutoConfigurations.of(ManagementContextAutoConfiguration.class, |
| 63 | + ServletWebServerFactoryAutoConfiguration.class, |
| 64 | + ServletManagementContextAutoConfiguration.class, WebEndpointAutoConfiguration.class, |
| 65 | + EndpointAutoConfiguration.class, DispatcherServletAutoConfiguration.class)); |
| 66 | + contextRunner.withPropertyValues("server.port=0", "management.server.address=127.0.0.1") |
| 67 | + .run((context) -> assertThat(context).getFailure() |
| 68 | + .hasMessageStartingWith("Management-specific server address cannot be configured")); |
| 69 | + } |
| 70 | + |
57 | 71 | private <T extends CharSequence> Consumer<T> numberOfOccurrences(String substring, int expectedCount) {
|
58 | 72 | return (charSequence) -> {
|
59 | 73 | int count = StringUtils.countOccurrencesOf(charSequence.toString(), substring);
|
|
0 commit comments