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);
}
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);
}
}
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);
}
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);
}
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);
}
}
Aggregations