use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class ActionParametersBundleIT method createTestTask.
private Long createTestTask() {
TaskTriggerInformation triggerInformation = new TaskTriggerInformation("CREATE SettingsRecord", "data-services", MDS_CHANNEL_NAME, VERSION, TRIGGER_SUBJECT, TRIGGER_SUBJECT);
List<TaskActionInformation> actions = new ArrayList<>();
actions.add(prepareActionWithKeyValue("testName", "ActionValue"));
actions.add(prepareActionWithKeyValue("testName", "{{pa.0.testNameWithPrefix}}"));
actions.add(prepareActionWithKeyValue("testName", "{{pa.1.testNameWithPrefix}}"));
Task task = new Task("TestTask", triggerInformation, actions, null, true, true);
taskService.save(task);
triggerHandler.registerHandlerFor(task.getTrigger().getEffectiveListenerSubject());
return task.getId();
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskActivityServiceImplTest method setup.
@Before
public void setup() throws Exception {
initMocks(this);
activityService = new TaskActivityServiceImpl(taskActivitiesDataService);
activities = createTaskActivities();
task = new Task();
task.setId(TASK_ID);
task.setFailuresInRow(0);
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskTriggerHandlerTest method shouldNotTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundNotSelected.
@Test
public void shouldNotTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundNotSelected() throws Exception {
Map<String, DataProvider> providers = new HashMap<>();
DataProvider provider = mock(DataProvider.class);
Map<String, String> lookup = new HashMap<>();
lookup.put("patientId", "123");
when(provider.lookup("Patient", null, lookup)).thenReturn(null);
providers.put(TASK_DATA_PROVIDER_NAME, provider);
handler.setDataProviders(providers);
TriggerEvent trigger = new TriggerEvent();
trigger.setSubject("trigger");
List<EventParameter> triggerEventParameters = new ArrayList<>();
triggerEventParameters.add(new EventParameter("patientId", "123"));
trigger.setEventParameters(triggerEventParameters);
ActionEvent action = new ActionEventBuilder().build();
action.setSubject("action");
SortedSet<ActionParameter> actionEventParameters = new TreeSet<>();
actionEventParameters.add(new ActionParameterBuilder().setDisplayName("Patient ID").setKey("patientId").setType(UNICODE).setOrder(0).build());
action.setActionParameters(actionEventParameters);
Task task = new Task();
task.setName("task");
task.setTrigger(new TaskTriggerInformation("Trigger", "channel", "module", "0.1", "trigger", "listener"));
Map<String, String> actionValues = new HashMap<>();
actionValues.put("patientId", "{{ad.12345.Patient#1.patientId}}");
task.addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "action", actionValues));
task.setId(7l);
task.setHasRegisteredChannel(true);
TaskConfig taskConfig = new TaskConfig();
task.setTaskConfig(taskConfig);
taskConfig.add(new DataSource(TASK_DATA_PROVIDER_NAME, 3L, 1L, "Patient", "provider", "specifiedName", asList(new Lookup("patientId", "trigger.patientId")), false));
List<Task> tasks = asList(task);
when(taskService.findActiveTasksForTriggerSubject("trigger")).thenReturn(tasks);
when(taskService.getActionEventFor(task.getActions().get(0))).thenReturn(action);
setTaskActivities();
task.setFailuresInRow(taskActivities.size());
Map<String, Object> param = new HashMap<>(4);
param.put("patientId", "123");
handler.handle(new MotechEvent("trigger", param));
verify(postExecutionHandler, never()).handleError(anyMap(), anyMap(), eq(task), any(TaskHandlerException.class), eq(TASK_ACTIVITY_ID));
verify(taskActivityService).addWarning(eq(task), eq("task.warning.notFoundObjectForType"), eq("Patient"));
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskContextTest method shouldThrowExceptionWhenDataSourceIsNull.
@Test
public void shouldThrowExceptionWhenDataSourceIsNull() throws Exception {
Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
TaskContext taskContext = new TaskContext(task, null, null, activityService);
taskContext.addDataSourceObject("1", null, true);
KeyInformation key = parse("ad.1.Integer#1.id");
expectedException.expect(TaskHandlerException.class);
expectedException.expect(new TaskHandlerExceptionMatcher(TaskFailureCause.DATA_SOURCE, "task.error.objectOfTypeNotFound", key.getObjectType()));
taskContext.getDataSourceObjectValue(key.getObjectId().toString(), key.getKey(), key.getObjectType());
}
use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.
the class TaskContextTest method testGetDataSourceValue.
@Test
public void testGetDataSourceValue() throws Exception {
Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
TaskContext taskContext = new TaskContext(task, null, null, activityService);
taskContext.addDataSourceObject("1", new TestDataSourceObject(), true);
KeyInformation key = parse("ad.1.Integer#1.id");
assertEquals(OBJECT_ID.intValue(), taskContext.getDataSourceObjectValue(key.getObjectId().toString(), key.getKey(), key.getObjectType()));
}
Aggregations