Search in sources :

Example 1 with SampleEventListener

use of org.motechproject.event.listener.SampleEventListener 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 SampleEventListener

use of org.motechproject.event.listener.SampleEventListener 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 SampleEventListener

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

the class EventListenerRegistryTest method testHasListener_Yes.

@Test
public void testHasListener_Yes() {
    registry.registerListener(new SampleEventListener(), "org.motechproject.server.someevent");
    assertTrue(registry.hasListener("org.motechproject.server.someevent"));
}
Also used : OtherSampleEventListener(org.motechproject.event.listener.OtherSampleEventListener) SampleEventListener(org.motechproject.event.listener.SampleEventListener) Test(org.junit.Test)

Example 4 with SampleEventListener

use of org.motechproject.event.listener.SampleEventListener 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 5 with SampleEventListener

use of org.motechproject.event.listener.SampleEventListener 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)

Aggregations

Test (org.junit.Test)14 SampleEventListener (org.motechproject.event.listener.SampleEventListener)14 OtherSampleEventListener (org.motechproject.event.listener.OtherSampleEventListener)13 EventListener (org.motechproject.event.listener.EventListener)11 ArrayList (java.util.ArrayList)7 Matchers.anyString (org.mockito.Matchers.anyString)7 EventListenerTree (org.motechproject.event.listener.impl.EventListenerTree)1