Search in sources :

Example 1 with EventListener

use of org.motechproject.event.listener.EventListener in project motech by motech.

the class EventListenerRegistryTest method testRegisterForSameEventTwice.

@Test
public void testRegisterForSameEventTwice() {
    List<String> et = new ArrayList<String>();
    et.add("org.motechproject.server.someevent");
    et.add("org.motechproject.server.someevent");
    EventListener sel = new SampleEventListener();
    registry.registerListener(sel, et);
    Set<EventListener> el = registry.getListeners(et.get(0));
    assertNotNull(el);
    assertTrue(el.size() == 1);
    assertTrue(el.contains(sel));
    el = registry.getListeners(et.get(1));
    assertNotNull(el);
    assertTrue(el.size() == 1);
    assertTrue(el.contains(sel));
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 2 with EventListener

use of org.motechproject.event.listener.EventListener in project motech by motech.

the class EventListenerRegistryTest method testAddThenRemoveListener.

@Test
public void testAddThenRemoveListener() {
    List<String> et = new ArrayList<String>();
    et.add("org.motechproject.server.someevent");
    EventListener sel = new SampleEventListener();
    registry.registerListener(sel, et);
    Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent");
    assertEquals(1, el.size());
    registry.clearListenersForBean("TestEventListener");
    el = registry.getListeners("org.motechproject.server.someevent");
    assertEquals(0, el.size());
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 3 with EventListener

use of org.motechproject.event.listener.EventListener in project motech by motech.

the class EventListenerRegistryTest method testRegisterMultipleListener.

@Test
public void testRegisterMultipleListener() {
    EventListener sel = new SampleEventListener();
    EventListener sel2 = new FooEventListener();
    registry.registerListener(sel, "org.motechproject.server.someevent");
    registry.registerListener(sel2, "org.motechproject.server.someevent");
    Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent");
    assertNotNull(el);
    assertTrue(el.size() == 2);
    assertTrue(el.contains(sel));
    assertTrue(el.contains(sel2));
}
Also used : OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 4 with EventListener

use of org.motechproject.event.listener.EventListener in project motech by motech.

the class EventListenerRegistryTest method testAddingWildCardListenerThenRemoving.

@Test
public void testAddingWildCardListenerThenRemoving() {
    List<String> et = new ArrayList<String>();
    et.add("org.motechproject.server.*");
    EventListener sel = new SampleEventListener();
    registry.registerListener(sel, et);
    Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent.test");
    assertEquals(1, el.size());
    registry.clearListenersForBean("TestEventListener");
    el = registry.getListeners("org.motechproject.server.someevent");
    assertEquals(0, el.size());
}
Also used : ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 5 with EventListener

use of org.motechproject.event.listener.EventListener in project motech by motech.

the class EventListenerRegistryTest method testEmptyEventListRegistration.

@Test
public void testEmptyEventListRegistration() throws NoSuchFieldException {
    List<String> subjects = new ArrayList<String>();
    EventListener sel = new SampleEventListener();
    EventListenerTree mockTree = mock(EventListenerTree.class);
    PrivateAccessor.setField(registry, "listenerTree", mockTree);
    registry.registerListener(sel, subjects);
    verify(mockTree, times(0)).addListener(Matchers.<EventListener>anyObject(), anyString());
}
Also used : EventListenerTree(org.motechproject.event.listener.impl.EventListenerTree) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) EventListener(org.motechproject.event.listener.EventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Aggregations

EventListener (org.motechproject.event.listener.EventListener)25 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)12 SampleEventListener (org.motechproject.event.listener.SampleEventListener)11 Matchers.anyString (org.mockito.Matchers.anyString)10 OtherSampleEventListener (org.motechproject.event.listener.OtherSampleEventListener)10 MotechEvent (org.motechproject.event.MotechEvent)9 MotechListenerEventProxy (org.motechproject.event.listener.annotations.MotechListenerEventProxy)4 HashMap (java.util.HashMap)3 Method (java.lang.reflect.Method)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 DateTime (org.joda.time.DateTime)1 TestEventPayload (org.motechproject.event.domain.TestEventPayload)1 EventListenerTree (org.motechproject.event.listener.impl.EventListenerTree)1 TestMdsEntity (org.motechproject.mds.test.domain.TestMdsEntity)1 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)1 Task (org.motechproject.tasks.domain.mds.task.Task)1 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)1 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)1