use of org.motechproject.tasks.domain.mds.task.TaskError 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.TaskError 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.TaskError 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.TaskError in project motech by motech.
the class ChannelServiceImpl method addOrUpdate.
@Override
@Transactional
public synchronized void addOrUpdate(final Channel channel) {
Set<TaskError> errors = ChannelValidator.validate(channel);
if (!isEmpty(errors)) {
throw new ValidationException(ChannelValidator.CHANNEL, TaskError.toDtos(errors));
}
// MOTECH-3049 There is a bug in datanucleus and sometimes ActionParameter is not found in TaskBundleClassLoader,
// so we temporary change contextClassLoader to TaskBundleClassLoader while updating channel
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(channel.getClass().getClassLoader());
final Channel existingChannel = getChannel(channel.getModuleName());
if (existingChannel != null && !existingChannel.equals(channel)) {
LOGGER.debug("Updating channel {}", channel.getDisplayName());
existingChannel.setActionTaskEvents(channel.getActionTaskEvents());
existingChannel.setTriggerTaskEvents(channel.getTriggerTaskEvents());
existingChannel.setDescription(channel.getDescription());
existingChannel.setDisplayName(channel.getDisplayName());
existingChannel.setModuleName(channel.getModuleName());
existingChannel.setModuleVersion(channel.getModuleVersion());
channelsDataService.update(existingChannel);
sendChannelUpdatedEvent(channel);
} else if (existingChannel == null) {
LOGGER.debug("Creating channel {}", channel.getDisplayName());
channelsDataService.create(channel);
}
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
LOGGER.info(String.format("Saved channel: %s", channel.getDisplayName()));
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskServiceImpl method validateActions.
private Set<TaskError> validateActions(Task task) {
LOGGER.debug("Validating all actions in task: {} with ID: {}", task.getName(), task.getId());
Set<TaskError> errors = new HashSet<>();
for (TaskActionInformation action : task.getActions()) {
Channel channel = channelService.getChannel(action.getModuleName());
errors.addAll(validateAction(task, channel, action));
}
logResultOfValidation("actions", task.getName(), errors);
return errors;
}
Aggregations