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