use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskTriggerHandlerTest method shouldTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundSelected.
@Test
public void shouldTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundSelected() 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", "", 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.providerId.Patient#1.patientId}}");
task.addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "action", actionValues));
task.setId(44l);
task.setHasRegisteredChannel(true);
TaskConfig taskConfig = new TaskConfig();
task.setTaskConfig(taskConfig);
taskConfig.add(new DataSource(TASK_DATA_PROVIDER_NAME, 4L, 1L, "Patient", "provider", "specifiedName", asList(new Lookup("patientId", "trigger.patientId")), true));
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).handleError(anyMap(), anyMap(), eq(task), any(TaskHandlerException.class), eq(TASK_ACTIVITY_ID));
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TasksTestBase method initTask.
protected void initTask() throws Exception {
Map<String, String> actionValues = new HashMap<>();
actionValues.put("phone", "123456");
actionValues.put("message", "Hello {{trigger.externalId}}, You have an appointment on {{trigger.startDate}}");
TaskTriggerInformation trigger = new TaskTriggerInformation("appointments", "Appointments", "appointments-bundle", "0.15", TRIGGER_SUBJECT, TRIGGER_SUBJECT);
TaskActionInformation action = new TaskActionInformation("sms", "SMS", "sms-bundle", "0.15", ACTION_SUBJECT, actionValues);
task = new Task();
task.setName("name");
task.setTrigger(trigger);
task.addAction(action);
task.setId(9l);
task.setHasRegisteredChannel(true);
tasks.add(task);
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskContextTest method shouldThrowExceptionWhenAccessingUnconfiguredDataSource.
@Test
public void shouldThrowExceptionWhenAccessingUnconfiguredDataSource() throws Exception {
Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
TaskContext taskContext = new TaskContext(task, null, null, activityService);
taskContext.addDataSourceObject("1", new TestDataSourceObject(), false);
KeyInformation key = parse("ad.1.Integer#2.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.TaskActionInformation in project motech by motech.
the class TaskContextTest method testGetDataSourceValueForBooleanWithGetterIs.
@Test
public void testGetDataSourceValueForBooleanWithGetterIs() 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.Boolean#1.checked");
assertEquals(true, taskContext.getDataSourceObjectValue(key.getObjectId().toString(), key.getKey(), key.getObjectType()));
}
use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.
the class TaskContextTest method shouldThrowExceptionWhenDataSourceFieldValueEvaluationThrowsException.
@Test
public void shouldThrowExceptionWhenDataSourceFieldValueEvaluationThrowsException() 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.providerId");
expectedException.expect(TaskHandlerException.class);
expectedException.expect(new TaskHandlerExceptionMatcher(TaskFailureCause.DATA_SOURCE, "task.error.objectDoesNotContainField", key.getKey()));
taskContext.getDataSourceObjectValue(key.getObjectId().toString(), key.getKey(), key.getObjectType());
}
Aggregations