Search in sources :

Example 1 with ContextRefreshedEvent

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

the class BeanFactoryPostProcessorTests method testBeanFactoryPostProcessorAsApplicationListener.

@Test
public void testBeanFactoryPostProcessorAsApplicationListener() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerBeanDefinition("bfpp", new RootBeanDefinition(ListeningBeanFactoryPostProcessor.class));
    ac.refresh();
    boolean condition = ac.getBean(ListeningBeanFactoryPostProcessor.class).received instanceof ContextRefreshedEvent;
    assertThat(condition).isTrue();
}
Also used : RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ContextRefreshedEvent(cn.taketoday.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 2 with ContextRefreshedEvent

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

the class BeanFactoryPostProcessorTests method testBeanFactoryPostProcessorWithInnerBeanAsApplicationListener.

@Test
public void testBeanFactoryPostProcessorWithInnerBeanAsApplicationListener() {
    StaticApplicationContext ac = new StaticApplicationContext();
    RootBeanDefinition rbd = new RootBeanDefinition(NestingBeanFactoryPostProcessor.class);
    rbd.getPropertyValues().add("listeningBean", new RootBeanDefinition(ListeningBean.class));
    ac.registerBeanDefinition("bfpp", rbd);
    ac.refresh();
    boolean condition = ac.getBean(NestingBeanFactoryPostProcessor.class).getListeningBean().received instanceof ContextRefreshedEvent;
    assertThat(condition).isTrue();
}
Also used : RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ContextRefreshedEvent(cn.taketoday.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with ContextRefreshedEvent

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

the class ApplicationListenerTests method testAddApplicationListener.

@Test
void testAddApplicationListener() throws NoSuchBeanDefinitionException, BeanDefinitionStoreException {
    try (StandardApplicationContext applicationContext = new StandardApplicationContext()) {
        applicationContext.addApplicationListener(new ApplicationListener<ContextRefreshedEvent>() {

            @Override
            public void onApplicationEvent(ContextRefreshedEvent event) {
                i = true;
            }
        });
        applicationContext.register(ContextCloseMetaInfoListener.class);
        applicationContext.refresh();
        assert i;
    }
}
Also used : StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) ContextRefreshedEvent(cn.taketoday.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with ContextRefreshedEvent

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

the class ApplicationListenerTests method testAddApplicationListener.

@Test
void testAddApplicationListener() throws NoSuchBeanDefinitionException, BeanDefinitionStoreException {
    try (StandardApplicationContext applicationContext = new StandardApplicationContext()) {
        applicationContext.addApplicationListener(new ApplicationListener<ContextRefreshedEvent>() {

            @Override
            public void onApplicationEvent(ContextRefreshedEvent event) {
                i = true;
            }
        });
        applicationContext.register(ContextCloseMetaInfoListener.class);
        applicationContext.refresh();
        assert i;
    }
}
Also used : StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) ContextRefreshedEvent(cn.taketoday.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 5 with ContextRefreshedEvent

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

the class BeanFactoryPostProcessorTests method testBeanFactoryPostProcessorAsApplicationListener.

@Test
public void testBeanFactoryPostProcessorAsApplicationListener() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerBeanDefinition("bfpp", new RootBeanDefinition(ListeningBeanFactoryPostProcessor.class));
    ac.refresh();
    boolean condition = ac.getBean(ListeningBeanFactoryPostProcessor.class).received instanceof ContextRefreshedEvent;
    assertThat(condition).isTrue();
}
Also used : RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) ContextRefreshedEvent(cn.taketoday.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

ContextRefreshedEvent (cn.taketoday.context.event.ContextRefreshedEvent)6 Test (org.junit.jupiter.api.Test)6 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)4 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)2