Search in sources :

Example 11 with TaskTriggerInformation

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

the class TaskServiceImplTest method shouldFailValidationIfTriggerChannelIsNotRegistered.

@Test
public void shouldFailValidationIfTriggerChannelIsNotRegistered() {
    TaskTriggerInformation trigger = new TaskTriggerInformation("triggerDisplay", "triggerChannel", "triggerModule", "1.0", "subject", "triggerListenerSubject");
    TaskActionInformation action = new TaskActionInformation("actionDisplay", "actionChannel", "actionModule", "1.0", "subject");
    Task fooTask = new TaskBuilder().withName("foo").withTrigger(trigger).withTaskConfig(new TaskConfig()).addAction(action).build();
    fooTask.setEnabled(true);
    when(channelService.getChannel("foo-module")).thenReturn(null);
    when(channelService.getChannel("actionModule")).thenReturn(null);
    Set<TaskError> errors = new HashSet<>();
    errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered"));
    when(triggerEventService.validateTrigger(trigger)).thenReturn(errors);
    expectedException.expect(ValidationException.class);
    expectedException.expect(new TypeSafeMatcher<ValidationException>() {

        @Override
        public void describeTo(Description description) {
        }

        @Override
        public boolean matchesSafely(ValidationException actualException) {
            final TaskErrorDto triggerChannelError = new TaskErrorDto("task.validation.error.triggerChannelNotRegistered");
            final TaskErrorDto actionChannelError = new TaskErrorDto("task.validation.error.actionChannelNotRegistered");
            Set<TaskErrorDto> taskErrors = actualException.getTaskErrors();
            return taskErrors.contains(triggerChannelError) && taskErrors.contains(actionChannelError);
        }
    });
    taskService.save(fooTask);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) ValidationException(org.motechproject.tasks.exception.ValidationException) Description(org.hamcrest.Description) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) Set(java.util.Set) HashSet(java.util.HashSet) TaskErrorDto(org.motechproject.tasks.dto.TaskErrorDto) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with TaskTriggerInformation

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

the class TriggerEventServiceImplTest method shouldValidateDynamicTrigger.

@Test
public void shouldValidateDynamicTrigger() throws Exception {
    TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
    when(channelsDataService.countFindByModuleName(MODULE_NAME)).thenReturn((long) 1992);
    when(triggerEventsDataService.countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject())).thenReturn((long) 0);
    when(dynamicChannelLoader.channelExists(MODULE_NAME)).thenReturn(true);
    when(dynamicChannelLoader.validateTrigger(MODULE_NAME, triggerInformation.getSubject())).thenReturn(true);
    Set<TaskError> errors = triggerEventService.validateTrigger(triggerInformation);
    verify(channelsDataService, times(1)).countFindByModuleName(MODULE_NAME);
    verify(triggerEventsDataService, times(1)).countByChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
    verify(dynamicChannelLoader, times(1)).channelExists(MODULE_NAME);
    verify(dynamicChannelLoader, times(1)).validateTrigger(MODULE_NAME, triggerInformation.getSubject());
    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 13 with TaskTriggerInformation

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

the class TriggerEventServiceImplTest method shouldGetTrigger.

@Test
public void shouldGetTrigger() throws Exception {
    TriggerEvent expectedTrigger = prepareTrigger();
    TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(expectedTrigger);
    when(triggerEventsDataService.byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject())).thenReturn(null);
    when(dynamicChannelLoader.getTrigger(eq(triggerInformation))).thenReturn(expectedTrigger);
    TriggerEvent trigger = triggerEventService.getTrigger(triggerInformation);
    verify(triggerEventsDataService, times(1)).byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject());
    verify(dynamicChannelLoader, times(1)).getTrigger(triggerInformation);
    assertEquals(expectedTrigger, trigger);
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Test(org.junit.Test)

Example 14 with TaskTriggerInformation

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

the class TriggerEventServiceImplTest method shouldReturnTrueIfTriggerExists.

@Test
public void shouldReturnTrueIfTriggerExists() throws Exception {
    TriggerEvent expectedTrigger = prepareTrigger();
    TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(expectedTrigger);
    when(triggerEventsDataService.byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject())).thenReturn(null);
    when(dynamicChannelLoader.getTrigger(eq(triggerInformation))).thenReturn(expectedTrigger);
    boolean exists = triggerEventService.triggerExists(triggerInformation);
    verify(triggerEventsDataService, times(1)).byChannelModuleNameAndSubject(MODULE_NAME, expectedTrigger.getSubject());
    verify(dynamicChannelLoader, times(1)).getTrigger(triggerInformation);
    assertTrue(exists);
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Test(org.junit.Test)

Example 15 with TaskTriggerInformation

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

the class TriggerEventServiceImplTest method shouldReturnFalseIfTriggerDoesNotExist.

@Test
public void shouldReturnFalseIfTriggerDoesNotExist() throws Exception {
    TaskTriggerInformation triggerInformation = prepareTaskTriggerInformation(prepareTrigger());
    when(triggerEventsDataService.byChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject())).thenReturn(null);
    when(dynamicChannelLoader.getTrigger(eq(triggerInformation))).thenReturn(null);
    boolean exists = triggerEventService.triggerExists(triggerInformation);
    verify(triggerEventsDataService, times(1)).byChannelModuleNameAndSubject(MODULE_NAME, triggerInformation.getSubject());
    verify(dynamicChannelLoader, times(1)).getTrigger(triggerInformation);
    assertFalse(exists);
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) 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