use of org.motechproject.tasks.domain.mds.task.FilterSet in project motech by motech.
the class TaskTriggerHandlerTest method shouldNotTriggerErrorWhenFilterDoesNotFindDataSourceWithFailIfDataNotFoundNotSelected.
@Test
public void shouldNotTriggerErrorWhenFilterDoesNotFindDataSourceWithFailIfDataNotFoundNotSelected() throws Exception {
Map<String, DataProvider> providers = new HashMap<>();
DataProvider provider = mock(DataProvider.class);
Map<String, String> lookup = new HashMap<>();
List<String> filtersManipulations = new ArrayList<>();
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);
Task task = new Task();
task.setName("task");
task.setId(44l);
task.setTrigger(new TaskTriggerInformation("Trigger", "channel", "module", "0.1", "trigger", "listener"));
task.setHasRegisteredChannel(true);
task.setActions(Collections.<TaskActionInformation>emptyList());
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")), false));
taskConfig.add(new FilterSet(asList(new Filter("Patient ID", "ad.12345.Patient#1.patientId", INTEGER, false, EXIST.getValue(), "", filtersManipulations))));
List<Task> tasks = asList(task);
when(taskService.findActiveTasksForTriggerSubject("trigger")).thenReturn(tasks);
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.FilterSet in project motech by motech.
the class TaskTriggerHandlerTest method shouldNotPassFiltersCriteria.
@Test
public void shouldNotPassFiltersCriteria() throws Exception {
List<String> filtersManipulations = new ArrayList<>();
setTriggerEvent();
setActionEvent();
setFilters();
task.getTaskConfig().add(new FilterSet(asList(new Filter("ExternalID (Trigger)", "trigger.externalId", INTEGER, false, EXIST.getValue(), "", filtersManipulations))));
when(taskService.findActiveTasksForTriggerSubject(TRIGGER_SUBJECT)).thenReturn(tasks);
when(taskService.getActionEventFor(task.getActions().get(0))).thenReturn(actionEvent);
handler.handle(createEvent());
verify(taskService).findActiveTasksForTriggerSubject(TRIGGER_SUBJECT);
verify(taskService, never()).getActionEventFor(task.getActions().get(0));
verify(eventRelay, never()).sendEventMessage(any(MotechEvent.class));
verify(taskActivityService).addTaskFiltered(TASK_ACTIVITY_ID);
}
use of org.motechproject.tasks.domain.mds.task.FilterSet in project motech by motech.
the class TaskTriggerHandlerTest method shouldTriggerErrorWhenFilterDoesNotFindDataSourceWithFailIfDataNotFoundSelected.
@Test
public void shouldTriggerErrorWhenFilterDoesNotFindDataSourceWithFailIfDataNotFoundSelected() throws Exception {
Map<String, DataProvider> providers = new HashMap<>();
DataProvider provider = mock(DataProvider.class);
Map<String, String> lookup = new HashMap<>();
List<String> filtersManipulations = new ArrayList<>();
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);
Task task = new Task();
task.setName("task");
task.setId(77l);
task.setTrigger(new TaskTriggerInformation("Trigger", "channel", "module", "0.1", "trigger", "listener"));
task.setHasRegisteredChannel(true);
task.setActions(Collections.<TaskActionInformation>emptyList());
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));
taskConfig.add(new FilterSet(asList(new Filter("Patient ID", "ad.12345.Patient#1.patientId", INTEGER, false, EXIST.getValue(), "", filtersManipulations))));
List<Task> tasks = asList(task);
when(taskService.findActiveTasksForTriggerSubject("trigger")).thenReturn(tasks);
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.FilterSet in project motech by motech.
the class TaskTriggerHandlerTest method setFilters.
private void setFilters() {
List<Filter> filters = new ArrayList<>();
List<String> filtersManipulations = new ArrayList<>();
filters.add(new Filter("EventName (Trigger)", "trigger.eventName", UNICODE, true, CONTAINS.getValue(), "ven", filtersManipulations));
filters.add(new Filter("EventName (Trigger)", "trigger.eventName", UNICODE, true, EXIST.getValue(), "", filtersManipulations));
filters.add(new Filter("EventName (Trigger)", "trigger.eventName", UNICODE, true, EQUALS.getValue(), "event name", filtersManipulations));
filters.add(new Filter("EventName (Trigger)", "trigger.eventName", UNICODE, true, EQUALS_IGNORE_CASE.getValue(), "EvEnT nAmE", filtersManipulations));
filters.add(new Filter("EventName (Trigger)", "trigger.eventName", UNICODE, true, STARTSWITH.getValue(), "ev", filtersManipulations));
filters.add(new Filter("EventName (Trigger)", "trigger.eventName", UNICODE, true, ENDSWITH.getValue(), "me", filtersManipulations));
filters.add(new Filter("ExternalID (Trigger)", "trigger.externalId", INTEGER, true, GT.getValue(), "19", filtersManipulations));
filters.add(new Filter("ExternalID (Trigger)", "trigger.externalId", INTEGER, true, LT.getValue(), "1234567891", filtersManipulations));
filters.add(new Filter("ExternalID (Trigger)", "trigger.externalId", INTEGER, true, EQ_NUMBER.getValue(), "123456789", filtersManipulations));
filters.add(new Filter("ExternalID (Trigger)", "trigger.externalId", INTEGER, true, EXIST.getValue(), "", filtersManipulations));
filters.add(new Filter("ExternalID (Trigger)", "trigger.externalId", INTEGER, false, GT.getValue(), "1234567891", filtersManipulations));
task.getTaskConfig().add(new FilterSet(filters));
}
use of org.motechproject.tasks.domain.mds.task.FilterSet in project motech by motech.
the class TaskTriggerHandlerTest method addActionFilterNotPassingCriteria.
private void addActionFilterNotPassingCriteria() {
List<String> filtersManipulations = new ArrayList<>();
task.getTaskConfig().add(new FilterSet(asList(new Filter("ExternalID (Trigger)", "trigger.externalId", INTEGER, false, EXIST.getValue(), "", filtersManipulations)), LogicalOperator.AND, 1));
}
Aggregations