use of org.motechproject.tasks.domain.mds.channel.TriggerEvent in project motech by motech.
the class DynamicChannelLoaderImplTest method testGetTrigger.
@Test
public void testGetTrigger() throws Exception {
TaskTriggerInformation info = prepareTaskTriggerInformation();
TriggerEvent triggerEvent = prepareTriggerEvent();
when(provider.getTrigger(eq(info))).thenReturn(triggerEvent);
TriggerEvent fetched = channelLoader.getTrigger(info);
assertEquals(triggerEvent, fetched);
verify(provider).getTrigger(eq(info));
}
use of org.motechproject.tasks.domain.mds.channel.TriggerEvent in project motech by motech.
the class TaskServiceImplTest method shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors.
@Test
public void shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors() {
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);
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
Task actualTask = verifyCreateAndCaptureTask();
assertFalse(actualTask.hasValidationErrors());
}
use of org.motechproject.tasks.domain.mds.channel.TriggerEvent 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.channel.TriggerEvent in project motech by motech.
the class TaskServiceImplTest method shouldSaveTaskWithEmptyActionInputFields.
@Test
public void shouldSaveTaskWithEmptyActionInputFields() {
Task task = new Task("name", trigger, asList(action), null, false, false);
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()));
TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", asList(new LookupFieldsParameter("id", asList("id"))), null)));
provider.setId(1234L);
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
when(providerService.getProviderById(1234L)).thenReturn(provider);
taskService.save(task);
verify(triggerHandler).registerHandlerFor(task.getTrigger().getEffectiveListenerSubject());
// When task has not set number of retries, it should not register handler for retries
verifyNoMoreInteractions(triggerHandler);
verifyCreateAndCaptureTask();
}
use of org.motechproject.tasks.domain.mds.channel.TriggerEvent 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);
}
Aggregations