How to load application.yaml config in spring-boot configuration for selenium testing -


i trying run selenium tests agains spring-boot app. want start app properties application.yml , application-test.yml define. however, default doesn't happen.

i have tried dave syer suggested , have implemented applicationcontextinitializer reads application.yml , application-test.yml files using yamlpropertysourceloader.

this doesn't seem have effect- setting server port 9000 in application-test has no effect.

below 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 code 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 application-test.yml

server:   port: 9000 

@contextconfiguration doesn't know spring boot initializers. did try @springapplicationconfiguration? (then wouldn't need custom initializer.)


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -