use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventListenerRegistryTest method testRegisterForMultipleEvents.
@Test
public void testRegisterForMultipleEvents() {
List<String> et = new ArrayList<String>();
et.add("org.motechproject.server.someevent");
et.add("org.motechproject.server.someotherevent");
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));
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class EventListenerRegistryTest method testRemovingListenerPreservesOtherListeners.
@Test
public void testRemovingListenerPreservesOtherListeners() {
List<String> et = new ArrayList<String>();
et.add("org.motechproject.server.someevent");
EventListener sel = new SampleEventListener();
EventListener se2 = new OtherSampleEventListener();
registry.registerListener(sel, et);
registry.registerListener(se2, et);
Set<EventListener> el = registry.getListeners("org.motechproject.server.someevent");
assertEquals(2, el.size());
registry.clearListenersForBean("TestEventListener");
el = registry.getListeners("org.motechproject.server.someevent");
assertEquals(1, el.size());
registry.clearListenersForBean("TestEventListener2");
el = registry.getListeners("org.motechproject.server.someevent");
assertEquals(0, el.size());
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class TaskControllerTest method shouldSaveTask.
@Test
public void shouldSaveTask() {
String subject = "trigger1";
TaskActionInformation action = new TaskActionInformation("send", "action1", "action", "0.15", "send", new HashMap<String, String>());
TaskTriggerInformation trigger = new TaskTriggerInformation("trigger", "trigger1", "trigger", "0.16", subject, subject);
Task expected = new Task("name", trigger, asList(action));
when(eventListenerRegistryService.getListeners(subject)).thenReturn(new HashSet<EventListener>());
controller.save(expected);
verify(taskWebService).save(expected);
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class TaskTriggerHandlerTest method shouldRegisterHandlerOneTimeForSameSubjects.
@Test
public void shouldRegisterHandlerOneTimeForSameSubjects() {
String subject = "org.motechproject.messagecampaign.campaign-completed";
Method method = findMethod(getTargetClass(handler), "handle", MotechEvent.class);
Set<EventListener> listeners = new HashSet<>();
listeners.add(new MotechListenerEventProxy("taskTriggerHandler", this, method));
when(registryService.getListeners(subject)).thenReturn(listeners);
handler.registerHandlerFor(subject);
handler.registerHandlerFor(subject);
handler.registerHandlerFor(subject);
handler.registerHandlerFor(subject);
handler.registerHandlerFor(subject);
handler.registerHandlerFor(subject);
handler.registerHandlerFor(subject);
verify(registryService, never()).registerListener(any(EventListener.class), eq(subject));
}
use of org.motechproject.event.listener.EventListener in project motech by motech.
the class TaskTriggerHandlerTest method shouldRegisterRetryHandlerForSubject.
@Test
public void shouldRegisterRetryHandlerForSubject() {
String subject = "org.motechproject.messagecampaign.campaign-completed";
handler.registerHandlerFor(subject, true);
ArgumentCaptor<EventListener> captor = ArgumentCaptor.forClass(EventListener.class);
verify(registryService).registerListener(captor.capture(), eq(subject));
MotechListenerEventProxy proxy = (MotechListenerEventProxy) captor.getValue();
assertEquals("taskTriggerHandler", proxy.getIdentifier());
assertEquals(handler, proxy.getBean());
assertEquals(findMethod(getTargetClass(handler), "handleRetry", MotechEvent.class), proxy.getMethod());
}
Aggregations