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

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

Introduction

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

Prototype

public static boolean unregister(Class<?> annotatedClass) 

Source Link

Document

Un-registers the specified Spring annotated POJO class used to configure and initialize the Spring ApplicationContext.

Usage

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

@After
public void tearDown() {
    SpringContextBootstrappingInitializer.applicationContext = null;
    SpringContextBootstrappingInitializer.contextRefreshedEvent = null;
    SpringContextBootstrappingInitializer.setBeanClassLoader(null);
    SpringContextBootstrappingInitializer.unregister(TestAppConfigOne.class);
    SpringContextBootstrappingInitializer.unregister(TestAppConfigTwo.class);
}

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

@Test
public void testOnApplicationEvent() {
    TestApplicationListener testApplicationListener = new TestApplicationListener("testOnApplicationEvent");

    try {/*from www. j  a va2s.  c  om*/
        testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener);

        assertUnnotified(testApplicationListener);

        ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(
                mock(ApplicationContext.class, "testOnApplicationEvent"));

        new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent);

        assertNotified(testApplicationListener, testContextRefreshedEvent);
    } finally {
        SpringContextBootstrappingInitializer.unregister(testApplicationListener);
    }
}

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

@Test
public void testOnApplicationEventWithContextStartedEvent() {
    TestApplicationListener testApplicationListener = new TestApplicationListener(
            "testOnApplicationEventWithContextStartedEvent");

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

        assertUnnotified(testApplicationListener);

        ContextStartedEvent testContextStartedEvent = mock(ContextStartedEvent.class,
                "testOnApplicationEventWithContextStartedEvent");

        new SpringContextBootstrappingInitializer().onApplicationEvent(testContextStartedEvent);

        assertUnnotified(testApplicationListener);
    } finally {
        SpringContextBootstrappingInitializer.unregister(testApplicationListener);
    }
}

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

@Test
public void testOnApplicationEventWithMultipleRegisteredApplicationListeners() {
    TestApplicationListener testApplicationListenerOne = new TestApplicationListener(
            "testOnApplicationEventWithMultipleRegisteredApplicationListeners.1");

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

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

    try {/*from w w w . j  ava 2  s. co m*/
        testApplicationListenerOne = SpringContextBootstrappingInitializer.register(testApplicationListenerOne);
        testApplicationListenerTwo = SpringContextBootstrappingInitializer.register(testApplicationListenerTwo);
        testApplicationListenerThree = SpringContextBootstrappingInitializer
                .register(testApplicationListenerThree);

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

        ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(mock(
                ApplicationContext.class, "testOnApplicationEventWithMultipleRegisteredApplicationListeners"));

        new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent);

        assertNotified(testApplicationListenerOne, testContextRefreshedEvent);
        assertNotified(testApplicationListenerTwo, testContextRefreshedEvent);
        assertNotified(testApplicationListenerThree, testContextRefreshedEvent);
    } finally {
        SpringContextBootstrappingInitializer.unregister(testApplicationListenerOne);
        SpringContextBootstrappingInitializer.unregister(testApplicationListenerTwo);
        SpringContextBootstrappingInitializer.unregister(testApplicationListenerThree);
    }
}

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

@Test
public void testOnApplicationEventWithUnregisteredApplicationListener() {
    TestApplicationListener testApplicationListener = new TestApplicationListener(
            "testOnApplicationEventWithUnregisteredApplicationListener");

    try {//from w  w w  .  j  av a  2 s  . c  o  m
        testApplicationListener = SpringContextBootstrappingInitializer
                .unregister(SpringContextBootstrappingInitializer.register(testApplicationListener));

        assertUnnotified(testApplicationListener);

        ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(
                mock(ApplicationContext.class, "testRegisterThenUnregisterWithOnApplicationEvent"));

        new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent);

        assertUnnotified(testApplicationListener);
    } finally {
        SpringContextBootstrappingInitializer.unregister(testApplicationListener);
    }
}

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

@Test
public void testNotifyOnExistingContextRefreshedEventBeforeApplicationContextExists() {
    assertNull(SpringContextBootstrappingInitializer.contextRefreshedEvent);

    TestApplicationListener testApplicationListener = new TestApplicationListener(
            "testNotifyOnExistingContextRefreshedEventBeforeApplicationContextExists");

    try {/*from   w w w.  ja  v a 2 s.  c  om*/
        testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener);
        assertUnnotified(testApplicationListener);
    } finally {
        SpringContextBootstrappingInitializer.unregister(testApplicationListener);
    }
}

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

@Test
public void testNotifyOnExistingContextRefreshedEventAfterContextRefreshed() {
    ContextRefreshedEvent testContextRefreshedEvent = new ContextRefreshedEvent(mock(ApplicationContext.class));

    new SpringContextBootstrappingInitializer().onApplicationEvent(testContextRefreshedEvent);

    TestApplicationListener testApplicationListener = new TestApplicationListener(
            "testNotifyOnExistingContextRefreshedEventAfterContextRefreshed");

    try {/*from  w  ww  .j a  v  a  2 s . c o  m*/
        testApplicationListener = SpringContextBootstrappingInitializer.register(testApplicationListener);
        assertNotified(testApplicationListener, testContextRefreshedEvent);
    } finally {
        SpringContextBootstrappingInitializer.unregister(testApplicationListener);
    }
}

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 .  j a va 2s. c  o  m
        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);
    }
}