|
|
@ -15,6 +15,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package org.springframework.boot.test.web;
|
|
|
|
package org.springframework.boot.test.web;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
@ -99,13 +100,10 @@ public class SpringBootTestRandomPortEnvironmentPostProcessorTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDefaultSameInProduction() {
|
|
|
|
public void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDefaultSameInProduction() {
|
|
|
|
// mgmt port is 8080 which means it's on the same port as main server since that
|
|
|
|
// mgmt port is 8080 which means it's on the same port as main server since that
|
|
|
|
// is
|
|
|
|
// is null in app properties
|
|
|
|
// null in app properties
|
|
|
|
|
|
|
|
addTestPropertySource("0", null);
|
|
|
|
addTestPropertySource("0", null);
|
|
|
|
Map<String, Object> other = new HashMap<>();
|
|
|
|
this.propertySources.addLast(new MapPropertySource("other",
|
|
|
|
other.put("management.server.port", "8080");
|
|
|
|
Collections.singletonMap("management.server.port", "8080")));
|
|
|
|
MapPropertySource otherSource = new MapPropertySource("other", other);
|
|
|
|
|
|
|
|
this.propertySources.addLast(otherSource);
|
|
|
|
|
|
|
|
this.postProcessor.postProcessEnvironment(this.environment, null);
|
|
|
|
this.postProcessor.postProcessEnvironment(this.environment, null);
|
|
|
|
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
|
|
|
|
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
|
|
|
|
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("");
|
|
|
|
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("");
|
|
|
@ -114,10 +112,8 @@ public class SpringBootTestRandomPortEnvironmentPostProcessorTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDifferentInProduction() {
|
|
|
|
public void postProcessWhenTestServerPortIsZeroAndManagementPortIsNotNullAndDifferentInProduction() {
|
|
|
|
addTestPropertySource("0", null);
|
|
|
|
addTestPropertySource("0", null);
|
|
|
|
Map<String, Object> other = new HashMap<>();
|
|
|
|
this.propertySources.addLast(new MapPropertySource("other",
|
|
|
|
other.put("management.server.port", "8081");
|
|
|
|
Collections.singletonMap("management.server.port", "8081")));
|
|
|
|
MapPropertySource otherSource = new MapPropertySource("other", other);
|
|
|
|
|
|
|
|
this.propertySources.addLast(otherSource);
|
|
|
|
|
|
|
|
this.postProcessor.postProcessEnvironment(this.environment, null);
|
|
|
|
this.postProcessor.postProcessEnvironment(this.environment, null);
|
|
|
|
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
|
|
|
|
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
|
|
|
|
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
|
|
|
|
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
|
|
|
@ -126,10 +122,8 @@ public class SpringBootTestRandomPortEnvironmentPostProcessorTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void postProcessWhenTestServerPortIsZeroAndManagementPortMinusOne() {
|
|
|
|
public void postProcessWhenTestServerPortIsZeroAndManagementPortMinusOne() {
|
|
|
|
addTestPropertySource("0", null);
|
|
|
|
addTestPropertySource("0", null);
|
|
|
|
Map<String, Object> other = new HashMap<>();
|
|
|
|
this.propertySources.addLast(new MapPropertySource("other",
|
|
|
|
other.put("management.server.port", "-1");
|
|
|
|
Collections.singletonMap("management.server.port", "-1")));
|
|
|
|
MapPropertySource otherSource = new MapPropertySource("other", other);
|
|
|
|
|
|
|
|
this.propertySources.addLast(otherSource);
|
|
|
|
|
|
|
|
this.postProcessor.postProcessEnvironment(this.environment, null);
|
|
|
|
this.postProcessor.postProcessEnvironment(this.environment, null);
|
|
|
|
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
|
|
|
|
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
|
|
|
|
assertThat(this.environment.getProperty("management.server.port"))
|
|
|
|
assertThat(this.environment.getProperty("management.server.port"))
|
|
|
|