use of org.motechproject.tasks.domain.mds.channel.ActionEvent in project motech by motech.
the class TaskActionExecutorTest method prepareActionEvent.
private ActionEvent prepareActionEvent() {
ActionEvent actionEvent = new ActionEvent();
actionEvent.setDisplayName("Action");
actionEvent.setSubject("actionSubject");
actionEvent.setDescription("");
SortedSet<ActionParameter> parameters = new TreeSet<>();
ActionParameter parameter = new ActionParameter();
parameter.setDisplayName("Map");
parameter.setKey("map");
parameter.setType(MAP);
parameter.setOrder(1);
parameters.add(parameter);
actionEvent.setActionParameters(parameters);
actionEvent.setPostActionParameters(parameters);
return actionEvent;
}
use of org.motechproject.tasks.domain.mds.channel.ActionEvent 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.channel.ActionEvent 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.channel.ActionEvent 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.channel.ActionEvent 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