Search in sources :

Example 1 with Callback

use of alma.acs.nc.AcsEventSubscriber.Callback in project ACS by ACS-Community.

the class NCSubscriberTest method testAddSubscription.

/**
	 */
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testAddSubscription() throws Exception {
    // Invalid receiver (returns null)
    try {
        m_subscriber.addSubscription(new EventReceiver1() {

            public Class<statusBlockEvent1> getEventType() {
                return null;
            }
        });
        fail("Event receiver is invalid, as it returns a null event type");
    } catch (AcsJEventSubscriptionEx e) {
    }
    // Invalid receiver (returns String.class)
    try {
        m_subscriber.addSubscription(new Callback() {

            public void receive(Object event, EventDescription eventDescrip) {
            }

            public Class getEventType() {
                return String.class;
            }
        });
        fail("Event receiver is invalid, as it returns a java.lang.String as the event type");
    } catch (AcsJEventSubscriptionEx e) {
    }
    // Several receiver subscriptions for the same type overwrite the previous one
    m_subscriber.addSubscription(new EventReceiver1());
    m_subscriber.addSubscription(new EventReceiver1());
    m_subscriber.addSubscription(new EventReceiver1());
    m_subscriber.addSubscription(new EventReceiver1());
    assertEquals(1, m_subscriber.subscriptionsFilters.size());
    assertEquals(1, m_subscriber.getNumberOfReceivers());
    assertFalse(m_subscriber.hasGenericReceiver());
    assertEquals(2, m_subscriber.proxySupplier.get_all_filters().length);
    m_subscriber.addSubscription(new EventReceiver2());
    m_subscriber.addSubscription(new EventReceiver2());
    m_subscriber.addSubscription(new EventReceiver2());
    m_subscriber.addSubscription(new EventReceiver2());
    assertEquals(2, m_subscriber.subscriptionsFilters.size());
    assertEquals(2, m_subscriber.getNumberOfReceivers());
    assertFalse(m_subscriber.hasGenericReceiver());
    assertEquals(3, m_subscriber.proxySupplier.get_all_filters().length);
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    m_subscriber.addGenericSubscription(new GenericEventReceiver());
    assertEquals(3, m_subscriber.subscriptionsFilters.size());
    assertEquals(2, m_subscriber.getNumberOfReceivers());
    assertTrue(m_subscriber.hasGenericReceiver());
    assertEquals(4, m_subscriber.proxySupplier.get_all_filters().length);
}
Also used : AcsJEventSubscriptionEx(alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx) GenericCallback(alma.acs.nc.AcsEventSubscriber.GenericCallback) Callback(alma.acs.nc.AcsEventSubscriber.Callback) EventDescription(alma.acsnc.EventDescription) Test(org.junit.Test)

Aggregations

Callback (alma.acs.nc.AcsEventSubscriber.Callback)1 GenericCallback (alma.acs.nc.AcsEventSubscriber.GenericCallback)1 AcsJEventSubscriptionEx (alma.acsErrTypeLifeCycle.wrappers.AcsJEventSubscriptionEx)1 EventDescription (alma.acsnc.EventDescription)1 Test (org.junit.Test)1