Example usage for org.springframework.data.gemfire.support SpringContextBootstrappingInitializer onApplicationEvent

List of usage examples for org.springframework.data.gemfire.support SpringContextBootstrappingInitializer onApplicationEvent

Introduction

In this page you can find the example usage for org.springframework.data.gemfire.support SpringContextBootstrappingInitializer onApplicationEvent.

Prototype

@Override
public void onApplicationEvent(ApplicationContextEvent event) 

Source Link

Document

Gets notified when the Spring ApplicationContext gets created and refreshed by GemFire, once the <initializer> block is processed and the SpringContextBootstrappingInitializer Declarable component is initialized.

Usage

From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializerTest.java

@Test
public void testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent() {
    ConfigurableApplicationContext mockApplicationContext = mock(ConfigurableApplicationContext.class,
            "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent");

    SpringContextBootstrappingInitializer initializer = new SpringContextBootstrappingInitializer();

    TestApplicationListener testApplicationListenerOne = new TestApplicationListener(
            "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.1");

    TestApplicationListener testApplicationListenerTwo = new TestApplicationListener(
            "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.2");

    TestApplicationListener testApplicationListenerThree = new TestApplicationListener(
            "testOnApplicationEventAndNotifyOnExistingContextRefreshedEvent.3");

    try {/*from  w  w w  .ja  v a 2 s .c  om*/
        testApplicationListenerOne = SpringContextBootstrappingInitializer.register(testApplicationListenerOne);

        assertUnnotified(testApplicationListenerOne);
        assertUnnotified(testApplicationListenerTwo);
        assertUnnotified(testApplicationListenerThree);

        ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(mockApplicationContext);

        initializer.onApplicationEvent(testContextRefreshedEvent);

        assertNotified(testApplicationListenerOne, testContextRefreshedEvent);
        assertUnnotified(testApplicationListenerTwo);
        assertUnnotified(testApplicationListenerThree);

        testApplicationListenerTwo = SpringContextBootstrappingInitializer.register(testApplicationListenerTwo);

        assertNotified(testApplicationListenerTwo, testContextRefreshedEvent);
        assertUnnotified(testApplicationListenerOne);
        assertUnnotified(testApplicationListenerThree);

        ContextStoppedEvent testContextStoppedEvent = new ContextStoppedEvent(mockApplicationContext);

        initializer.onApplicationEvent(testContextStoppedEvent);

        assertUnnotified(testApplicationListenerOne);
        assertUnnotified(testApplicationListenerTwo);
        assertUnnotified(testApplicationListenerThree);

        initializer.onApplicationEvent(testContextRefreshedEvent);

        assertNotified(testApplicationListenerOne, testContextRefreshedEvent);
        assertNotified(testApplicationListenerTwo, testContextRefreshedEvent);
        assertUnnotified(testApplicationListenerThree);

        ContextClosedEvent testContextClosedEvent = new ContextClosedEvent(mockApplicationContext);

        initializer.onApplicationEvent(testContextClosedEvent);

        assertUnnotified(testApplicationListenerOne);
        assertUnnotified(testApplicationListenerTwo);
        assertUnnotified(testApplicationListenerThree);

        SpringContextBootstrappingInitializer.register(testApplicationListenerThree);

        assertUnnotified(testApplicationListenerOne);
        assertUnnotified(testApplicationListenerTwo);
        assertUnnotified(testApplicationListenerThree);
    } finally {
        SpringContextBootstrappingInitializer.unregister(testApplicationListenerOne);
        SpringContextBootstrappingInitializer.unregister(testApplicationListenerTwo);
        SpringContextBootstrappingInitializer.unregister(testApplicationListenerThree);
    }
}