use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class ConditionEvaluationReportLoggingListenerTests method logsDebugOnError.
@Test
void logsDebugOnError(CapturedOutput output) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
this.initializer.initialize(context);
context.register(ErrorConfig.class);
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh).satisfies((ex) -> withDebugLogging(() -> this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex))));
assertThat(output).contains("CONDITIONS EVALUATION REPORT");
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class SpringApplicationTests method deregistersShutdownHookForFailedApplicationContext.
@Test
void deregistersShutdownHookForFailedApplicationContext() {
SpringApplication application = new SpringApplication(BrokenPostConstructConfig.class);
List<ApplicationEvent> events = new ArrayList<>();
application.addListeners(events::add);
application.setWebApplicationType(WebApplicationType.NONE);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(application::run);
assertThat(events).hasAtLeastOneElementOfType(ApplicationFailedEvent.class);
ApplicationFailedEvent failure = events.stream().filter((event) -> event instanceof ApplicationFailedEvent).map(ApplicationFailedEvent.class::cast).findFirst().get();
assertThat(SpringApplicationShutdownHookInstance.get()).didNotRegisterApplicationContext(failure.getApplicationContext());
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class EnvironmentPostProcessorApplicationListenerTests method onApplicationEventWhenApplicationFailedEventSwitchesLogs.
@Test
void onApplicationEventWhenApplicationFailedEventSwitchesLogs() {
SpringApplication application = mock(SpringApplication.class);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
ApplicationFailedEvent event = new ApplicationFailedEvent(application, new String[0], context, new RuntimeException());
this.listener.onApplicationEvent(event);
then(this.deferredLogs).should().switchOverAll();
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class AutoConfigurationReportLoggingInitializerTests method logsDebugOnError.
@Test
public void logsDebugOnError() {
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()).isNotEqualTo(0);
assertThat(this.infoLog.size()).isEqualTo(0);
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class AutoConfigurationReportLoggingInitializerTests method noErrorIfNotInitialized.
@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)).contains("Unable to provide auto-configuration report");
}
Aggregations