Search in sources :

Example 6 with ActionEvent

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;
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter)

Example 7 with 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));
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 8 with ActionEvent

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());
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 9 with ActionEvent

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()));
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 10 with ActionEvent

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");
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Aggregations

ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)32 Test (org.junit.Test)21 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)18 Task (org.motechproject.tasks.domain.mds.task.Task)13 TreeSet (java.util.TreeSet)12 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)12 HashMap (java.util.HashMap)10 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)9 Channel (org.motechproject.tasks.domain.mds.channel.Channel)8 TaskContext (org.motechproject.tasks.service.util.TaskContext)8 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)7 MotechEvent (org.motechproject.event.MotechEvent)6 ArrayList (java.util.ArrayList)5 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)5 ActionParameterBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)5 ActionParameter (org.motechproject.tasks.domain.mds.channel.ActionParameter)4 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)4 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)4 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)3