use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskDataProviderServiceImpl method registerProvider.
@Override
@Transactional
public void registerProvider(final InputStream stream) {
final Type type = new TypeToken<TaskDataProvider>() {
}.getType();
final TaskDataProvider provider = (TaskDataProvider) motechJsonReader.readFromStream(stream, type);
if (TaskDataProviderValidator.validateIsNotEmpty(provider)) {
LOGGER.info("Registering a task data provider with name: {}", provider.getName());
Set<TaskError> errors = TaskDataProviderValidator.validate(provider);
if (!isEmpty(errors)) {
throw new ValidationException(TaskDataProviderValidator.TASK_DATA_PROVIDER, TaskError.toDtos(errors));
}
addProvider(provider);
} else {
LOGGER.info("Registering an empty task data provider with name: {} is not possible", provider.getName());
}
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskDataProviderServiceImplTest method shouldGetAllProviders.
@Test
public void shouldGetAllProviders() {
List<TaskDataProvider> expected = new ArrayList<>();
expected.add(new TaskDataProvider());
expected.add(new TaskDataProvider());
when(dataProviderDataService.retrieveAll()).thenReturn(expected);
assertEquals(expected, taskDataProviderService.getProviders());
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskDataProviderServiceImplTest method shouldRegisterProviderFromInputStream.
@Test
public void shouldRegisterProviderFromInputStream() {
Type type = new TypeToken<TaskDataProvider>() {
}.getType();
List<TaskDataProviderObject> objects = new ArrayList<>();
List<LookupFieldsParameter> lookupFields = asList(new LookupFieldsParameter("lookupField", asList("lookupField")));
List<FieldParameter> fields = asList(new FieldParameter("displayName", "fieldKey"));
objects.add(new TaskDataProviderObject("displayName", "type", lookupFields, fields));
TaskDataProvider provider = new TaskDataProvider(PROVIDER_NAME, objects);
when(motechJsonReader.readFromStream(inputStream, type)).thenReturn(provider);
taskDataProviderService.registerProvider(inputStream);
verify(motechJsonReader).readFromStream(inputStream, type);
verify(dataProviderDataService).create(provider);
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskDataProviderServiceImplTest method shouldGetProviderByName.
@Test
public void shouldGetProviderByName() {
TaskDataProvider provider = new TaskDataProvider(PROVIDER_NAME, new ArrayList<TaskDataProviderObject>());
when(dataProviderDataService.findByName(PROVIDER_NAME)).thenReturn(provider);
assertEquals(provider, taskDataProviderService.getProvider(PROVIDER_NAME));
}
use of org.motechproject.tasks.domain.mds.task.TaskDataProvider in project motech by motech.
the class TaskDataProviderServiceImplTest method shouldNotSaveProviderWhenValidationExceptionIsAppeared.
@Test(expected = ValidationException.class)
public void shouldNotSaveProviderWhenValidationExceptionIsAppeared() {
Type type = new TypeToken<TaskDataProvider>() {
}.getType();
TaskDataProvider provider = new TaskDataProvider();
TaskDataProviderObject incorrectProviderObject = new TaskDataProviderObject();
incorrectProviderObject.setDisplayName("displayName");
provider.getObjects().add(0, incorrectProviderObject);
when(motechJsonReader.readFromStream(inputStream, type)).thenReturn(provider);
taskDataProviderService.registerProvider(inputStream);
verify(motechJsonReader).readFromStream(inputStream, type);
verify(dataProviderDataService).create(provider);
}
Aggregations