Search in sources :

Example 1 with FilterSet

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"));
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) HashMap(java.util.HashMap) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) Matchers.anyString(org.mockito.Matchers.anyString) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) DataProvider(org.motechproject.commons.api.DataProvider) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskHandlerException(org.motechproject.tasks.exception.TaskHandlerException) Filter(org.motechproject.tasks.domain.mds.task.Filter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 2 with FilterSet

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);
}
Also used : FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Filter(org.motechproject.tasks.domain.mds.task.Filter) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 3 with FilterSet

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));
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) HashMap(java.util.HashMap) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) Matchers.anyString(org.mockito.Matchers.anyString) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) DataProvider(org.motechproject.commons.api.DataProvider) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskHandlerException(org.motechproject.tasks.exception.TaskHandlerException) Filter(org.motechproject.tasks.domain.mds.task.Filter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 4 with FilterSet

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));
}
Also used : FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Filter(org.motechproject.tasks.domain.mds.task.Filter) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Example 5 with FilterSet

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));
}
Also used : FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Filter(org.motechproject.tasks.domain.mds.task.Filter) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)16 Test (org.junit.Test)11 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)11 ArrayList (java.util.ArrayList)9 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)9 Filter (org.motechproject.tasks.domain.mds.task.Filter)7 Matchers.anyString (org.mockito.Matchers.anyString)5 Task (org.motechproject.tasks.domain.mds.task.Task)5 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)4 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)4 MotechEvent (org.motechproject.event.MotechEvent)3 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)3 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)3 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)3 TaskConfigStep (org.motechproject.tasks.domain.mds.task.TaskConfigStep)3 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)3 HashMap (java.util.HashMap)2 Random (java.util.Random)2 DataProvider (org.motechproject.commons.api.DataProvider)2 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)2