use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method shouldExecuteTaskIfActionMapParameterHasValueWithMixedTypes.
@Test
public void shouldExecuteTaskIfActionMapParameterHasValueWithMixedTypes() throws Exception {
TaskActionInformation actionInformation = prepareTaskActionInformationWithTrigger();
ActionEvent actionEvent = prepareActionEvent();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
taskActionExecutor.setBundleContext(bundleContext);
taskActionExecutor.execute(task, actionInformation, 0, prepareTaskContext(task), TASK_ACTIVITY_ID);
verify(eventRelay).sendEventMessage(eq(prepareMotechEvent()));
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method shouldAddActivityNotificationIfServiceIsNotAvailable.
@Test
public void shouldAddActivityNotificationIfServiceIsNotAvailable() throws TaskHandlerException, ActionNotFoundException {
TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setSubject("actionSubject").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").setActionParameters(new TreeSet<>()).build();
actionEvent.setActionParameters(new TreeSet<>());
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
when(bundleContext.getServiceReference("serviceInterface")).thenReturn(null);
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
taskActionExecutor.setBundleContext(bundleContext);
taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
verify(activityService).addWarning(task, "task.warning.serviceUnavailable", "serviceInterface");
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method shouldRaiseEventIfActionHasSubject.
@Test
public void shouldRaiseEventIfActionHasSubject() throws ActionNotFoundException, TaskHandlerException {
TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "actionSubject");
ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setSubject("actionSubject").setDescription("").setActionParameters(new TreeSet<>()).build();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
task.setId(11L);
Map<String, Object> metadata = new HashMap<>();
metadata.put(EventDataKeys.TASK_ID, 11L);
metadata.put(EventDataKeys.TASK_RETRY, null);
metadata.put(EventDataKeys.TASK_ACTIVITY_ID, TASK_ACTIVITY_ID);
taskActionExecutor.setBundleContext(bundleContext);
taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), metadata, activityService), TASK_ACTIVITY_ID);
MotechEvent raisedEvent = new MotechEvent("actionSubject", new HashMap<>(), TasksEventCallbackService.TASKS_EVENT_CALLBACK_NAME, metadata);
verify(eventRelay).sendEventMessage(raisedEvent);
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method prepareTaskActionInformationWithTrigger.
private TaskActionInformation prepareTaskActionInformationWithTrigger() {
TaskActionInformation actionInformation = prepareTaskActionInformation();
Map<String, String> values = new HashMap<>();
values.put("map", "key1:value{{trigger.id}}");
actionInformation.setValues(values);
return actionInformation;
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method shouldNotRaiseEventIfActionHasSubjectAndService_IfServiceIsAvailable.
@Test
public void shouldNotRaiseEventIfActionHasSubjectAndService_IfServiceIsAvailable() throws ActionNotFoundException, TaskHandlerException {
TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setSubject("actionSubject").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").setActionParameters(new TreeSet<>()).build();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
ServiceReference serviceReference = mock(ServiceReference.class);
when(bundleContext.getServiceReference("serviceInterface")).thenReturn(serviceReference);
when(bundleContext.getService(serviceReference)).thenReturn(new TestService());
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
taskActionExecutor.setBundleContext(bundleContext);
taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
verify(eventRelay, never()).sendEventMessage(any(MotechEvent.class));
}
Aggregations