|
23 | 23 | import eu.openanalytics.containerproxy.ContainerProxyApplication;
|
24 | 24 | import org.springframework.context.ApplicationContextInitializer;
|
25 | 25 | import org.springframework.context.ConfigurableApplicationContext;
|
| 26 | +import org.springframework.core.env.MutablePropertySources; |
26 | 27 | import org.springframework.core.env.PropertiesPropertySource;
|
| 28 | +import org.springframework.core.env.PropertySource; |
27 | 29 | import org.springframework.test.context.support.TestPropertySourceUtils;
|
28 | 30 |
|
| 31 | +import javax.annotation.Nonnull; |
| 32 | +import java.util.stream.Collectors; |
| 33 | + |
29 | 34 | public class PropertyOverrideContextInitializer
|
30 |
| - implements ApplicationContextInitializer<ConfigurableApplicationContext> { |
| 35 | + implements ApplicationContextInitializer<ConfigurableApplicationContext> { |
| 36 | + |
| 37 | + @Override |
| 38 | + public void initialize(@Nonnull ConfigurableApplicationContext configurableApplicationContext) { |
| 39 | + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(configurableApplicationContext, |
| 40 | + "proxy.kubernetes.namespace=" + TestIntegrationOnKube.namespace); |
31 | 41 |
|
32 |
| - @Override |
33 |
| - public void initialize(ConfigurableApplicationContext configurableApplicationContext) { |
34 |
| - TestPropertySourceUtils.addInlinedPropertiesToEnvironment(configurableApplicationContext, |
35 |
| - "proxy.kubernetes.namespace=" + TestIntegrationOnKube.namespace); |
| 42 | + MutablePropertySources propertySources = configurableApplicationContext.getEnvironment().getPropertySources(); |
| 43 | + PropertiesPropertySource defaultProperties = new PropertiesPropertySource("shinyProxyDefaultProperties", ContainerProxyApplication.getDefaultProperties()); |
| 44 | + propertySources.addFirst(defaultProperties); |
36 | 45 |
|
37 |
| - PropertiesPropertySource defaultProperties = new PropertiesPropertySource("shinyProxyDefaultProperties", ContainerProxyApplication.getDefaultProperties()); |
38 |
| - configurableApplicationContext.getEnvironment().getPropertySources().addFirst(defaultProperties); |
| 46 | + // remove any external, file-based property source |
| 47 | + // we don't want any application.yml or application.properties to be loaded during the tests |
| 48 | + propertySources |
| 49 | + .stream() |
| 50 | + .map(PropertySource::getName) |
| 51 | + .filter(p -> p.contains("Config resource 'file ") && p.contains("via location 'optional:file:./'")) |
| 52 | + .collect(Collectors.toList()) |
| 53 | + .forEach(propertySources::remove); |
39 | 54 |
|
40 |
| - } |
| 55 | + } |
41 | 56 | }
|
0 commit comments