use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation 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.TaskTriggerInformation in project motech by motech.
the class TriggerEventServiceImplTest method shouldValidateDynamicTrigger.
@Test
public void shouldValidateDynamicTrigger() throws Exception {
TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 1992);
when(triggerEventsDataService.countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject())).thenReturn((long) 0);
when(dynamicChannelLoader.channelExists(MODULE_NAME)).thenReturn(true);
when(dynamicChannelLoader.validateTrigger(MODULE_NAME, triggerInformation.getSubject())).thenReturn(true);
Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
verify(triggerEventsDataService, times(1)).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
verify(dynamicChannelLoader, times(1)).channelExists(MODULE_NAME);
verify(dynamicChannelLoader, times(1)).validateTrigger(MODULE_NAME, triggerInformation.getSubject());
assertEquals(0, errors.size());
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TriggerEventServiceImplTest method shouldGetTrigger.
@Test
public void shouldGetTrigger() throws Exception {
TriggerEvent expectedTrigger = prepareTrigger();
TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(expectedTrigger);
when(triggerEventsDataService.byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject())).thenReturn(null);
when(dynamicChannelLoader.getTrigger(eq(triggerInformation))).thenReturn(expectedTrigger);
TriggerEvent trigger = triggerEventService.getTrigger(triggerInformation);
verify(triggerEventsDataService, times(1)).byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject());
verify(dynamicChannelLoader, times(1)).getTrigger(triggerInformation);
assertEquals(expectedTrigger, trigger);
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TriggerEventServiceImplTest method shouldReturnTrueIfTriggerExists.
@Test
public void shouldReturnTrueIfTriggerExists() throws Exception {
TriggerEvent expectedTrigger = prepareTrigger();
TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(expectedTrigger);
when(triggerEventsDataService.byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject())).thenReturn(null);
when(dynamicChannelLoader.getTrigger(eq(triggerInformation))).thenReturn(expectedTrigger);
boolean exists = triggerEventService.triggerExists(triggerInformation);
verify(triggerEventsDataService, times(1)).byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject());
verify(dynamicChannelLoader, times(1)).getTrigger(triggerInformation);
assertTrue(exists);
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TriggerEventServiceImplTest method shouldReturnFalseIfTriggerDoesNotExist.
@Test
public void shouldReturnFalseIfTriggerDoesNotExist() throws Exception {
TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
when(triggerEventsDataService.byChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject())).thenReturn(null);
when(dynamicChannelLoader.getTrigger(eq(triggerInformation))).thenReturn(null);
boolean exists = triggerEventService.triggerExists(triggerInformation);
verify(triggerEventsDataService, times(1)).byChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
verify(dynamicChannelLoader, times(1)).getTrigger(triggerInformation);
assertFalse(exists);
}
Aggregations