Search in sources :

Example 21 with TaskTriggerInformation

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

the class TriggerEventServiceImplTest method shouldReturnChannelNotFoundErrorIfTriggerDoesNotExist.

@Test
public void shouldReturnChannelNotFoundErrorIfTriggerDoesNotExist() throws Exception {
    TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
    when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 0);
    when(dynamicChannelLoader.channelExists(MODULE_NAME)).thenReturn(true);
    when(dynamicChannelLoader.validateTrigger(MODULE_NAME, triggerInformation.getSubject())).thenReturn(false);
    Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
    verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
    verify(triggerEventsDataService, never()).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
    verify(dynamicChannelLoader, times(1)).channelExists(MODULE_NAME);
    verify(dynamicChannelLoader, times(1)).validateTrigger(MODULE_NAME, triggerInformation.getSubject());
    assertEquals(1, errors.size());
    assertEquals("task.validation.error.triggerNotExist", errors.iterator().next().getMessage());
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) Test(org.junit.Test)

Example 22 with TaskTriggerInformation

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

the class TriggerEventServiceImplTest method shouldValidateStaticTrigger.

@Test
public void shouldValidateStaticTrigger() throws Exception {
    TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
    when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 1992);
    when(triggerEventsDataService.countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject())).thenReturn((long) 1);
    Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
    verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
    verify(triggerEventsDataService, times(1)).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
    verify(dynamicChannelLoader, never()).channelExists(anyString());
    verify(dynamicChannelLoader, never()).getTrigger(any(TaskTriggerInformation.class));
    assertEquals(0, errors.size());
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) Test(org.junit.Test)

Example 23 with TaskTriggerInformation

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

the class TriggerEventServiceImplTest method shouldReturnChannelNotFoundErrorIfChannelDoesNotExist.

@Test
public void shouldReturnChannelNotFoundErrorIfChannelDoesNotExist() throws Exception {
    TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
    when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 0);
    when(dynamicChannelLoader.channelExists(MODULE_NAME)).thenReturn(false);
    Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
    verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
    verify(triggerEventsDataService, never()).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getTriggerListenerSubject());
    verify(dynamicChannelLoader, times(1)).channelExists(MODULE_NAME);
    verify(dynamicChannelLoader, never()).validateTrigger(MODULE_NAME, triggerInformation.getTriggerListenerSubject());
    assertEquals(1, errors.size());
    assertEquals("task.validation.error.triggerChannelNotRegistered", errors.iterator().next().getMessage());
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) Test(org.junit.Test)

Example 24 with TaskTriggerInformation

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

the class TaskServiceImpl method checkChannelAvailableInTask.

private void checkChannelAvailableInTask(Task task) {
    if (null != task) {
        List<String> symbolic = WebBundleUtil.getSymbolicNames(bundleContext);
        TaskTriggerInformation trigger = task.getTrigger();
        List<TaskActionInformation> actions = task.getActions();
        task.setHasRegisteredChannel(null != trigger && symbolic.contains(trigger.getModuleName()));
        if (CollectionUtils.isNotEmpty(actions)) {
            for (TaskActionInformation action : actions) {
                if (!symbolic.contains(action.getModuleName())) {
                    task.setHasRegisteredChannel(false);
                }
            }
        }
    }
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation)

Example 25 with TaskTriggerInformation

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

the class TaskControllerTest method shouldSaveTask.

@Test
public void shouldSaveTask() {
    String subject = "trigger1";
    TaskActionInformation action = new TaskActionInformation("send", "action1", "action", "0.15", "send", new HashMap<String, String>());
    TaskTriggerInformation trigger = new TaskTriggerInformation("trigger", "trigger1", "trigger", "0.16", subject, subject);
    Task expected = new Task("name", trigger, asList(action));
    when(eventListenerRegistryService.getListeners(subject)).thenReturn(new HashSet<EventListener>());
    controller.save(expected);
    verify(taskWebService).save(expected);
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) EventListener(org.motechproject.event.listener.EventListener) Test(org.junit.Test)

Aggregations

TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)28 Test (org.junit.Test)23 Task (org.motechproject.tasks.domain.mds.task.Task)16 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)14 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)8 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)7 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)7 HashMap (java.util.HashMap)6 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)6 ArrayList (java.util.ArrayList)5 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)5 Matchers.anyString (org.mockito.Matchers.anyString)4 DataProvider (org.motechproject.commons.api.DataProvider)4 MotechEvent (org.motechproject.event.MotechEvent)4 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)4 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)4 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)4 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)4 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)2