use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskDataServiceBundleIT method shouldFindTasksByName.
@Test
public void shouldFindTasksByName() {
String taskName = "test";
Task[] tasks = new Task[] { new Task(taskName, null, null), new Task("abc", null, null), new Task("test2", null, null) };
for (Task task : tasks) {
tasksDataService.create(task);
}
List<String> tasksByName = extract(tasksDataService.findTasksByName(taskName), on(Task.class).getName());
assertTrue(tasksByName.contains(taskName));
assertFalse(tasksByName.contains("abc"));
assertFalse(tasksByName.contains("test2"));
}
use of org.motechproject.tasks.domain.mds.task.Task 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.Task 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());
}
use of org.motechproject.tasks.domain.mds.task.Task 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.Task 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");
}
Aggregations