use of org.motechproject.tasks.service.util.TaskContext 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));
}
use of org.motechproject.tasks.service.util.TaskContext in project motech by motech.
the class TaskActionExecutorTest method shouldExecuteTaskAndUsePostActionParameters.
@Test
public void shouldExecuteTaskAndUsePostActionParameters() throws Exception {
TaskActionInformation actionInformation = prepareTaskActionInformationWithService("key", "value");
TaskActionInformation actionInformationWithPostActionParameter = prepareTaskActionInformationWithService("key", "{{pa.0.testKey}}");
ActionEvent actionEvent = prepareActionEventWithService();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
when(taskService.getActionEventFor(actionInformationWithPostActionParameter)).thenReturn(actionEvent);
ServiceReference serviceReference = mock(ServiceReference.class);
when(bundleContext.getServiceReference("serviceInterface")).thenReturn(serviceReference);
when(bundleContext.getService(serviceReference)).thenReturn(new TestService());
Task task = new Task();
task.addAction(actionInformation);
task.addAction(actionInformationWithPostActionParameter);
taskActionExecutor.setBundleContext(bundleContext);
TaskContext taskContext = new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService);
for (TaskActionInformation action : task.getActions()) {
taskActionExecutor.execute(task, action, task.getActions().indexOf(action), taskContext, TASK_ACTIVITY_ID);
}
assertEquals("testObject", taskContext.getPostActionParameterValue("0", "testKey"));
assertEquals("testObject", taskContext.getPostActionParameterValue("1", "testKey"));
}
use of org.motechproject.tasks.service.util.TaskContext in project motech by motech.
the class TaskActionExecutorTest method shouldThrowExceptionIfBundleContextIsNotAvailable.
@Test(expected = TaskHandlerException.class)
public void shouldThrowExceptionIfBundleContextIsNotAvailable() throws TaskHandlerException, ActionNotFoundException {
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();
actionEvent.setActionParameters(new TreeSet<>());
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
}
use of org.motechproject.tasks.service.util.TaskContext in project motech by motech.
the class TaskActionExecutorTest method shouldThrowExceptionIfActionHasNeitherEventNorService.
@Test(expected = TaskHandlerException.class)
public void shouldThrowExceptionIfActionHasNeitherEventNorService() throws TaskHandlerException, ActionNotFoundException {
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();
actionEvent.setActionParameters(new TreeSet<>());
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
}
Aggregations