use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskServiceImplTest method shouldNotSaveTaskIfNotMatchExtraValidationConditions.
@Test(expected = ValidationException.class)
public void shouldNotSaveTaskIfNotMatchExtraValidationConditions() {
Map<String, String> map = new HashMap<>();
map.put("phone", "12345");
TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true));
action.setValues(map);
Task task = new Task("name", trigger, asList(action), config, true, false);
Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SENDING", "", asList(new EventParameter("test", "value")), "")), null);
Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE").setDescription("").setActionParameters(null).build()));
TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", asList(new LookupFieldsParameter("id", asList("id"))), null)));
provider.setId(1234L);
Set<TaskError> errors = new HashSet<>();
errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName()));
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
when(providerService.getProviderById(1234L)).thenReturn(provider);
when(triggerEventService.validateTrigger(trigger)).thenReturn(errors);
taskService.save(task);
}
use of org.motechproject.tasks.domain.mds.task.TaskError 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.TaskError 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.TaskError in project motech by motech.
the class TaskServiceImplTest method shouldValidateTasksAfterChannelUpdateForValidTaskDataProviders.
@Test
public void shouldValidateTasksAfterChannelUpdateForValidTaskDataProviders() {
TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true));
Task task = new Task("name", trigger, asList(action), config, true, false);
Set<TaskError> existingErrors = new HashSet<>();
existingErrors.add(new TaskError("task.validation.error.providerObjectLookupNotExist"));
task.addValidationErrors(existingErrors);
TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", null, null)));
provider.setId(1234L);
LinkedHashMap<String, Object> hashMap = new LinkedHashMap<>();
hashMap.put("displayName", "id");
ArrayList<String> list = new ArrayList<>();
list.add("id");
hashMap.put("fields", list);
provider.getObjects().get(0).setLookupFields(asList((Object) hashMap));
Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null);
Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE").setDescription("").setActionParameters(null).build()));
when(tasksDataService.retrieveAll()).thenReturn(asList(task));
when(providerService.getProvider(provider.getName())).thenReturn(provider);
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
taskService.validateTasksAfterTaskDataProviderUpdate(getProviderUpdateEvent(provider.getName()));
Task actualTask = verifyCreateAndCaptureTask();
assertTrue(task.isEnabled());
assertTrue(actualTask.getValidationErrors().isEmpty());
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskServiceImplTest method shouldValidateTasksAfterChannelUpdateForValidTriggers.
@Test
public void shouldValidateTasksAfterChannelUpdateForValidTriggers() {
Task task = new Task("name", trigger, asList(action), new TaskConfig(), true, false);
Set<TaskError> existingErrors = new HashSet<>();
existingErrors.add(new TaskError("task.validation.error.triggerNotExist"));
task.addValidationErrors(existingErrors);
when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null);
Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(new ActionEventBuilder().setDisplayName("schedule").setSubject("SCHEDULE").setDescription("").setActionParameters(null).build()));
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
Task actualTask = verifyCreateAndCaptureTask();
assertTrue(actualTask.isEnabled());
assertTrue(actualTask.getValidationErrors().isEmpty());
}
Aggregations