use of org.motechproject.tasks.domain.mds.task.TaskConfig in project motech by motech.
the class TaskServiceImplTest method shouldValidateTasksOfDependentModulesAfterChannelUpdateForInvalidTriggers.
@Test
public void shouldValidateTasksOfDependentModulesAfterChannelUpdateForInvalidTriggers() {
Task task = new Task("name", trigger, new ArrayList<>(asList(action)), new TaskConfig(), true, false);
task.setId(6l);
when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
when(tasksDataService.findById(6l)).thenReturn(task);
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("schedule").setSubject("SCHEDULE").setDescription("").setActionParameters(null).build()));
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
Set<TaskError> triggerValidationErrors = new HashSet<>();
triggerValidationErrors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName()));
when(triggerEventService.validateTrigger(eq(trigger))).thenReturn(triggerValidationErrors);
taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
Task actualTask = verifyUpdateAndCaptureTask(times(2));
assertFalse(actualTask.isEnabled());
List<Object> errors = new ArrayList<Object>(actualTask.getValidationErrors());
assertEquals(1, errors.size());
assertThat(errors, hasItem(hasProperty("message", equalTo("task.validation.error.triggerNotExist"))));
}
use of org.motechproject.tasks.domain.mds.task.TaskConfig 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.TaskConfig 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.TaskConfig in project motech by motech.
the class TaskConfigTest method shouldRemoveAllSteps.
@Test
public void shouldRemoveAllSteps() throws Exception {
TaskConfig config = new TaskConfig().add(new FilterSet(), new FilterSet(), new FilterSet()).add(new DataSource(), new DataSource(), new DataSource());
assertNotNull(config.getSteps());
assertFalse(config.getSteps().isEmpty());
config.removeAll();
assertNotNull(config.getSteps());
assertTrue(config.getSteps().isEmpty());
}
use of org.motechproject.tasks.domain.mds.task.TaskConfig in project motech by motech.
the class TaskConfigTest method shouldAddAllStepsAndSetNewOrderNumber.
@Test
public void shouldAddAllStepsAndSetNewOrderNumber() throws Exception {
List<TaskConfigStep> steps = new ArrayList<>();
steps.add(new FilterSet());
steps.add(new DataSource());
steps.add(new DataSource());
steps.add(new FilterSet());
Random random = new Random();
for (TaskConfigStep step : steps) {
step.setOrder(random.nextInt());
}
TaskConfig config = new TaskConfig().addAll(null).addAll(new TreeSet<TaskConfigStep>()).addAll(new TreeSet<>(steps));
List<Integer> orders = new ArrayList<>(steps.size());
for (TaskConfigStep step : config.getSteps()) {
orders.add(step.getOrder());
}
assertThat(orders, hasItems(0, 1, 2, 3));
}
Aggregations