Search in sources :

Example 11 with SpringApplication

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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 12 with SpringApplication

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"));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 13 with SpringApplication

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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 14 with SpringApplication

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");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 15 with SpringApplication

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");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent) Test(org.junit.Test)

Aggregations

SpringApplication (org.springframework.boot.SpringApplication)63 Test (org.junit.Test)45 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)14 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 HashMap (java.util.HashMap)6 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)4 JoranException (ch.qos.logback.core.joran.spi.JoranException)3 ObjectName (javax.management.ObjectName)3 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)3 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)3 JavaLoggingSystem (org.springframework.boot.logging.java.JavaLoggingSystem)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 StandardEnvironment (org.springframework.core.env.StandardEnvironment)3 File (java.io.File)2 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)2 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)2 AbstractLoggingSystem (org.springframework.boot.logging.AbstractLoggingSystem)2 LoggingSystem (org.springframework.boot.logging.LoggingSystem)2