Example usage for org.springframework.boot.context.event ApplicationFailedEvent ApplicationFailedEvent

List of usage examples for org.springframework.boot.context.event ApplicationFailedEvent ApplicationFailedEvent

Introduction

In this page you can find the example usage for org.springframework.boot.context.event ApplicationFailedEvent ApplicationFailedEvent.

Prototype

public ApplicationFailedEvent(SpringApplication application, String[] args,
        ConfigurableApplicationContext context, Throwable exception) 

Source Link

Document

Create a new ApplicationFailedEvent instance.

Usage

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsDebugOnError() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {/*from  ww w  . jav a  2  s.  co  m*/
        context.refresh();
        fail("Did not error");
    } catch (Exception ex) {
        this.initializer.onApplicationEvent(
                new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex));
    }

    assertThat(this.debugLog.size(), not(equalTo(0)));
    assertThat(this.infoLog.size(), equalTo(0));
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsInfoOnErrorIfDebugDisabled() {
    setupLogging(false, true);//from  w w  w .  j a  v a  2  s.  com
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {
        context.refresh();
        fail("Did not error");
    } catch (Exception ex) {
        this.initializer.onApplicationEvent(
                new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex));
    }

    assertThat(this.debugLog.size(), equalTo(0));
    assertThat(this.infoLog.size(), not(equalTo(0)));
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void noErrorIfNotInitialized() throws Exception {
    this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], null,
            new RuntimeException("Planned")));
    assertThat(this.infoLog.get(0), containsString("Unable to provide auto-configuration report"));
}

From source file:org.springframework.boot.context.event.EventPublishingRunListener.java

@Override
public void failed(ConfigurableApplicationContext context, Throwable exception) {
    ApplicationFailedEvent event = new ApplicationFailedEvent(this.application, this.args, context, exception);
    if (context != null && context.isActive()) {
        // Listeners have been registered to the application context so we should
        // use it at this point if we can
        context.publishEvent(event);/*  www .j a va2 s .  co m*/
    } else {
        // An inactive context may not have a multicaster so we use our multicaster to
        // call all of the context's listeners instead
        if (context instanceof AbstractApplicationContext) {
            for (ApplicationListener<?> listener : ((AbstractApplicationContext) context)
                    .getApplicationListeners()) {
                this.initialMulticaster.addApplicationListener(listener);
            }
        }
        this.initialMulticaster.setErrorHandler(new LoggingErrorHandler());
        this.initialMulticaster.multicastEvent(event);
    }
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Test
public void applicationFailedEventCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    multicastEvent(new ApplicationFailedEvent(this.springApplication, new String[0],
            new GenericApplicationContext(), new Exception()));
    assertThat(loggingSystem.cleanedUp).isTrue();
}