Search in sources :

Example 91 with MotechEvent

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

the class ServerEventRelayBundleIT method shouldRedeliverQueueMessages_SpecifiedTimes_WithDelay.

/**
 * For the test to work, set attribute schedulerSupport="true" in the broker element of the activemq.xml
 * Ref: http://activemq.apache.org/delay-and-schedule-message-delivery.html
 */
@Test
public void shouldRedeliverQueueMessages_SpecifiedTimes_WithDelay() throws InterruptedException {
    InvalidMessageEventListener eventListener = new InvalidMessageEventListener();
    eventListenerRegistry.registerListener(eventListener, MESSAGE_REDELIVERY_TEST);
    MotechEvent testMessage = new MotechEvent(MESSAGE_REDELIVERY_TEST);
    eventRelay.sendEventMessage(testMessage);
    Boolean isDiscarded = null;
    MotechEvent motechEvent = null;
    for (int pollCount = 0; pollCount < 10; pollCount++) {
        motechEvent = eventListener.getMotechEvent();
        if (motechEvent != null) {
            isDiscarded = motechEvent.isDiscarded();
            if (isDiscarded) {
                break;
            }
        }
        Thread.sleep(3000);
    }
    assertTrue(isDiscarded != null && isDiscarded);
    assertEquals(motechEventConfig.getMessageMaxRedeliveryCount(), motechEvent.getMessageRedeliveryCount());
    assertEventHandledTimes(eventListener);
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 92 with MotechEvent

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

the class BundleAdminServiceTest method testSetUploadSize.

@Test
public void testSetUploadSize() {
    when(configurationService.getPlatformSettings()).thenReturn(motechSettings);
    when(motechSettings.getUploadSize()).thenReturn("1000000");
    MotechEvent motechEvent = new MotechEvent(FILE_CHANGED_EVENT_SUBJECT);
    moduleAdminService.changeMaxUploadSize(motechEvent);
    verify(commonsMultipartResolver).setMaxUploadSize(Long.valueOf("1000000"));
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 93 with MotechEvent

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

the class TaskDataProviderServiceImplTest method shouldSendEventWhenProviderWasUpdated.

@Test
public void shouldSendEventWhenProviderWasUpdated() {
    Type type = new TypeToken<TaskDataProvider>() {
    }.getType();
    List<TaskDataProviderObject> objects = new ArrayList<>();
    List<LookupFieldsParameter> lookupFields = asList(new LookupFieldsParameter("lookupField", asList("lookupField")));
    List<FieldParameter> fields = asList(new FieldParameter("displayName", "fieldKey"));
    objects.add(new TaskDataProviderObject("displayName", "type", lookupFields, fields));
    TaskDataProvider provider = new TaskDataProvider(PROVIDER_NAME, objects);
    List<TaskDataProviderObject> updatedObjects = new ArrayList<>(objects);
    updatedObjects.add(new TaskDataProviderObject("displayName2", "type2", lookupFields, fields));
    TaskDataProvider updatedProvider = new TaskDataProvider(PROVIDER_NAME, updatedObjects);
    when(motechJsonReader.readFromStream(inputStream, type)).thenReturn(updatedProvider);
    when(dataProviderDataService.findByName(PROVIDER_NAME)).thenReturn(provider);
    ArgumentCaptor<MotechEvent> captor = ArgumentCaptor.forClass(MotechEvent.class);
    taskDataProviderService.registerProvider(inputStream);
    ArgumentCaptor<TaskDataProvider> taskDataProviderArgumentCaptor = ArgumentCaptor.forClass(TaskDataProvider.class);
    verify(dataProviderDataService).update(taskDataProviderArgumentCaptor.capture());
    assertEquals(PROVIDER_NAME, taskDataProviderArgumentCaptor.getValue().getName());
    verify(dataProviderDataService).update(provider);
    verify(eventRelay).sendEventMessage(captor.capture());
    MotechEvent event = captor.getValue();
    assertEquals(DATA_PROVIDER_UPDATE_SUBJECT, event.getSubject());
    assertEquals(PROVIDER_NAME, event.getParameters().get(DATA_PROVIDER_NAME));
}
Also used : ArrayList(java.util.ArrayList) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) Type(java.lang.reflect.Type) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) FieldParameter(org.motechproject.tasks.domain.mds.task.FieldParameter) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 94 with MotechEvent

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

the class TasksPostExecutionHandlerTest method shoulNotifyOnSuccessfulTask.

@Test
public void shoulNotifyOnSuccessfulTask() {
    when(taskActivityService.addSuccessfulExecution(TASK_ACTIVITY_ID)).thenReturn(true);
    when(taskActivityService.getTaskActivityById(TASK_ACTIVITY_ID)).thenReturn(taskActivity);
    when(taskService.getTask(task.getId())).thenReturn(task);
    postExecutionHandler.handleActionExecuted(createEventParameters(), new HashMap<>(), TASK_ACTIVITY_ID);
    ArgumentCaptor<MotechEvent> captorEvent = ArgumentCaptor.forClass(MotechEvent.class);
    verify(eventRelay).sendEventMessage(captorEvent.capture());
    MotechEvent motechEvent = captorEvent.getValue();
    assertEquals(EventSubjects.createHandlerSuccessSubject(task.getName()), motechEvent.getSubject());
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 95 with MotechEvent

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

the class ServerEventRelayTest method testSplitEvents.

@Test
public void testSplitEvents() throws Exception {
    MotechEvent motechEvent = createEvent();
    setUpListeners(SUBJECT, eventListener, secondaryEventListener);
    eventRelay.sendEventMessage(motechEvent);
    ArgumentCaptor<MotechEvent> argumentCaptor = ArgumentCaptor.forClass(MotechEvent.class);
    verify(outboundEventGateway, times(2)).sendEventMessage(argumentCaptor.capture());
    MotechEvent capturedEvent;
    capturedEvent = argumentCaptor.getAllValues().get(0);
    assertEquals(capturedEvent.getMessageDestination(), LISTENER_IDENTIFIER);
    capturedEvent = argumentCaptor.getAllValues().get(1);
    assertEquals(capturedEvent.getMessageDestination(), SECONDARY_LISTENER_IDENTIFIER);
}
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