private static final String LINE_SEPARATOR = System.getProperty("line.separator");
@Override
public ApplicationContext loadContext(MergedContextConfiguration config)
throws Exception {
SpringApplication application = getSpringApplication();
application.setSources(getSources(config));
ConfigurableEnvironment environment = new StandardEnvironment();
if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
String profiles = StringUtils.arrayToCommaDelimitedString(config
.getActiveProfiles());
EnvironmentTestUtils.addEnvironment(environment, "spring.profiles.active="
+ profiles);
}
// Ensure @IntegrationTest properties go before external config and after system
environment.getPropertySources()
.addAfter(
StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
new MapPropertySource("integrationTest",
getEnvironmentProperties(config)));
application.setEnvironment(environment);
List<ApplicationContextInitializer<?>> initializers = getInitializers(config,
application);
if (config instanceof WebMergedContextConfiguration) {
new WebConfigurer().configure(config, application, initializers);
}
else {
application.setWebEnvironment(false);
}
application.setInitializers(initializers);
return application.run();
}