Search in sources :

Example 11 with TaskDataProvider

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

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

Example 13 with TaskDataProvider

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

the class TaskServiceImplTest method shouldNotSaveTaskIfNotMatchExtraValidationConditions.

@Test(expected = ValidationException.class)
public void shouldNotSaveTaskIfNotMatchExtraValidationConditions() {
    Map<String, String> map = new HashMap<>();
    map.put("phone", "12345");
    TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true));
    action.setValues(map);
    Task task = new Task("name", trigger, asList(action), config, true, false);
    Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SENDING", "", 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);
    Set<TaskError> errors = new HashSet<>();
    errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName()));
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
    when(providerService.getProviderById(1234L)).thenReturn(provider);
    when(triggerEventService.validateTrigger(trigger)).thenReturn(errors);
    taskService.save(task);
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with TaskDataProvider

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

the class TaskServiceImplTest method shouldImportTask.

@Test
public void shouldImportTask() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    action.getValues().put("phone", "{{ad.providerName.Test#1.id}}");
    List<String> filtersManipulations = new ArrayList<>();
    Task given = new TaskBuilder().withName("test").withTrigger(trigger).addAction(action).addDataSource(new DataSource("providerName", 1234L, 1L, "Test", "id", asList(new Lookup("id", "trigger.value")), true)).addFilterSet(new FilterSet(asList(new Filter("displayName", "ad.providerName.Test#1.id", UNICODE, true, OperatorType.EXIST.getValue(), "", filtersManipulations)))).isEnabled(true).build();
    TaskDataProvider provider = new TaskDataProvider();
    provider.setName("providerName");
    provider.setId(56789L);
    provider.setObjects(asList(new TaskDataProviderObject("display", "Test", asList(new LookupFieldsParameter("id", asList("id"))), asList(new FieldParameter("display", "id", UNICODE)))));
    Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null);
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE").setDescription("").setActionParameters(null).build();
    actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Phone").setKey("phone").build(), true);
    Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(actionEvent));
    when(providerService.getProviders()).thenReturn(asList(provider));
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
    when(triggerEventService.triggerExists(given.getTrigger())).thenReturn(true);
    when(providerService.getProvider("providerName")).thenReturn(provider);
    String json = mapper.writeValueAsString(given);
    taskService.importTask(json);
    action.getValues().put("phone", "{{ad.providerName.Test#1.id}}");
    Task expected = new TaskBuilder().withName("test").withTrigger(trigger).addAction(action).addDataSource(new DataSource("providerName", 56789L, 1L, "Test", "id", asList(new Lookup("id", "trigger.value")), true)).addFilterSet(new FilterSet(asList(new Filter("displayName", "ad.providerName.Test#1.id", UNICODE, true, OperatorType.EXIST.getValue(), "", filtersManipulations)))).isEnabled(true).build();
    Task actual = verifyCreateAndCaptureTask();
    assertEquals(expected, actual);
    verify(taskMigrationManager).migrateTask(actual);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) Filter(org.motechproject.tasks.domain.mds.task.Filter) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) FieldParameter(org.motechproject.tasks.domain.mds.task.FieldParameter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 15 with TaskDataProvider

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

the class TaskDataProviderServiceImplTest method shouldUnregisterDataProvider.

@Test
public void shouldUnregisterDataProvider() {
    List<LookupFieldsParameter> lookupFields = asList(new LookupFieldsParameter("lookupField", asList("lookupField")));
    List<FieldParameter> fields = asList(new FieldParameter("displayName", "fieldKey"));
    List<TaskDataProviderObject> objects = new ArrayList<>();
    objects.add(new TaskDataProviderObject("displayName", "type", lookupFields, fields));
    TaskDataProvider provider = new TaskDataProvider(PROVIDER_NAME, objects);
    when(dataProviderDataService.findByName(PROVIDER_NAME)).thenReturn(provider);
    taskDataProviderService.unregister(PROVIDER_NAME);
    verify(dataProviderDataService).delete(provider);
}
Also used : TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) ArrayList(java.util.ArrayList) FieldParameter(org.motechproject.tasks.domain.mds.task.FieldParameter) 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