use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.
the class TaskServiceImplTest method shouldFindActionForGivenInformation.
@Test
public void shouldFindActionForGivenInformation() throws ActionNotFoundException {
ActionEvent expected = new ActionEventBuilder().build();
expected.setSubject(action.getSubject());
expected.setDisplayName("receive");
Channel c = new Channel();
c.setActionTaskEvents(asList(expected));
when(channelService.getChannel("test-action")).thenReturn(c);
TaskEvent actual = taskService.getActionEventFor(action);
assertEquals(expected, actual);
}
use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.
the class TaskServiceImplTest method shouldThrowActionNotFoundExceptionWhenChannelContainsEmptyActionList.
@Test(expected = ActionNotFoundException.class)
public void shouldThrowActionNotFoundExceptionWhenChannelContainsEmptyActionList() throws ActionNotFoundException {
Channel c = new Channel();
c.setActionTaskEvents(new ArrayList<ActionEvent>());
when(channelService.getChannel("test-action")).thenReturn(c);
taskService.getActionEventFor(action);
}
use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.
the class TaskAnnotationBeanPostProcessor method postProcessAfterInitialization.
@Override
public Object postProcessAfterInitialization(final Object bean, final String beanName) {
if (bean == null) {
return null;
}
final Class<?> targetClass = getTargetClass(bean);
final TaskChannel taskChannel = targetClass.getAnnotation(TaskChannel.class);
if (taskChannel != null) {
LOGGER.debug("The @TaskChannel annotation was found in {}", targetClass.getName());
doWithMethods(targetClass, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) throws IllegalAccessException {
Method targetMethod = findMethod(targetClass, method.getName(), method.getParameterTypes());
if (targetMethod != null) {
TaskAction taskAction = targetMethod.getAnnotation(TaskAction.class);
if (taskAction != null) {
LOGGER.debug("The @TaskAction annotation was found in method: {}", targetMethod.getName());
String serviceInterface = getServiceInterface(targetClass);
Channel channel = getChannel(taskChannel);
addActionTaskEvent(channel, serviceInterface, targetMethod, taskAction);
}
}
}
});
}
return bean;
}
use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.
the class TaskAnnotationBeanPostProcessor method getChannel.
private Channel getChannel(TaskChannel taskChannel) {
String displayName = taskChannel.channelName();
String moduleName = taskChannel.moduleName();
String moduleVersion = taskChannel.moduleVersion();
Channel channel = channelService.getChannel(moduleName);
if (channel == null) {
LOGGER.debug("Creating new channel: {} for module: {}", displayName, moduleName);
channel = new Channel(displayName, moduleName, moduleVersion);
} else {
LOGGER.debug("Channel: {} for module: {} was retrieved", displayName, moduleName);
}
return channel;
}
use of org.motechproject.tasks.domain.mds.channel.Channel 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());
}
Aggregations