|
|
@ -42,15 +42,23 @@ public class ConfigFileApplicationContextInitializerTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void loadPropertiesFile() throws Exception {
|
|
|
|
public void loadPropertiesFile() throws Exception {
|
|
|
|
this.initializer.setName("testproperties");
|
|
|
|
this.initializer.setNames("testproperties");
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
assertThat(property, equalTo("frompropertiesfile"));
|
|
|
|
assertThat(property, equalTo("frompropertiesfile"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void loadTwoPropertiesFiles() throws Exception {
|
|
|
|
|
|
|
|
this.initializer.setNames("testproperties,moreproperties");
|
|
|
|
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
|
|
|
|
assertThat(property, equalTo("frommorepropertiesfile"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void loadYamlFile() throws Exception {
|
|
|
|
public void loadYamlFile() throws Exception {
|
|
|
|
this.initializer.setName("testyaml");
|
|
|
|
this.initializer.setNames("testyaml");
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
assertThat(property, equalTo("fromyamlfile"));
|
|
|
|
assertThat(property, equalTo("fromyamlfile"));
|
|
|
@ -67,7 +75,7 @@ public class ConfigFileApplicationContextInitializerTests {
|
|
|
|
.addFirst(
|
|
|
|
.addFirst(
|
|
|
|
new SimpleCommandLinePropertySource(
|
|
|
|
new SimpleCommandLinePropertySource(
|
|
|
|
"--my.property=fromcommandline"));
|
|
|
|
"--my.property=fromcommandline"));
|
|
|
|
this.initializer.setName("testproperties");
|
|
|
|
this.initializer.setNames("testproperties");
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
assertThat(property, equalTo("fromcommandline"));
|
|
|
|
assertThat(property, equalTo("fromcommandline"));
|
|
|
@ -75,7 +83,7 @@ public class ConfigFileApplicationContextInitializerTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void loadPropertiesThenProfileProperties() throws Exception {
|
|
|
|
public void loadPropertiesThenProfileProperties() throws Exception {
|
|
|
|
this.initializer.setName("enableprofile");
|
|
|
|
this.initializer.setNames("enableprofile");
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
assertThat(property, equalTo("fromprofilepropertiesfile"));
|
|
|
|
assertThat(property, equalTo("fromprofilepropertiesfile"));
|
|
|
@ -83,7 +91,7 @@ public class ConfigFileApplicationContextInitializerTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void yamlProfiles() throws Exception {
|
|
|
|
public void yamlProfiles() throws Exception {
|
|
|
|
this.initializer.setName("testprofiles");
|
|
|
|
this.initializer.setNames("testprofiles");
|
|
|
|
this.context.getEnvironment().setActiveProfiles("dev");
|
|
|
|
this.context.getEnvironment().setActiveProfiles("dev");
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
@ -94,7 +102,7 @@ public class ConfigFileApplicationContextInitializerTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void yamlSetsProfiles() throws Exception {
|
|
|
|
public void yamlSetsProfiles() throws Exception {
|
|
|
|
this.initializer.setName("testsetprofiles");
|
|
|
|
this.initializer.setNames("testsetprofiles");
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
this.initializer.initialize(this.context);
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
String property = this.context.getEnvironment().getProperty("my.property");
|
|
|
|
assertThat(property, equalTo("fromdevprofile"));
|
|
|
|
assertThat(property, equalTo("fromdevprofile"));
|
|
|
|