Search in sources :

Example 36 with TaskActionInformation

use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.

the class TaskControllerTest method shouldSaveTask.

@Test
public void shouldSaveTask() {
    String subject = "trigger1";
    TaskActionInformation action = new TaskActionInformation("send", "action1", "action", "0.15", "send", new HashMap<String, String>());
    TaskTriggerInformation trigger = new TaskTriggerInformation("trigger", "trigger1", "trigger", "0.16", subject, subject);
    Task expected = new Task("name", trigger, asList(action));
    when(eventListenerRegistryService.getListeners(subject)).thenReturn(new HashSet<EventListener>());
    controller.save(expected);
    verify(taskWebService).save(expected);
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) EventListener(org.motechproject.event.listener.EventListener) Test(org.junit.Test)

Example 37 with TaskActionInformation

use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.

the class TaskBuilderTest method shouldReturnBuiltTaskObject.

@Test
public void shouldReturnBuiltTaskObject() throws Exception {
    TaskBuilder builder = new TaskBuilder();
    Task task = builder.withName(TASK_NAME).withDescription(TASK_DESCRIPTION).isEnabled(isEnabled).withTrigger(new TaskTriggerInformation()).addAction(new TaskActionInformation()).withTaskConfig(new TaskConfig()).addFilterSet(new FilterSet()).addDataSource(new DataSource()).build();
    assertNotNull(task);
    assertEquals(TASK_NAME, task.getName());
    assertEquals(TASK_DESCRIPTION, task.getDescription());
    assertEquals(isEnabled, task.isEnabled());
    assertNotNull(task.getTrigger());
    assertNotNull(task.getActions());
    assertFalse(task.getActions().isEmpty());
    assertNotNull(task.getTaskConfig());
    assertFalse(task.getTaskConfig().getDataSources().isEmpty());
    assertFalse(task.getTaskConfig().getFilters().isEmpty());
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) Test(org.junit.Test)

Example 38 with TaskActionInformation

use of org.motechproject.tasks.domain.mds.task.TaskActionInformation in project motech by motech.

the class ActionParametersBundleIT method prepareActionWithKeyValue.

private TaskActionInformation prepareActionWithKeyValue(String key, String value) {
    TaskActionInformation actionInformation = new TaskActionInformation(TASK_TEST_ACTION_NAME, TASK_TEST_CHANNEL_NAME, TASK_TEST_CHANNEL_NAME, VERSION, TASK_TEST_SERVICE_INTERFACE, TASK_TEST_SERVICE_METHOD);
    Map<String, String> values = new HashMap<>();
    values.put(key, value);
    actionInformation.setValues(values);
    return actionInformation;
}
Also used : HashMap(java.util.HashMap) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation)

Example 39 with TaskActionInformation

use of org.motechproject.tasks.domain.mds.task.TaskActionInformation 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();
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ArrayList(java.util.ArrayList)

Example 40 with TaskActionInformation

use of org.motechproject.tasks.domain.mds.task.TaskActionInformation 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"));
}
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)

Aggregations

TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)44 Task (org.motechproject.tasks.domain.mds.task.Task)34 Test (org.junit.Test)32 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)24 HashMap (java.util.HashMap)18 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)14 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)12 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 TreeSet (java.util.TreeSet)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)9 TaskContext (org.motechproject.tasks.service.util.TaskContext)8 MotechEvent (org.motechproject.event.MotechEvent)7 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)6 ArrayList (java.util.ArrayList)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 HashSet (java.util.HashSet)3 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)3 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)3