I am trying to run selenium tests agains my spring-boot app. I want to start the app with the properties my application.yml and application-test.yml define. However, by default this doesn't happen.
I have tried to do as Dave Syer suggested and have implemented an ApplicationContextInitializer that reads the application.yml and application-test.yml files using a YamlPropertySourceLoader.
This doesn't seem to have any effect- setting the server port to 9000 in my application-test has no effect.
Below is my Test Base Class code:
@ContextConfiguration(classes = {TestConfiguration.class}, initializers = {TestApplicationYamlLoaderApplicationContextInitializer.class})
@SharedDriver(type = SharedDriver.SharedType.ONCE)
@ActiveProfiles({"test"})
public abstract class IntegrationBase extends AbstractTestNGSpringContextTests {
....
}
Below is the code for my ApplicationContextInitializer:
public class TestApplicationYamlLoaderApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment env = applicationContext.getEnvironment();
YamlPropertySourceLoader loader = YamlPropertySourceLoader.matchAllLoader();
PropertySource applicationYamlPropertySource = loader.load("application.yml", new FileSystemResource("src/main/resources/application.yml"));
PropertySource testProfileYamlPropertySource = loader.load("application.yml", new FileSystemResource("src/main/resources/application-test.yml"));
env.getPropertySources().addFirst(applicationYamlPropertySource);
env.getPropertySources().addFirst(testProfileYamlPropertySource);
System.out.println("woohoo!");
}
}
And the application-test.yml
server:
port: 9000