Search in sources :

Example 1 with ApplicationFailedEvent

use of cn.taketoday.framework.context.event.ApplicationFailedEvent in project today-infrastructure by TAKETODAY.

the class ApplicationTests method deregistersShutdownHookForFailedApplicationContext.

@Test
void deregistersShutdownHookForFailedApplicationContext() {
    Application application = new Application(BrokenPostConstructConfig.class);
    List<ApplicationEvent> events = new ArrayList<>();
    application.addListeners(events::add);
    application.setApplicationType(ApplicationType.NONE_WEB);
    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(ApplicationShutdownHookInstance.get()).didNotRegisterApplicationContext(failure.getApplicationContext());
}
Also used : ApplicationFailedEvent(cn.taketoday.framework.context.event.ApplicationFailedEvent) BeforeEach(org.junit.jupiter.api.BeforeEach) LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) Resource(cn.taketoday.core.io.Resource) ApplicationEvent(cn.taketoday.context.ApplicationEvent) PostConstruct(jakarta.annotation.PostConstruct) Ordered(cn.taketoday.core.Ordered) PropertySource(cn.taketoday.core.env.PropertySource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) ApplicationContextInitializedEvent(cn.taketoday.framework.context.event.ApplicationContextInitializedEvent) ConfigurableWebEnvironment(cn.taketoday.web.context.ConfigurableWebEnvironment) StandardServletEnvironment(cn.taketoday.web.context.support.StandardServletEnvironment) Map(java.util.Map) ApplicationBuilder(cn.taketoday.framework.builder.ApplicationBuilder) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) BeanDefinitionOverrideException(cn.taketoday.beans.factory.support.BeanDefinitionOverrideException) ApplicationEnvironmentPreparedEvent(cn.taketoday.framework.context.event.ApplicationEnvironmentPreparedEvent) AbstractApplicationContext(cn.taketoday.context.support.AbstractApplicationContext) BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) Profiles(cn.taketoday.core.env.Profiles) BeanCurrentlyInCreationException(cn.taketoday.beans.factory.BeanCurrentlyInCreationException) ObjectProvider(cn.taketoday.beans.factory.ObjectProvider) Bean(cn.taketoday.context.annotation.Bean) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) ContextRefreshedEvent(cn.taketoday.context.event.ContextRefreshedEvent) ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) ApplicationFailedEvent(cn.taketoday.framework.context.event.ApplicationFailedEvent) ApplicationContextException(cn.taketoday.context.ApplicationContextException) CapturedOutput(cn.taketoday.framework.test.system.CapturedOutput) CachedIntrospectionResults(cn.taketoday.beans.CachedIntrospectionResults) TestPropertySourceUtils(cn.taketoday.test.context.support.TestPropertySourceUtils) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) CommandLinePropertySource(cn.taketoday.core.env.CommandLinePropertySource) Mockito.mock(org.mockito.Mockito.mock) AvailabilityChangeEvent(cn.taketoday.framework.availability.AvailabilityChangeEvent) HttpHandler(cn.taketoday.http.server.reactive.HttpHandler) StringUtils(cn.taketoday.util.StringUtils) ConfigurableBeanFactory(cn.taketoday.beans.factory.config.ConfigurableBeanFactory) InstanceSupplier(cn.taketoday.framework.BootstrapRegistry.InstanceSupplier) DefaultResourceLoader(cn.taketoday.core.io.DefaultResourceLoader) Mockito.spy(org.mockito.Mockito.spy) ApplicationReadyEvent(cn.taketoday.framework.context.event.ApplicationReadyEvent) ArrayList(java.util.ArrayList) WebApplicationContext(cn.taketoday.web.WebApplicationContext) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) MultiValueMap(cn.taketoday.core.MultiValueMap) LinkedHashSet(java.util.LinkedHashSet) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) ApplicationPreparedEvent(cn.taketoday.framework.context.event.ApplicationPreparedEvent) Mono(reactor.core.publisher.Mono) AnnotationConfigReactiveWebServerApplicationContext(cn.taketoday.framework.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) AfterEach(org.junit.jupiter.api.AfterEach) Mockito.never(org.mockito.Mockito.never) Condition(org.assertj.core.api.Condition) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) AnnotationConfigServletWebServerApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) MapPropertySource(cn.taketoday.core.env.MapPropertySource) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Configuration(cn.taketoday.context.annotation.Configuration) NettyReactiveWebServerFactory(cn.taketoday.framework.web.embedded.netty.NettyReactiveWebServerFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReadinessState(cn.taketoday.framework.availability.ReadinessState) ApplicationStartingEvent(cn.taketoday.framework.context.event.ApplicationStartingEvent) SimpleApplicationEventMulticaster(cn.taketoday.context.event.SimpleApplicationEventMulticaster) ArgumentMatcher(org.mockito.ArgumentMatcher) ApplicationEventMulticaster(cn.taketoday.context.event.ApplicationEventMulticaster) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClassPathResource(cn.taketoday.core.io.ClassPathResource) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) BeanCreationException(cn.taketoday.beans.factory.BeanCreationException) Lazy(cn.taketoday.context.annotation.Lazy) ApplicationContextInitializer(cn.taketoday.context.ApplicationContextInitializer) ApplicationContext(cn.taketoday.context.ApplicationContext) CompositePropertySource(cn.taketoday.core.env.CompositePropertySource) BDDMockito.willThrow(org.mockito.BDDMockito.willThrow) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) Autowired(cn.taketoday.beans.factory.annotation.Autowired) AnnotationConfigUtils(cn.taketoday.context.annotation.AnnotationConfigUtils) ResourceLoader(cn.taketoday.core.io.ResourceLoader) SmartApplicationListener(cn.taketoday.context.event.SmartApplicationListener) Test(org.junit.jupiter.api.Test) List(java.util.List) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StaticApplicationContext(cn.taketoday.context.support.StaticApplicationContext) HashMap(java.util.HashMap) ReactiveWebApplicationContext(cn.taketoday.framework.web.reactive.context.ReactiveWebApplicationContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApplicationContextAware(cn.taketoday.context.aware.ApplicationContextAware) OutputCaptureExtension(cn.taketoday.framework.test.system.OutputCaptureExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ApplicationListener(cn.taketoday.context.ApplicationListener) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) InOrder(org.mockito.InOrder) Iterator(java.util.Iterator) UnsatisfiedDependencyException(cn.taketoday.beans.factory.UnsatisfiedDependencyException) BDDMockito.then(org.mockito.BDDMockito.then) TomcatServletWebServerFactory(cn.taketoday.framework.web.embedded.tomcat.TomcatServletWebServerFactory) Mockito(org.mockito.Mockito) AvailabilityState(cn.taketoday.framework.availability.AvailabilityState) LivenessState(cn.taketoday.framework.availability.LivenessState) Collections(java.util.Collections) ApplicationStartedEvent(cn.taketoday.framework.context.event.ApplicationStartedEvent) BeanCreationException(cn.taketoday.beans.factory.BeanCreationException) ApplicationEvent(cn.taketoday.context.ApplicationEvent) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with ApplicationFailedEvent

use of cn.taketoday.framework.context.event.ApplicationFailedEvent in project today-framework by TAKETODAY.

the class ApplicationTests method deregistersShutdownHookForFailedApplicationContext.

@Test
void deregistersShutdownHookForFailedApplicationContext() {
    Application application = new Application(BrokenPostConstructConfig.class);
    List<ApplicationEvent> events = new ArrayList<>();
    application.addListeners(events::add);
    application.setApplicationType(ApplicationType.NONE_WEB);
    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(ApplicationShutdownHookInstance.get()).didNotRegisterApplicationContext(failure.getApplicationContext());
}
Also used : ApplicationFailedEvent(cn.taketoday.framework.context.event.ApplicationFailedEvent) BeforeEach(org.junit.jupiter.api.BeforeEach) LinkedMultiValueMap(cn.taketoday.core.LinkedMultiValueMap) Resource(cn.taketoday.core.io.Resource) ApplicationEvent(cn.taketoday.context.ApplicationEvent) PostConstruct(jakarta.annotation.PostConstruct) Ordered(cn.taketoday.core.Ordered) PropertySource(cn.taketoday.core.env.PropertySource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) ApplicationContextInitializedEvent(cn.taketoday.framework.context.event.ApplicationContextInitializedEvent) ConfigurableWebEnvironment(cn.taketoday.web.context.ConfigurableWebEnvironment) StandardServletEnvironment(cn.taketoday.web.context.support.StandardServletEnvironment) Map(java.util.Map) ApplicationBuilder(cn.taketoday.framework.builder.ApplicationBuilder) BeanDefinitionRegistry(cn.taketoday.beans.factory.support.BeanDefinitionRegistry) BeanDefinitionOverrideException(cn.taketoday.beans.factory.support.BeanDefinitionOverrideException) ApplicationEnvironmentPreparedEvent(cn.taketoday.framework.context.event.ApplicationEnvironmentPreparedEvent) AbstractApplicationContext(cn.taketoday.context.support.AbstractApplicationContext) BeanNameGenerator(cn.taketoday.beans.factory.support.BeanNameGenerator) Profiles(cn.taketoday.core.env.Profiles) BeanCurrentlyInCreationException(cn.taketoday.beans.factory.BeanCurrentlyInCreationException) ObjectProvider(cn.taketoday.beans.factory.ObjectProvider) Bean(cn.taketoday.context.annotation.Bean) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) ContextRefreshedEvent(cn.taketoday.context.event.ContextRefreshedEvent) ConfigurableApplicationContext(cn.taketoday.context.ConfigurableApplicationContext) ApplicationFailedEvent(cn.taketoday.framework.context.event.ApplicationFailedEvent) ApplicationContextException(cn.taketoday.context.ApplicationContextException) CapturedOutput(cn.taketoday.framework.test.system.CapturedOutput) CachedIntrospectionResults(cn.taketoday.beans.CachedIntrospectionResults) TestPropertySourceUtils(cn.taketoday.test.context.support.TestPropertySourceUtils) DefaultBeanNameGenerator(cn.taketoday.beans.factory.support.DefaultBeanNameGenerator) CommandLinePropertySource(cn.taketoday.core.env.CommandLinePropertySource) Mockito.mock(org.mockito.Mockito.mock) AvailabilityChangeEvent(cn.taketoday.framework.availability.AvailabilityChangeEvent) HttpHandler(cn.taketoday.http.server.reactive.HttpHandler) StringUtils(cn.taketoday.util.StringUtils) ConfigurableBeanFactory(cn.taketoday.beans.factory.config.ConfigurableBeanFactory) InstanceSupplier(cn.taketoday.framework.BootstrapRegistry.InstanceSupplier) DefaultResourceLoader(cn.taketoday.core.io.DefaultResourceLoader) Mockito.spy(org.mockito.Mockito.spy) ApplicationReadyEvent(cn.taketoday.framework.context.event.ApplicationReadyEvent) ArrayList(java.util.ArrayList) WebApplicationContext(cn.taketoday.web.WebApplicationContext) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) MultiValueMap(cn.taketoday.core.MultiValueMap) LinkedHashSet(java.util.LinkedHashSet) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) ApplicationPreparedEvent(cn.taketoday.framework.context.event.ApplicationPreparedEvent) Mono(reactor.core.publisher.Mono) AnnotationConfigReactiveWebServerApplicationContext(cn.taketoday.framework.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext) AfterEach(org.junit.jupiter.api.AfterEach) Mockito.never(org.mockito.Mockito.never) Condition(org.assertj.core.api.Condition) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) AnnotationConfigServletWebServerApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) MapPropertySource(cn.taketoday.core.env.MapPropertySource) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Configuration(cn.taketoday.context.annotation.Configuration) NettyReactiveWebServerFactory(cn.taketoday.framework.web.embedded.netty.NettyReactiveWebServerFactory) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ReadinessState(cn.taketoday.framework.availability.ReadinessState) ApplicationStartingEvent(cn.taketoday.framework.context.event.ApplicationStartingEvent) SimpleApplicationEventMulticaster(cn.taketoday.context.event.SimpleApplicationEventMulticaster) ArgumentMatcher(org.mockito.ArgumentMatcher) ApplicationEventMulticaster(cn.taketoday.context.event.ApplicationEventMulticaster) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClassPathResource(cn.taketoday.core.io.ClassPathResource) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) BeanCreationException(cn.taketoday.beans.factory.BeanCreationException) Lazy(cn.taketoday.context.annotation.Lazy) ApplicationContextInitializer(cn.taketoday.context.ApplicationContextInitializer) ApplicationContext(cn.taketoday.context.ApplicationContext) CompositePropertySource(cn.taketoday.core.env.CompositePropertySource) BDDMockito.willThrow(org.mockito.BDDMockito.willThrow) ConfigurableEnvironment(cn.taketoday.core.env.ConfigurableEnvironment) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) Autowired(cn.taketoday.beans.factory.annotation.Autowired) AnnotationConfigUtils(cn.taketoday.context.annotation.AnnotationConfigUtils) ResourceLoader(cn.taketoday.core.io.ResourceLoader) SmartApplicationListener(cn.taketoday.context.event.SmartApplicationListener) Test(org.junit.jupiter.api.Test) List(java.util.List) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StaticApplicationContext(cn.taketoday.context.support.StaticApplicationContext) HashMap(java.util.HashMap) ReactiveWebApplicationContext(cn.taketoday.framework.web.reactive.context.ReactiveWebApplicationContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApplicationContextAware(cn.taketoday.context.aware.ApplicationContextAware) OutputCaptureExtension(cn.taketoday.framework.test.system.OutputCaptureExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ApplicationListener(cn.taketoday.context.ApplicationListener) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) InOrder(org.mockito.InOrder) Iterator(java.util.Iterator) UnsatisfiedDependencyException(cn.taketoday.beans.factory.UnsatisfiedDependencyException) BDDMockito.then(org.mockito.BDDMockito.then) TomcatServletWebServerFactory(cn.taketoday.framework.web.embedded.tomcat.TomcatServletWebServerFactory) Mockito(org.mockito.Mockito) AvailabilityState(cn.taketoday.framework.availability.AvailabilityState) LivenessState(cn.taketoday.framework.availability.LivenessState) Collections(java.util.Collections) ApplicationStartedEvent(cn.taketoday.framework.context.event.ApplicationStartedEvent) BeanCreationException(cn.taketoday.beans.factory.BeanCreationException) ApplicationEvent(cn.taketoday.context.ApplicationEvent) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

CachedIntrospectionResults (cn.taketoday.beans.CachedIntrospectionResults)2 BeanCreationException (cn.taketoday.beans.factory.BeanCreationException)2 BeanCurrentlyInCreationException (cn.taketoday.beans.factory.BeanCurrentlyInCreationException)2 ObjectProvider (cn.taketoday.beans.factory.ObjectProvider)2 UnsatisfiedDependencyException (cn.taketoday.beans.factory.UnsatisfiedDependencyException)2 Autowired (cn.taketoday.beans.factory.annotation.Autowired)2 ConfigurableBeanFactory (cn.taketoday.beans.factory.config.ConfigurableBeanFactory)2 BeanDefinitionOverrideException (cn.taketoday.beans.factory.support.BeanDefinitionOverrideException)2 BeanDefinitionRegistry (cn.taketoday.beans.factory.support.BeanDefinitionRegistry)2 BeanNameGenerator (cn.taketoday.beans.factory.support.BeanNameGenerator)2 DefaultBeanNameGenerator (cn.taketoday.beans.factory.support.DefaultBeanNameGenerator)2 ApplicationContext (cn.taketoday.context.ApplicationContext)2 ApplicationContextException (cn.taketoday.context.ApplicationContextException)2 ApplicationContextInitializer (cn.taketoday.context.ApplicationContextInitializer)2 ApplicationEvent (cn.taketoday.context.ApplicationEvent)2 ApplicationListener (cn.taketoday.context.ApplicationListener)2 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)2 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)2 AnnotationConfigUtils (cn.taketoday.context.annotation.AnnotationConfigUtils)2 Bean (cn.taketoday.context.annotation.Bean)2