Search in sources :

Example 1 with TaskDataProviderObject

use of org.motechproject.tasks.domain.mds.task.TaskDataProviderObject 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 2 with TaskDataProviderObject

use of org.motechproject.tasks.domain.mds.task.TaskDataProviderObject 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 3 with TaskDataProviderObject

use of org.motechproject.tasks.domain.mds.task.TaskDataProviderObject 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)

Example 4 with TaskDataProviderObject

use of org.motechproject.tasks.domain.mds.task.TaskDataProviderObject in project motech by motech.

the class TaskDataProviderServiceImplTest method shouldGetProviderById.

@Test
public void shouldGetProviderById() {
    TaskDataProvider provider = new TaskDataProvider(PROVIDER_NAME, new ArrayList<TaskDataProviderObject>());
    when(dataProviderDataService.findById(PROVIDER_ID)).thenReturn(provider);
    assertEquals(provider, taskDataProviderService.getProviderById(PROVIDER_ID));
}
Also used : TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) Test(org.junit.Test)

Example 5 with TaskDataProviderObject

use of org.motechproject.tasks.domain.mds.task.TaskDataProviderObject 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();
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) Task(org.motechproject.tasks.domain.mds.task.Task) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test)

Aggregations

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