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);
}
Aggregations