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);
}
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));
}
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);
}
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));
}
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();
}
Aggregations