use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskServiceImpl method validateActions.
private Set<TaskError> validateActions(Task task, Channel channel) {
LOGGER.debug("Validating all actions in task: {} with ID: {}", task.getName(), task.getId());
Set<TaskError> errors = new HashSet<>();
for (TaskActionInformation action : task.getActions()) {
errors.addAll(validateAction(task, channel, action));
}
logResultOfValidation("actions", task.getName(), errors);
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskDataServiceBundleIT method shouldFindActiveTasksByTriggerSubject.
@Test
public void shouldFindActiveTasksByTriggerSubject() {
TaskActionInformation action = new TaskActionInformation("send", "test", MDS_ENTITIES_BUNDLE, "0.15", "SEND", new HashMap<String, String>());
TaskTriggerInformation trigger1 = new TaskTriggerInformation("receive-1", "test", MDS_ENTITIES_BUNDLE, "0.14", "RECEIVE-1", null);
TaskTriggerInformation trigger2 = new TaskTriggerInformation("receive-2", "test", "test", "0.14", "RECEIVE-2", null);
Task expected1 = new Task("name1", trigger1, asList(action), null, true, true);
Task expected2 = new Task("name2", trigger2, asList(action), null, true, false);
Task expected3 = new Task("name3", new TaskTriggerInformation(trigger1), asList(action), null, true, true);
tasksDataService.create(expected1);
tasksDataService.create(expected2);
tasksDataService.create(expected3);
assertEquals(new ArrayList<Task>(), taskService.findActiveTasksForTriggerSubject(""));
assertEquals(asList(expected1, expected3), taskService.findActiveTasksForTriggerSubject(trigger1.getSubject()));
assertEquals(new ArrayList<Task>(), taskService.findActiveTasksForTriggerSubject(trigger2.getSubject()));
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method prepareTaskActionInformationWithService.
private TaskActionInformation prepareTaskActionInformationWithService(String key, String value) {
TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
Map<String, String> values = new HashMap<>();
values.put(key, value);
actionInformation.setValues(values);
actionInformation.setServiceInterface("serviceInterface");
actionInformation.setServiceMethod("serviceMethod");
return actionInformation;
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method shouldRaiseEventWhenActionHasSubjectAndService_IfServiceIsNotAvailable.
@Test
public void shouldRaiseEventWhenActionHasSubjectAndService_IfServiceIsNotAvailable() 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<ActionParameter>()).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(eventRelay).sendEventMessage(any(MotechEvent.class));
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskActionExecutorTest method shouldInvokeServiceIfActionHasService.
@Test
public void shouldInvokeServiceIfActionHasService() throws ActionNotFoundException, TaskHandlerException {
TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").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);
TestService testService = new TestService();
when(bundleContext.getService(serviceReference)).thenReturn(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);
assertTrue(testService.serviceMethodInvoked());
}
Aggregations