use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method propertySourceAnnotation.
@Test
public void propertySourceAnnotation() throws Exception {
SpringApplication application = new SpringApplication(WithPropertySource.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableApplicationContext context = application.run();
String property = context.getEnvironment().getProperty("the.property");
assertThat(property).isEqualTo("fromspecificlocation");
property = context.getEnvironment().getProperty("my.property");
assertThat(property).isEqualTo("fromapplicationproperties");
assertThat(context.getEnvironment()).has(matchingPropertySource("class path resource " + "[specificlocation.properties]"));
context.close();
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method activateProfileFromProfileSpecificProperties.
@Test
public void activateProfileFromProfileSpecificProperties() throws Exception {
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.profiles.active=includeprofile");
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment).has(matchingProfile("includeprofile"));
assertThat(environment).has(matchingProfile("specific"));
assertThat(environment).has(matchingProfile("morespecific"));
assertThat(environment).has(matchingProfile("yetmorespecific"));
assertThat(environment).doesNotHave(matchingProfile("missing"));
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method propertySourceAnnotationMultipleLocationsAndName.
@Test
public void propertySourceAnnotationMultipleLocationsAndName() throws Exception {
SpringApplication application = new SpringApplication(WithPropertySourceMultipleLocationsAndName.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableApplicationContext context = application.run();
String property = context.getEnvironment().getProperty("the.property");
assertThat(property).isEqualTo("frommorepropertiesfile");
assertThat(context.getEnvironment()).has(matchingPropertySource("foo"));
context.close();
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method profileSubDocumentInSameProfileSpecificFile.
@Test
public void profileSubDocumentInSameProfileSpecificFile() throws Exception {
// gh-340
SpringApplication application = new SpringApplication(Config.class);
application.setWebApplicationType(WebApplicationType.NONE);
this.context = application.run("--spring.profiles.active=activeprofilewithsubdoc");
String property = this.context.getEnvironment().getProperty("foobar");
assertThat(property).isEqualTo("baz");
}
use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.
the class DelegatingApplicationListenerTests method orderedInitialize.
@Test
public void orderedInitialize() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes=" + MockInitB.class.getName() + "," + MockInitA.class.getName());
this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new SpringApplication(), new String[0], this.context.getEnvironment()));
this.context.getBeanFactory().registerSingleton("testListener", this.listener);
this.context.refresh();
assertThat(this.context.getBeanFactory().getSingleton("a")).isEqualTo("a");
assertThat(this.context.getBeanFactory().getSingleton("b")).isEqualTo("b");
}
Aggregations