Search in sources :

Example 6 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class AnsiOutputApplicationListenerTests method disabled.

@Test
public void disabled() throws Exception {
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    Map<String, Object> props = new HashMap<>();
    props.put("spring.output.ansi.enabled", "never");
    application.setDefaultProperties(props);
    this.context = application.run();
    assertThat(AnsiOutputEnabledValue.get()).isEqualTo(Enabled.NEVER);
}
Also used : HashMap(java.util.HashMap) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 7 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method propertySourceAnnotationMultipleLocations.

@Test
public void propertySourceAnnotationMultipleLocations() throws Exception {
    SpringApplication application = new SpringApplication(WithPropertySourceMultipleLocations.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("class path resource " + "[specificlocation.properties]"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 8 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method propertySourceAnnotationWithPlaceholder.

@Test
public void propertySourceAnnotationWithPlaceholder() throws Exception {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "source.location=specificlocation");
    SpringApplication application = new SpringApplication(WithPropertySourcePlaceholders.class);
    application.setEnvironment(this.environment);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableApplicationContext context = application.run();
    String property = context.getEnvironment().getProperty("the.property");
    assertThat(property).isEqualTo("fromspecificlocation");
    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 9 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method profileSubDocumentInDifferentProfileSpecificFile.

@Test
public void profileSubDocumentInDifferentProfileSpecificFile() throws Exception {
    // gh-4132
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = application.run("--spring.profiles.active=activeprofilewithdifferentsubdoc,activeprofilewithdifferentsubdoc2");
    String property = this.context.getEnvironment().getProperty("foobar");
    assertThat(property).isEqualTo("baz");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 10 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class ConfigFileApplicationListenerTests method additionalProfilesCanBeIncludedFromAnyPropertySource.

@Test
public void additionalProfilesCanBeIncludedFromAnyPropertySource() throws Exception {
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = application.run("--spring.profiles.active=myprofile", "--spring.profiles.include=dev");
    String property = this.context.getEnvironment().getProperty("my.property");
    assertThat(property).isEqualTo("fromdevpropertiesfile");
    assertThat(this.context.getEnvironment().containsProperty("customdefault")).isFalse();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) 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