Search in sources :

Example 26 with TaskActionInformation

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

the class TaskDataServiceBundleIT method shouldAddAndUpdateTask.

@Test
public void shouldAddAndUpdateTask() {
    TaskActionInformation action = new TaskActionInformation("send", "test", "test", "0.15", "SEND", new HashMap<String, String>());
    TaskTriggerInformation trigger = new TaskTriggerInformation("receive", "test", "test", "0.14", "RECEIVE", null);
    Task expected = new Task("name", trigger, asList(action));
    tasksDataService.create(expected);
    List<Task> tasks = tasksDataService.retrieveAll();
    assertEquals(asList(expected), tasks);
    Task actual = tasks.get(0);
    actual.setName("newName");
    tasksDataService.update(actual);
    tasks = tasksDataService.retrieveAll();
    assertEquals(asList(actual), tasks);
}
Also used : 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 27 with TaskActionInformation

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

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

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

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

Aggregations

TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)44 Task (org.motechproject.tasks.domain.mds.task.Task)34 Test (org.junit.Test)32 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)24 HashMap (java.util.HashMap)18 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)14 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)12 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 TreeSet (java.util.TreeSet)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)9 TaskContext (org.motechproject.tasks.service.util.TaskContext)8 MotechEvent (org.motechproject.event.MotechEvent)7 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)6 ArrayList (java.util.ArrayList)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 HashSet (java.util.HashSet)3 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)3 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)3