Merge branch '2.1.x'

Closes gh-16473
This commit is contained in:
Andy Wilkinson
2019-04-05 17:37:24 +01:00
2 changed files with 22 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,9 @@
*/
package org.springframework.boot.actuate.autoconfigure.web.server;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Rule;
import org.junit.Test;
@@ -33,28 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link ManagementContextAutoConfiguration}.
*
* @author Madhura Bhave
* @author Andy Wilkinson
*/
public class ManagementContextAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(
AutoConfigurations.of(ManagementContextAutoConfiguration.class,
ServletManagementContextAutoConfiguration.class));
@Rule
public OutputCapture output = new OutputCapture();
@Test
public void managementServerPortShouldBeIgnoredForNonEmbeddedServer() {
this.contextRunner.withPropertyValues("management.server.port=8081")
.run((context) -> {
assertThat(context.getStartupFailure()).isNull();
assertThat(this.output.toString())
.contains("Could not start embedded management container on "
+ "different port (management endpoints are still available through JMX)");
});
}
@Test
public void childManagementContextShouldStartForEmbeddedServer() {
WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(
@@ -65,10 +53,19 @@ public class ManagementContextAutoConfigurationTests {
ServletManagementContextAutoConfiguration.class,
WebEndpointAutoConfiguration.class,
EndpointAutoConfiguration.class));
contextRunner.withPropertyValues("management.server.port=8081")
.run((context) -> assertThat(this.output.toString()).doesNotContain(
"Could not start embedded management container on "
+ "different port (management endpoints are still available through JMX)"));
contextRunner.withPropertyValues("server.port=0", "management.server.port=0").run(
(context) -> assertThat(tomcatStartedOccurencesIn(this.output.toString()))
.isEqualTo(2));
}
private int tomcatStartedOccurencesIn(String output) {
int matches = 0;
Matcher matcher = Pattern.compile("Tomcat started on port").matcher(output);
while (matcher.find()) {
matches++;
}
return matches;
}
}