Search in sources :

Example 16 with TaskBuilder

use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder 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 17 with TaskBuilder

use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder 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 18 with TaskBuilder

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

the class TaskDataServiceBundleIT method shouldAddTaskAsNewIfItHasIDAndTaskNotExistInDB.

@Test
public void shouldAddTaskAsNewIfItHasIDAndTaskNotExistInDB() {
    Task expected = new TaskBuilder().withId(1L).withName("name").withTrigger(new TaskTriggerInformation("receive", "test", "test", "0.14", "RECEIVE", "RECEIVE")).addAction(new TaskActionInformation("send", "test", "test", "0.15", "SEND", new HashMap<String, String>())).build();
    tasksDataService.create(expected);
    List<Task> tasks = tasksDataService.retrieveAll();
    assertEquals(asList(expected), tasks);
}
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) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Test(org.junit.Test)

Example 19 with TaskBuilder

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

the class TaskActionExecutorTest method shouldThrowExceptionIfBundleContextIsNotAvailable.

@Test(expected = TaskHandlerException.class)
public void shouldThrowExceptionIfBundleContextIsNotAvailable() throws TaskHandlerException, ActionNotFoundException {
    TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").setActionParameters(new TreeSet<>()).build();
    actionEvent.setActionParameters(new TreeSet<>());
    when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
    Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
    taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 20 with TaskBuilder

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

the class TaskActionExecutorTest method shouldThrowExceptionIfActionHasNeitherEventNorService.

@Test(expected = TaskHandlerException.class)
public void shouldThrowExceptionIfActionHasNeitherEventNorService() throws TaskHandlerException, ActionNotFoundException {
    TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").setActionParameters(new TreeSet<>()).build();
    actionEvent.setActionParameters(new TreeSet<>());
    when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
    Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
    taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Aggregations

Test (org.junit.Test)26 Task (org.motechproject.tasks.domain.mds.task.Task)26 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)26 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)24 HashMap (java.util.HashMap)11 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)8 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)8 TreeSet (java.util.TreeSet)7 TaskContext (org.motechproject.tasks.service.util.TaskContext)7 MotechEvent (org.motechproject.event.MotechEvent)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)4 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)4 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)4 ArrayList (java.util.ArrayList)3 Filter (org.motechproject.tasks.domain.mds.task.Filter)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 Matchers.anyString (org.mockito.Matchers.anyString)2