Revert "Add profiles directly to the application environment for tests"

This reverts commit 487b9cbf96.

Fixes gh-19788
This commit is contained in:
Andy Wilkinson
2020-01-20 14:55:20 +00:00
parent 11efe172e9
commit c85f19b75b
2 changed files with 8 additions and 45 deletions

View File

@@ -28,6 +28,7 @@ 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.mock.web.SpringBootMockServletContext;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;
import org.springframework.boot.web.servlet.support.ServletContextApplicationContextInitializer;
import org.springframework.context.ApplicationContext;
@@ -92,7 +93,7 @@ public class SpringBootContextLoader extends AbstractContextLoader {
application.getSources().addAll(Arrays.asList(configLocations));
ConfigurableEnvironment environment = getEnvironment();
if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
environment.setActiveProfiles(config.getActiveProfiles());
setActiveProfiles(environment, config.getActiveProfiles());
}
ResourceLoader resourceLoader = (application.getResourceLoader() != null) ? application.getResourceLoader()
: new DefaultResourceLoader(getClass().getClassLoader());
@@ -138,6 +139,11 @@ public class SpringBootContextLoader extends AbstractContextLoader {
return new StandardEnvironment();
}
private void setActiveProfiles(ConfigurableEnvironment environment, String[] profiles) {
TestPropertyValues.of("spring.profiles.active=" + StringUtils.arrayToCommaDelimitedString(profiles))
.applyTo(environment);
}
protected String[] getInlinedProperties(MergedContextConfiguration config) {
ArrayList<String> properties = new ArrayList<>();
// JMX bean names will clash if the same bean is used in multiple contexts