use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TriggerEventServiceImplTest method shouldReturnChannelNotFoundErrorIfTriggerDoesNotExist.
@Test
public void shouldReturnChannelNotFoundErrorIfTriggerDoesNotExist() throws Exception {
TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 0);
when(dynamicChannelLoader.channelExists(MODULE_NAME)).thenReturn(true);
when(dynamicChannelLoader.validateTrigger(MODULE_NAME, triggerInformation.getSubject())).thenReturn(false);
Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
verify(triggerEventsDataService, never()).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
verify(dynamicChannelLoader, times(1)).channelExists(MODULE_NAME);
verify(dynamicChannelLoader, times(1)).validateTrigger(MODULE_NAME, triggerInformation.getSubject());
assertEquals(1, errors.size());
assertEquals("task.validation.error.triggerNotExist", errors.iterator().next().getMessage());
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TriggerEventServiceImplTest method shouldValidateStaticTrigger.
@Test
public void shouldValidateStaticTrigger() throws Exception {
TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 1992);
when(triggerEventsDataService.countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject())).thenReturn((long) 1);
Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
verify(triggerEventsDataService, times(1)).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
verify(dynamicChannelLoader, never()).channelExists(anyString());
verify(dynamicChannelLoader, never()).getTrigger(any(TaskTriggerInformation.class));
assertEquals(0, errors.size());
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TriggerEventServiceImplTest method shouldReturnChannelNotFoundErrorIfChannelDoesNotExist.
@Test
public void shouldReturnChannelNotFoundErrorIfChannelDoesNotExist() throws Exception {
TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 0);
when(dynamicChannelLoader.channelExists(MODULE_NAME)).thenReturn(false);
Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
verify(triggerEventsDataService, never()).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getTriggerListenerSubject());
verify(dynamicChannelLoader, times(1)).channelExists(MODULE_NAME);
verify(dynamicChannelLoader, never()).validateTrigger(MODULE_NAME, triggerInformation.getTriggerListenerSubject());
assertEquals(1, errors.size());
assertEquals("task.validation.error.triggerChannelNotRegistered", errors.iterator().next().getMessage());
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TaskServiceImpl method checkChannelAvailableInTask.
private void checkChannelAvailableInTask(Task task) {
if (null != task) {
List<String> symbolic = WebBundleUtil.getSymbolicNames(bundleContext);
TaskTriggerInformation trigger = task.getTrigger();
List<TaskActionInformation> actions = task.getActions();
task.setHasRegisteredChannel(null != trigger && symbolic.contains(trigger.getModuleName()));
if (CollectionUtils.isNotEmpty(actions)) {
for (TaskActionInformation action : actions) {
if (!symbolic.contains(action.getModuleName())) {
task.setHasRegisteredChannel(false);
}
}
}
}
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TaskControllerTest method shouldSaveTask.
@Test
public void shouldSaveTask() {
String subject = "trigger1";
TaskActionInformation action = new TaskActionInformation("send", "action1", "action", "0.15", "send", new HashMap<String, String>());
TaskTriggerInformation trigger = new TaskTriggerInformation("trigger", "trigger1", "trigger", "0.16", subject, subject);
Task expected = new Task("name", trigger, asList(action));
when(eventListenerRegistryService.getListeners(subject)).thenReturn(new HashSet<EventListener>());
controller.save(expected);
verify(taskWebService).save(expected);
}
Aggregations