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);
}
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"));
}
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));
}
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());
}
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);
}
Aggregations