Search in sources :

Example 6 with TaskDataProvider

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());
    }
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) Type(java.lang.reflect.Type) ValidationException(org.motechproject.tasks.exception.ValidationException) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with TaskDataProvider

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());
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with TaskDataProvider

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);
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) Type(java.lang.reflect.Type) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) ArrayList(java.util.ArrayList) FieldParameter(org.motechproject.tasks.domain.mds.task.FieldParameter) Test(org.junit.Test)

Example 9 with TaskDataProvider

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));
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) Test(org.junit.Test)

Example 10 with TaskDataProvider

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);
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) Type(java.lang.reflect.Type) Test(org.junit.Test)

Aggregations

TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)28 Test (org.junit.Test)20 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)14 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)9 ArrayList (java.util.ArrayList)8 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)8 Task (org.motechproject.tasks.domain.mds.task.Task)8 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)7 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)7 Type (java.lang.reflect.Type)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 Channel (org.motechproject.tasks.domain.mds.channel.Channel)6 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)6 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)6 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)6 FieldParameter (org.motechproject.tasks.domain.mds.task.FieldParameter)5 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)5 LinkedHashMap (java.util.LinkedHashMap)3 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)3