Browse Source

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

Closes gh-16998
pull/20830/head
Stephane Nicoll 6 years ago
parent
commit
f4c68dbc98
  1. 17
      spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java

17
spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java

@ -23,10 +23,6 @@ import java.util.List; @@ -23,10 +23,6 @@ import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.SpringApplication;
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.mock.web.SpringBootMockServletContext;
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
disableJmx(properties);
properties.addAll(Arrays.asList(config.getPropertySourceProperties()));
if (!isEmbeddedWebEnvironment(config) && !hasCustomServerPort(properties)) {
properties.add("server.port=-1");
}
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");
}
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
* to the context. By default this method will adapt {@link ContextCustomizer context

Loading…
Cancel
Save