Search in sources :

Example 6 with DefaultBootstrapContext

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

the class RestartApplicationListenerTests method testInitialize.

private void testInitialize(boolean failed) {
    Restarter.clearInstance();
    RestartApplicationListener listener = new RestartApplicationListener();
    DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext();
    SpringApplication application = new SpringApplication();
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    listener.onApplicationEvent(new ApplicationStartingEvent(bootstrapContext, application, ARGS));
    assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
    assertThat(Restarter.getInstance().isFinished()).isFalse();
    listener.onApplicationEvent(new ApplicationPreparedEvent(application, ARGS, context));
    if (failed) {
        listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS, context, new RuntimeException()));
    } else {
        listener.onApplicationEvent(new ApplicationReadyEvent(application, ARGS, context, null));
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationPreparedEvent(org.springframework.boot.context.event.ApplicationPreparedEvent) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent)

Example 7 with DefaultBootstrapContext

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

the class DelegatingApplicationListenerTests method emptyInitializers.

@Test
void emptyInitializers() {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes:");
    this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new DefaultBootstrapContext(), new SpringApplication(), new String[0], this.context.getEnvironment()));
}
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)

Aggregations

DefaultBootstrapContext (org.springframework.boot.DefaultBootstrapContext)7 SpringApplication (org.springframework.boot.SpringApplication)4 Test (org.junit.jupiter.api.Test)3 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)2 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)2 DeferredLogFactory (org.springframework.boot.logging.DeferredLogFactory)2 File (java.io.File)1 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)1 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)1 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1