Skip to content

Commit 2f3e5d6

Browse files
nosanmbhave
authored andcommitted
Test server port shouldn't affect management port when random
Closes gh-16108
1 parent 07d95ce commit 2f3e5d6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public void postProcessEnvironment(ConfigurableEnvironment environment,
5252
}
5353
Integer managementPort = getPropertyAsInteger(environment,
5454
MANAGEMENT_PORT_PROPERTY, null);
55-
if (managementPort == null || managementPort.equals(-1)) {
55+
if (managementPort == null || managementPort.equals(-1)
56+
|| managementPort.equals(0)) {
5657
return;
5758
}
5859
Integer serverPort = getPropertyAsInteger(environment, SERVER_PORT_PROPERTY,

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/web/SpringBootTestRandomPortEnvironmentPostProcessorTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,6 +58,17 @@ public void postProcessWhenServerAndManagementPortIsZeroInTestPropertySource() {
5858
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
5959
}
6060

61+
@Test
62+
public void postProcessWhenServerPortAndManagementPortIsZeroInDifferentPropertySources() {
63+
addTestPropertySource("0", null);
64+
Map<String, Object> source = new HashMap<>();
65+
source.put("management.server.port", "0");
66+
this.propertySources.addLast(new MapPropertySource("other", source));
67+
this.postProcessor.postProcessEnvironment(this.environment, null);
68+
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
69+
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
70+
}
71+
6172
@Test
6273
public void postProcessWhenTestServerAndTestManagementPortAreNonZero() {
6374
addTestPropertySource("8080", "8081");

0 commit comments

Comments
 (0)