Search in sources :

Example 21 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImplTest method shouldNotUpdateTaskIfItDoesNotHaveAnyValidationErrors.

@Test
public void shouldNotUpdateTaskIfItDoesNotHaveAnyValidationErrors() {
    Map<String, String> map = new HashMap<>();
    map.put("phone", "12345");
    action.setValues(map);
    Task task = new Task("name", trigger, asList(action), new TaskConfig(), true, false);
    when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
    Channel channel = new Channel("test", "test-action", "0.14", "", null, asList(new ActionEventBuilder().setDisplayName(action.getDisplayName()).setSubject(action.getSubject()).setDescription("").setActionParameters(null).build()));
    when(channelService.getChannel(action.getModuleName())).thenReturn(channel);
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(channel);
    taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(action));
    verify(tasksDataService, never()).create(any(Task.class));
    verify(tasksDataService, never()).update(any(Task.class));
    verify(tasksDataService, never()).doInTransaction(any(TransactionCallback.class));
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) TransactionCallback(org.springframework.transaction.support.TransactionCallback) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) QueryExecution(org.motechproject.mds.query.QueryExecution) Test(org.junit.Test)

Example 22 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImplTest method shouldValidateTasksAfterChannelUpdateForInvalidTaskDataProviders.

@Test
public void shouldValidateTasksAfterChannelUpdateForInvalidTaskDataProviders() {
    TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true));
    Task task = new Task("name", trigger, asList(action), config, true, false);
    task.setId(12345l);
    List<LookupFieldsParameter> lookupFields = new ArrayList<>();
    lookupFields.add(new LookupFieldsParameter("property", asList("property")));
    TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", lookupFields, null)));
    provider.setId(1234L);
    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()));
    when(tasksDataService.findById(12345l)).thenReturn(task);
    when(tasksDataService.retrieveAll()).thenReturn(asList(task));
    when(providerService.getProvider(provider.getName())).thenReturn(provider);
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
    taskService.validateTasksAfterTaskDataProviderUpdate(getProviderUpdateEvent(provider.getName()));
    Task actualTask = verifyUpdateAndCaptureTask();
    assertFalse(actualTask.isEnabled());
    List<Object> errors = new ArrayList<>(actualTask.getValidationErrors());
    assertEquals(1, errors.size());
    assertThat(errors, hasItem(hasProperty("message", equalTo("task.validation.error.providerObjectLookupNotExist"))));
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) 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) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) Test(org.junit.Test)

Example 23 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImplTest method shouldValidateTasksAfterChannelUpdateForValidTriggers.

@Test
public void shouldValidateTasksAfterChannelUpdateForValidTriggers() {
    Task task = new Task("name", trigger, asList(action), new TaskConfig(), true, false);
    Set<TaskError> existingErrors = new HashSet<>();
    existingErrors.add(new TaskError("task.validation.error.triggerNotExist"));
    task.addValidationErrors(existingErrors);
    when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
    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("schedule").setSubject("SCHEDULE").setDescription("").setActionParameters(null).build()));
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
    when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
    taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
    Task actualTask = verifyCreateAndCaptureTask();
    assertTrue(actualTask.isEnabled());
    assertTrue(actualTask.getValidationErrors().isEmpty());
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) Task(org.motechproject.tasks.domain.mds.task.Task) 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) QueryExecution(org.motechproject.mds.query.QueryExecution) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImplTest method shouldThrowActionNotFoundException.

@Test(expected = ActionNotFoundException.class)
public void shouldThrowActionNotFoundException() throws ActionNotFoundException {
    List<ActionEvent> actionEvents = new ArrayList<>();
    actionEvents.add(new ActionEventBuilder().build());
    Channel c = new Channel();
    c.setActionTaskEvents(actionEvents);
    when(channelService.getChannel("test-action")).thenReturn(c);
    taskService.getActionEventFor(action);
}
Also used : 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) Test(org.junit.Test)

Example 25 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImplTest method shouldValidateTasksAfterChannelUpdateForInvalidActions.

@Test
public void shouldValidateTasksAfterChannelUpdateForInvalidActions() {
    Task task = new Task("name", trigger, new ArrayList<>(asList(action)), new TaskConfig(), true, false);
    task.setId(124l);
    when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
    when(tasksDataService.findById(124l)).thenReturn(task);
    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("schedule").setSubject("SCHEDULE").setDescription("").setActionParameters(null).build()));
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
    taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(action));
    Task actualTask = verifyUpdateAndCaptureTask();
    assertFalse(actualTask.isEnabled());
    List<Object> errors = new ArrayList<>(actualTask.getValidationErrors());
    assertEquals(1, errors.size());
    assertThat(errors, hasItem(hasProperty("message", equalTo("task.validation.error.actionNotExist"))));
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) Task(org.motechproject.tasks.domain.mds.task.Task) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) QueryExecution(org.motechproject.mds.query.QueryExecution) Test(org.junit.Test)

Aggregations

Channel (org.motechproject.tasks.domain.mds.channel.Channel)35 Test (org.junit.Test)25 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)14 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)13 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)13 Task (org.motechproject.tasks.domain.mds.task.Task)12 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)9 ArrayList (java.util.ArrayList)8 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)8 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)8 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)8 HashSet (java.util.HashSet)6 QueryExecution (org.motechproject.mds.query.QueryExecution)6 TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)6 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)5 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 TaskChannel (org.motechproject.tasks.annotations.TaskChannel)4