Search in sources :

Example 1 with ActionParameterBuilder

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

Example 2 with ActionParameterBuilder

use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.

the class TaskTriggerHandlerTest method setAdditionalData.

private void setAdditionalData(boolean isFail) {
    task.getActions().get(0).getValues().put("dataSourceTrigger", "test: {{ad.12345.TestObjectField#1.id}}");
    task.getActions().get(0).getValues().put("dataSourceObject", "test: {{ad.12345.TestObject#2.field.id}}");
    actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Data source by trigger").setKey("dataSourceTrigger").build(), true);
    actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Data source by data source object").setKey("dataSourceObject").build(), true);
    task.getTaskConfig().add(new DataSource(TASK_DATA_PROVIDER_NAME, 4L, 1L, "TestObjectField", "id", "specifiedName", asList(new Lookup("id", "{{trigger.externalId}}")), isFail));
    task.getTaskConfig().add(new DataSource(TASK_DATA_PROVIDER_NAME, 4L, 2L, "TestObject", "id", "specifiedName", asList(new Lookup("id", "{{trigger.externalId}}-{{ad.12345.TestObjectField#1.id}}")), isFail));
    handler.addDataProvider(dataProvider);
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) DataSource(org.motechproject.tasks.domain.mds.task.DataSource)

Example 3 with ActionParameterBuilder

use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.

the class TaskTriggerHandlerTest method setDoubleField.

private void setDoubleField() {
    task.getActions().get(0).getValues().put("double", "123.5");
    actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Double").setKey("double").setType(DOUBLE).build(), true);
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)

Example 4 with ActionParameterBuilder

use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.

the class TaskTriggerHandlerTest method setMapField.

private void setMapField() {
    task.getActions().get(0).getValues().put("map", "key1:value\n{{trigger.map}}\n{{trigger.eventName}}:{{ad.12345.TestObjectField#1.id}}");
    actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Map").setKey("map").setType(MAP).build(), true);
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)

Example 5 with ActionParameterBuilder

use of org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder in project motech by motech.

the class TaskTriggerHandlerTest method setTimeField.

private void setTimeField() {
    task.getActions().get(0).getValues().put("time", "21:21 +0100");
    actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Time").setKey("time").setType(TIME).build(), true);
}
Also used : ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)

Aggregations

ActionParameterBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)19 TreeSet (java.util.TreeSet)6 ActionParameter (org.motechproject.tasks.domain.mds.channel.ActionParameter)6 Test (org.junit.Test)5 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)5 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)5 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)4 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)4 Task (org.motechproject.tasks.domain.mds.task.Task)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 MotechEvent (org.motechproject.event.MotechEvent)3 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)3 Annotation (java.lang.annotation.Annotation)2 DataProvider (org.motechproject.commons.api.DataProvider)2 Channel (org.motechproject.tasks.domain.mds.channel.Channel)2 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)2