Search in sources :

Example 21 with TaskActionInformation

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

the class TaskServiceImplTest method shouldFailValidationIfTriggerChannelIsNotRegistered.

@Test
public void shouldFailValidationIfTriggerChannelIsNotRegistered() {
    TaskTriggerInformation trigger = new TaskTriggerInformation("triggerDisplay", "triggerChannel", "triggerModule", "1.0", "subject", "triggerListenerSubject");
    TaskActionInformation action = new TaskActionInformation("actionDisplay", "actionChannel", "actionModule", "1.0", "subject");
    Task fooTask = new TaskBuilder().withName("foo").withTrigger(trigger).withTaskConfig(new TaskConfig()).addAction(action).build();
    fooTask.setEnabled(true);
    when(channelService.getChannel("foo-module")).thenReturn(null);
    when(channelService.getChannel("actionModule")).thenReturn(null);
    Set<TaskError> errors = new HashSet<>();
    errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered"));
    when(triggerEventService.validateTrigger(trigger)).thenReturn(errors);
    expectedException.expect(ValidationException.class);
    expectedException.expect(new TypeSafeMatcher<ValidationException>() {

        @Override
        public void describeTo(Description description) {
        }

        @Override
        public boolean matchesSafely(ValidationException actualException) {
            final TaskErrorDto triggerChannelError = new TaskErrorDto("task.validation.error.triggerChannelNotRegistered");
            final TaskErrorDto actionChannelError = new TaskErrorDto("task.validation.error.actionChannelNotRegistered");
            Set<TaskErrorDto> taskErrors = actualException.getTaskErrors();
            return taskErrors.contains(triggerChannelError) && taskErrors.contains(actionChannelError);
        }
    });
    taskService.save(fooTask);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) ValidationException(org.motechproject.tasks.exception.ValidationException) Description(org.hamcrest.Description) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Set(java.util.Set) HashSet(java.util.HashSet) TaskErrorDto(org.motechproject.tasks.dto.TaskErrorDto) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with TaskActionInformation

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

the class TaskFilterExecutorTest method shouldThrowExceptionIfDataSourceObjectIsNotFound.

@Test(expected = TaskHandlerException.class)
public void shouldThrowExceptionIfDataSourceObjectIsNotFound() throws TaskHandlerException {
    List<Filter> filters = new ArrayList<>();
    List<String> filtersManipulations = new ArrayList<>();
    filters.add(new Filter("MRS.Person#2.Age", "ad.2.Person#2.age", INTEGER, false, EXIST.getValue(), "", filtersManipulations));
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    TaskContext taskContext = new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService);
    new TaskFilterExecutor().checkFilters(filters, LogicalOperator.AND, taskContext);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) Filter(org.motechproject.tasks.domain.mds.task.Filter) ArrayList(java.util.ArrayList) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 23 with TaskActionInformation

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

the class ProviderNameTaskMigrator method migrateActions.

private void migrateActions(Task task) {
    // replace data source references in actions
    for (TaskActionInformation action : task.getActions()) {
        for (Map.Entry<String, String> entry : action.getValues().entrySet()) {
            String oldVal = entry.getValue();
            String newVal = replaceTaskValue(oldVal, EXPR_PATTERN, task);
            entry.setValue(newVal);
        }
    }
}
Also used : TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Map(java.util.Map)

Example 24 with TaskActionInformation

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

the class TaskAnnotationBeanPostProcessor method getAction.

private ActionEvent getAction(Channel channel, String serviceInterface, Method method, String actionName) {
    TaskActionInformation info = new TaskActionInformation(method.getName(), actionName, channel.getDisplayName(), channel.getModuleName(), channel.getModuleVersion(), serviceInterface, method.getName());
    ActionEvent actionEvent = null;
    for (ActionEvent action : channel.getActionTaskEvents()) {
        if (action.accept(info)) {
            actionEvent = action;
            break;
        }
    }
    return actionEvent;
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation)

Example 25 with TaskActionInformation

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

the class TaskDataServiceBundleIT method shouldFindTasksThatDependOnAModule.

@Test
public void shouldFindTasksThatDependOnAModule() {
    TaskTriggerInformation trigger1 = new TaskTriggerInformation("trigger1", "best", "test", "0.14", "RECEIVE-1", null);
    TaskTriggerInformation trigger2 = new TaskTriggerInformation("trigger2", "lest", "jest", "0.14", "RECEIVE-2", null);
    TaskActionInformation action1 = new TaskActionInformation("action1", "test", "test", "0.15", "SEND");
    TaskActionInformation action2 = new TaskActionInformation("action2", "fest", "test", "0.12", "actionSubject");
    TaskActionInformation action3 = new TaskActionInformation("action2", "fest", "jest", "0.12", "actionSubject");
    Task[] tasks = new Task[] { new Task("task1", trigger1, asList(action1)), new Task("task2", trigger2, asList(action3)), new Task("task3", new TaskTriggerInformation(trigger1), asList(action2)), new Task("task4", new TaskTriggerInformation(trigger2), asList(action1)) };
    for (Task task : tasks) {
        tasksDataService.create(task);
    }
    List<String> tasksUsingTestModule = extract(taskService.findTasksDependentOnModule("test"), on(Task.class).getName());
    assertTrue(tasksUsingTestModule.contains("task1"));
    assertTrue(tasksUsingTestModule.contains("task3"));
    assertTrue(tasksUsingTestModule.contains("task4"));
    assertFalse(tasksUsingTestModule.contains("task2"));
}
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) 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