Search in sources :

Example 6 with TaskContext

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));
}
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) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 7 with TaskContext

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

Example 8 with TaskContext

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);
}
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)

Example 9 with TaskContext

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);
}
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

TaskContext (org.motechproject.tasks.service.util.TaskContext)9 Test (org.junit.Test)8 ObjectTest (org.motechproject.tasks.domain.ObjectTest)8 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)8 Task (org.motechproject.tasks.domain.mds.task.Task)8 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)8 HashMap (java.util.HashMap)7 TreeSet (java.util.TreeSet)7 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)7 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)7 MotechEvent (org.motechproject.event.MotechEvent)3 ServiceReference (org.osgi.framework.ServiceReference)3 ArrayList (java.util.ArrayList)1 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)1 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)1