This commit is contained in:
Phillip Webb
2016-12-28 15:23:26 -08:00
parent 97d7ffd8e8
commit 8b69856fc9
22 changed files with 64 additions and 41 deletions

View File

@@ -38,6 +38,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySources;
import org.springframework.core.env.PropertySourcesPropertyResolver;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.DefaultResourceLoader;
@@ -160,15 +161,21 @@ public class SpringBootContextLoader extends AbstractContextLoader {
}
private boolean hasCustomServerPort(List<String> properties) {
Map<String, Object> props = TestPropertySourceUtils.convertInlinedPropertiesToMap(
properties.toArray(new String[properties.size()]));
MutablePropertySources sources = new MutablePropertySources();
sources.addFirst(new MapPropertySource("inline", props));
PropertySources sources = convertToPropertySources(properties);
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
new PropertySourcesPropertyResolver(sources), "server.");
return resolver.containsProperty("port");
}
private PropertySources convertToPropertySources(List<String> properties) {
Map<String, Object> source = TestPropertySourceUtils
.convertInlinedPropertiesToMap(
properties.toArray(new String[properties.size()]));
MutablePropertySources sources = new MutablePropertySources();
sources.addFirst(new MapPropertySource("inline", source));
return sources;
}
private List<ApplicationContextInitializer<?>> getInitializers(
MergedContextConfiguration config, SpringApplication application) {
List<ApplicationContextInitializer<?>> initializers = new ArrayList<ApplicationContextInitializer<?>>();