Search in sources :

Example 96 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class ServerEventRelayTest method createEvent.

private MotechEvent createEvent(String messageDestination) {
    MotechEvent event = createEvent();
    event.setMessageDestination(messageDestination);
    return event;
}
Also used : MotechEvent(org.motechproject.event.MotechEvent)

Example 97 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class ServerEventRelayTest method testRelayToSingleListenerWithoutMessageDestination.

@Test
public void testRelayToSingleListenerWithoutMessageDestination() throws Exception {
    MotechEvent motechEvent = createEvent();
    setUpListeners(SUBJECT, eventListener);
    eventRelay.relayQueueEvent(motechEvent);
    verify(eventListener, never()).handle(motechEvent);
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 98 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class ServerEventRelayTest method shouldNotifyCallbackServiceOnFailedEventHandling.

@Test
public void shouldNotifyCallbackServiceOnFailedEventHandling() throws Exception {
    MotechEvent motechEvent = createEvent(LISTENER_IDENTIFIER);
    motechEvent.setCallbackName(TEST_SERVICE_CALLBACK);
    setUpListeners(SUBJECT, eventListener);
    when(bundleContext.getServiceReferences(EventCallbackService.class, null)).thenReturn(Arrays.asList(serviceReference));
    when(bundleContext.getService(serviceReference)).thenReturn(callbackService);
    when(callbackService.getName()).thenReturn(TEST_SERVICE_CALLBACK);
    RuntimeException initCause = new RuntimeException();
    doThrow(new RuntimeException("Failed", initCause)).when(eventListener).handle(any(MotechEvent.class));
    eventRelay.relayQueueEvent(motechEvent);
    verify(eventListener).handle(motechEvent);
    verify(callbackService).failureCallback(motechEvent, initCause);
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 99 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class ServerEventRelayTest method testRelayToSingleListenerWithMessageDestination.

@Test
public void testRelayToSingleListenerWithMessageDestination() throws Exception {
    MotechEvent motechEvent = createEvent(LISTENER_IDENTIFIER);
    setUpListeners(SUBJECT, eventListener);
    eventRelay.relayQueueEvent(motechEvent);
    verify(eventListener).handle(motechEvent);
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 100 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class ServerEventRelayTest method testThatOnlyListenerIdentifiedByMessageDestinationHandlesEvent.

@Test
public void testThatOnlyListenerIdentifiedByMessageDestinationHandlesEvent() throws Exception {
    setUpListeners(SUBJECT, eventListener, secondaryEventListener);
    MotechEvent motechEvent = createEvent(LISTENER_IDENTIFIER);
    eventRelay.relayQueueEvent(motechEvent);
    verify(eventListener).handle(motechEvent);
    verify(secondaryEventListener, never()).handle(any(MotechEvent.class));
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Aggregations

MotechEvent (org.motechproject.event.MotechEvent)138 Test (org.junit.Test)87 HashMap (java.util.HashMap)79 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)28 DateTime (org.joda.time.DateTime)25 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)20 ArrayList (java.util.ArrayList)14 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)13 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)11 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)10 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)8 Matchers.anyString (org.mockito.Matchers.anyString)7 EventListener (org.motechproject.event.listener.EventListener)7 CronJobId (org.motechproject.scheduler.contract.CronJobId)7 Task (org.motechproject.tasks.domain.mds.task.Task)7 JobId (org.motechproject.scheduler.contract.JobId)6 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)6 Time (org.motechproject.commons.date.model.Time)5 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)5 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)5