Search in sources :

Example 51 with Task

use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.

the class TaskDataServiceBundleIT method shouldAddTaskAsNewIfItHasIDAndTaskNotExistInDB.

@Test
public void shouldAddTaskAsNewIfItHasIDAndTaskNotExistInDB() {
    Task expected = new TaskBuilder().withId(1L).withName("name").withTrigger(new TaskTriggerInformation("receive", "test", "test", "0.14", "RECEIVE", "RECEIVE")).addAction(new TaskActionInformation("send", "test", "test", "0.15", "SEND", new HashMap<String, String>())).build();
    tasksDataService.create(expected);
    List<Task> tasks = tasksDataService.retrieveAll();
    assertEquals(asList(expected), tasks);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Test(org.junit.Test)

Example 52 with Task

use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.

the class TaskDataServiceBundleIT method shouldSaveMoreThan255CharactersInTaskActionInformation.

@Test
public void shouldSaveMoreThan255CharactersInTaskActionInformation() {
    String value1 = RandomStringUtils.randomAlphanumeric(500);
    String value2 = RandomStringUtils.randomAlphanumeric(450);
    Map<String, String> values = new HashMap<>();
    values.put("value1", value1);
    values.put("value2", value2);
    TaskActionInformation action = new TaskActionInformation("action", "test", "test", "0.15", "SEND", values);
    TaskTriggerInformation trigger = new TaskTriggerInformation("trigger", "best", "test", "0.14", "RECEIVE-1", null);
    Task task = new Task("task1", trigger, asList(action));
    task = tasksDataService.create(task);
    Task taskFromDatabase = tasksDataService.findById(task.getId());
    assertEquals(value1, taskFromDatabase.getActions().get(0).getValues().get("value1"));
    assertEquals(value2, taskFromDatabase.getActions().get(0).getValues().get("value2"));
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Test(org.junit.Test)

Example 53 with Task

use of org.motechproject.tasks.domain.mds.task.Task 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 54 with Task

use of org.motechproject.tasks.domain.mds.task.Task 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 55 with Task

use of org.motechproject.tasks.domain.mds.task.Task 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

Task (org.motechproject.tasks.domain.mds.task.Task)86 Test (org.junit.Test)65 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)35 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)26 HashMap (java.util.HashMap)21 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)19 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)19 ArrayList (java.util.ArrayList)18 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)17 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)16 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)15 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)14 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)13 Channel (org.motechproject.tasks.domain.mds.channel.Channel)12 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)11 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 TreeSet (java.util.TreeSet)9 MotechEvent (org.motechproject.event.MotechEvent)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)9