Commit f4c68dbc authored by Stephane Nicoll's avatar Stephane Nicoll

Do not set server.port=-1 for non embedded tests

Closes gh-16998
parent 1199b7c0
...@@ -23,10 +23,6 @@ import java.util.List; ...@@ -23,10 +23,6 @@ import java.util.List;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType; import org.springframework.boot.WebApplicationType;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.mock.web.SpringBootMockServletContext; import org.springframework.boot.test.mock.web.SpringBootMockServletContext;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
...@@ -166,9 +162,6 @@ public class SpringBootContextLoader extends AbstractContextLoader { ...@@ -166,9 +162,6 @@ public class SpringBootContextLoader extends AbstractContextLoader {
// JMX bean names will clash if the same bean is used in multiple contexts // JMX bean names will clash if the same bean is used in multiple contexts
disableJmx(properties); disableJmx(properties);
properties.addAll(Arrays.asList(config.getPropertySourceProperties())); properties.addAll(Arrays.asList(config.getPropertySourceProperties()));
if (!isEmbeddedWebEnvironment(config) && !hasCustomServerPort(properties)) {
properties.add("server.port=-1");
}
return StringUtils.toStringArray(properties); return StringUtils.toStringArray(properties);
} }
...@@ -176,16 +169,6 @@ public class SpringBootContextLoader extends AbstractContextLoader { ...@@ -176,16 +169,6 @@ public class SpringBootContextLoader extends AbstractContextLoader {
properties.add("spring.jmx.enabled=false"); properties.add("spring.jmx.enabled=false");
} }
private boolean hasCustomServerPort(List<String> properties) {
Binder binder = new Binder(convertToConfigurationPropertySource(properties));
return binder.bind("server.port", Bindable.of(String.class)).isBound();
}
private ConfigurationPropertySource convertToConfigurationPropertySource(List<String> properties) {
return new MapConfigurationPropertySource(
TestPropertySourceUtils.convertInlinedPropertiesToMap(StringUtils.toStringArray(properties)));
}
/** /**
* Return the {@link ApplicationContextInitializer initializers} that will be applied * Return the {@link ApplicationContextInitializer initializers} that will be applied
* to the context. By default this method will adapt {@link ContextCustomizer context * to the context. By default this method will adapt {@link ContextCustomizer context
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment