|
16 | 16 |
|
17 | 17 | package io.zonky.test.db.postgres; |
18 | 18 |
|
| 19 | +import com.google.common.collect.ImmutableMap; |
19 | 20 | import io.zonky.test.db.AutoConfigureEmbeddedDatabase; |
20 | 21 | import io.zonky.test.db.AutoConfigureEmbeddedDatabase.EmbeddedDatabaseType; |
21 | 22 | import io.zonky.test.db.AutoConfigureEmbeddedDatabase.Replace; |
|
39 | 40 | import org.springframework.context.ConfigurableApplicationContext; |
40 | 41 | import org.springframework.context.support.AbstractApplicationContext; |
41 | 42 | import org.springframework.core.annotation.AnnotatedElementUtils; |
| 43 | +import org.springframework.core.env.ConfigurableEnvironment; |
| 44 | +import org.springframework.core.env.MapPropertySource; |
42 | 45 | import org.springframework.test.context.ContextConfigurationAttributes; |
43 | 46 | import org.springframework.test.context.ContextCustomizer; |
44 | 47 | import org.springframework.test.context.ContextCustomizerFactory; |
@@ -86,6 +89,8 @@ public PreloadableEmbeddedPostgresContextCustomizer(AutoConfigureEmbeddedDatabas |
86 | 89 |
|
87 | 90 | @Override |
88 | 91 | public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { |
| 92 | + context.addBeanFactoryPostProcessor(new EnvironmentPostProcessor(context.getEnvironment())); |
| 93 | + |
89 | 94 | Class<?> testClass = mergedConfig.getTestClass(); |
90 | 95 | FlywayTest[] flywayAnnotations = findFlywayTestAnnotations(testClass); |
91 | 96 |
|
@@ -118,6 +123,27 @@ public int hashCode() { |
118 | 123 | } |
119 | 124 | } |
120 | 125 |
|
| 126 | + protected static class EnvironmentPostProcessor implements BeanDefinitionRegistryPostProcessor { |
| 127 | + |
| 128 | + private final ConfigurableEnvironment environment; |
| 129 | + |
| 130 | + public EnvironmentPostProcessor(ConfigurableEnvironment environment) { |
| 131 | + this.environment = environment; |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { |
| 136 | + environment.getPropertySources().addFirst(new MapPropertySource( |
| 137 | + PreloadableEmbeddedPostgresContextCustomizer.class.getSimpleName(), |
| 138 | + ImmutableMap.of("spring.test.database.replace", "NONE"))); |
| 139 | + } |
| 140 | + |
| 141 | + @Override |
| 142 | + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { |
| 143 | + // nothing to do |
| 144 | + } |
| 145 | + } |
| 146 | + |
121 | 147 | protected static class PreloadableEmbeddedPostgresRegistrar implements BeanDefinitionRegistryPostProcessor { |
122 | 148 |
|
123 | 149 | private final AutoConfigureEmbeddedDatabase databaseAnnotation; |
|
0 commit comments