Search in sources :

Example 41 with Task

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

the class TaskServiceImplTest method shouldGetTaskById.

@Test
public void shouldGetTaskById() {
    long taskId = 12345L;
    Task expected = new Task();
    expected.setId(taskId);
    when(tasksDataService.findById(taskId)).thenReturn(expected);
    Task actual = taskService.getTask(taskId);
    assertEquals(expected, actual);
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) Test(org.junit.Test)

Example 42 with Task

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

the class TaskServiceImplTest method shouldNotSaveTaskWithDuplicateName.

@Test(expected = TaskNameAlreadyExistsException.class)
public void shouldNotSaveTaskWithDuplicateName() {
    when(tasksDataService.findTasksByName("name")).thenReturn(asList(new Task("name", trigger, asList(action))));
    Task t = new Task("name", trigger, asList(action), null, false, false);
    try {
        taskService.save(t);
    } finally {
        verify(tasksDataService, times(1)).findTasksByName(t.getName());
        verifyNoMoreInteractions(tasksDataService);
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) Test(org.junit.Test)

Example 43 with Task

use of org.motechproject.tasks.domain.mds.task.Task 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 44 with Task

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

the class TaskServiceImplTest method shouldNotSaveTaskWithoutTrigger.

@Test(expected = ValidationException.class)
public void shouldNotSaveTaskWithoutTrigger() {
    Task t = new Task("name", null, asList(action));
    taskService.save(t);
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) Test(org.junit.Test)

Example 45 with Task

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

the class TaskServiceImplTest method shouldNotSaveTaskWithInvalidRetryNumberValue.

@Test(expected = ValidationException.class)
public void shouldNotSaveTaskWithInvalidRetryNumberValue() {
    Task t = new Task("name", trigger, asList(action));
    t.setNumberOfRetries(-3);
    try {
        taskService.save(t);
    } finally {
        verifyZeroInteractions(tasksDataService);
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) Test(org.junit.Test)

Aggregations

Task (org.motechproject.tasks.domain.mds.task.Task)86 Test (org.junit.Test)65 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)35 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)26 HashMap (java.util.HashMap)21 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)19 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)19 ArrayList (java.util.ArrayList)18 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)17 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)16 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)15 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)14 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)13 Channel (org.motechproject.tasks.domain.mds.channel.Channel)12 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)11 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 TreeSet (java.util.TreeSet)9 MotechEvent (org.motechproject.event.MotechEvent)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)9