Search in sources :

Example 1 with ApplicationFailedEvent

use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.

the class AutoConfigurationReportLoggingInitializerTests method logsInfoOnErrorIfDebugDisabled.

@Test
public void logsInfoOnErrorIfDebugDisabled() {
    setupLogging(false, true);
    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()).isEqualTo(0);
    assertThat(this.infoLog.size()).isNotEqualTo(0);
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) LogConfigurationException(org.apache.commons.logging.LogConfigurationException) Test(org.junit.Test)

Example 2 with ApplicationFailedEvent

use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method onDifferentPortWithPrimaryFailure.

@Test
public void onDifferentPortWithPrimaryFailure() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    ApplicationFailedEvent event = mock(ApplicationFailedEvent.class);
    given(event.getApplicationContext()).willReturn(this.applicationContext);
    this.applicationContext.publishEvent(event);
    assertThat(((ConfigurableApplicationContext) managementContext).isActive()).isFalse();
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Test(org.junit.Test)

Example 3 with ApplicationFailedEvent

use of org.springframework.boot.context.event.ApplicationFailedEvent in project pinpoint by naver.

the class EnvironmentLoggingListener method onApplicationEvent.

@Override
public void onApplicationEvent(SpringApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        ApplicationEnvironmentPreparedEvent prepared = (ApplicationEnvironmentPreparedEvent) event;
        ConfigurableEnvironment environment = prepared.getEnvironment();
        logPropertySource(event, environment);
    } else if (event instanceof ApplicationStartedEvent) {
        ApplicationStartedEvent started = (ApplicationStartedEvent) event;
        ConfigurableEnvironment environment = started.getApplicationContext().getEnvironment();
        logPropertySource(event, environment);
    } else if (event instanceof ApplicationFailedEvent) {
        ApplicationFailedEvent failed = (ApplicationFailedEvent) event;
        ConfigurableEnvironment environment = failed.getApplicationContext().getEnvironment();
        logPropertySource(event, environment);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("ApplicationEvent:{}", event.getClass().getSimpleName());
        }
    }
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ApplicationStartedEvent(org.springframework.boot.context.event.ApplicationStartedEvent) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)

Example 4 with ApplicationFailedEvent

use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method applicationFailedEventCleansUpLoggingSystem.

@Test
void applicationFailedEventCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.bootstrapContext, 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();
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) IOException(java.io.IOException) BindException(org.springframework.boot.context.properties.bind.BindException) Test(org.junit.jupiter.api.Test)

Example 5 with ApplicationFailedEvent

use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.

the class ConditionEvaluationReportLoggingListenerTests method noErrorIfNotInitialized.

@Test
void noErrorIfNotInitialized(CapturedOutput output) {
    this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], null, new RuntimeException("Planned")));
    assertThat(output).contains("Unable to provide the conditions report");
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)13 SpringApplication (org.springframework.boot.SpringApplication)9 Test (org.junit.jupiter.api.Test)6 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 Test (org.junit.Test)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)3 IOException (java.io.IOException)2 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)2 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)2 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)2 ApplicationStartedEvent (org.springframework.boot.context.event.ApplicationStartedEvent)2 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1