Search in sources :

Example 61 with SpringApplication

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

the class DelegatingApplicationListenerTests method orderedInitialize.

@Test
void orderedInitialize() {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes=" + MockInitB.class.getName() + "," + MockInitA.class.getName());
    this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new DefaultBootstrapContext(), 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 : DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext) SpringApplication(org.springframework.boot.SpringApplication) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent) Test(org.junit.jupiter.api.Test)

Example 62 with SpringApplication

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

the class LocalDevToolsAutoConfigurationTests method initializeAndRun.

private ConfigurableApplicationContext initializeAndRun(Class<?> config, Map<String, Object> properties, String... args) {
    Restarter.initialize(new String[0], false, new MockRestartInitializer(), false);
    SpringApplication application = new SpringApplication(config);
    application.setDefaultProperties(getDefaultProperties(properties));
    return application.run(args);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) MockRestartInitializer(org.springframework.boot.devtools.restart.MockRestartInitializer)

Example 63 with SpringApplication

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

the class DevToolPropertiesIntegrationTests method postProcessEnablesIncludeStackTraceProperty.

@Test
void postProcessEnablesIncludeStackTraceProperty() throws Exception {
    SpringApplication application = new SpringApplication(TestConfiguration.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = getContext(application::run);
    ConfigurableEnvironment environment = this.context.getEnvironment();
    String includeStackTrace = environment.getProperty("server.error.include-stacktrace");
    assertThat(includeStackTrace).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString());
    String includeMessage = environment.getProperty("server.error.include-message");
    assertThat(includeMessage).isEqualTo(ErrorProperties.IncludeAttribute.ALWAYS.toString());
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.jupiter.api.Test)

Example 64 with SpringApplication

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

the class DevToolPropertiesIntegrationTests method beanMethodPropertyConditionIsAffectedByDevToolProperties.

@Test
void beanMethodPropertyConditionIsAffectedByDevToolProperties() throws Exception {
    SpringApplication application = new SpringApplication(BeanConditionConfiguration.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = getContext(application::run);
    this.context.getBean(MyBean.class);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.jupiter.api.Test)

Example 65 with SpringApplication

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

the class ConfigurationPropertiesTests method loadWhenEnvironmentPrefixSetShouldBind.

@Test
@SuppressWarnings("unchecked")
void loadWhenEnvironmentPrefixSetShouldBind() {
    MutablePropertySources sources = this.context.getEnvironment().getPropertySources();
    sources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, Collections.singletonMap("MY_SPRING_FOO_NAME", "Jane")));
    SpringApplication application = new SpringApplication(PrefixConfiguration.class);
    application.setApplicationContextFactory((webApplicationType) -> ConfigurationPropertiesTests.this.context);
    application.setEnvironmentPrefix("my");
    application.setEnvironment(this.context.getEnvironment());
    application.run();
    BasicProperties bean = this.context.getBean(BasicProperties.class);
    assertThat(bean.name).isEqualTo("Jane");
}
Also used : SystemEnvironmentPropertySource(org.springframework.core.env.SystemEnvironmentPropertySource) SpringApplication(org.springframework.boot.SpringApplication) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.jupiter.api.Test)

Aggregations

SpringApplication (org.springframework.boot.SpringApplication)205 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)56 Test (org.junit.Test)43 Test (org.junit.jupiter.api.Test)39 Environment (org.springframework.core.env.Environment)21 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)15 HashMap (java.util.HashMap)9 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)9 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)9 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)9 File (java.io.File)7 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 JavaLoggingSystem (org.springframework.boot.logging.java.JavaLoggingSystem)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 JoranException (ch.qos.logback.core.joran.spi.JoranException)3 IOException (java.io.IOException)3