Search in sources :

Example 6 with EventParameter

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

the class TasksTestBase method setTriggerEvent.

protected void setTriggerEvent() {
    List<EventParameter> triggerEventParameters = new ArrayList<>();
    triggerEventParameters.add(new EventParameter("ExternalID", "externalId"));
    triggerEventParameters.add(new EventParameter("StartDate", "startDate", DATE));
    triggerEventParameters.add(new EventParameter("EndDate", "endDate", DATE));
    triggerEventParameters.add(new EventParameter("FacilityId", "facilityId"));
    triggerEventParameters.add(new EventParameter("EventName", "eventName"));
    triggerEventParameters.add(new EventParameter("List", "list", LIST));
    triggerEventParameters.add(new EventParameter("Map", "map", MAP));
    triggerEvent = new TriggerEvent();
    triggerEvent.setSubject(TRIGGER_SUBJECT);
    triggerEvent.setEventParameters(triggerEventParameters);
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ArrayList(java.util.ArrayList)

Example 7 with EventParameter

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

the class SchedulerChannelProviderBundleIT method getExpectedTrigger.

private TriggerEvent getExpectedTrigger() {
    List<EventParameter> parameters = new ArrayList<>();
    parameters.add(new EventParameter("scheduler.jobId", "JobID"));
    return new TriggerEvent("Job: test-event-job_id", "test-event-job_id", null, parameters, TEST_EVENT);
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ArrayList(java.util.ArrayList)

Example 8 with EventParameter

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

the class TaskServiceImplTest method shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors.

@Test
public void shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors() {
    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);
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
    taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
    Task actualTask = verifyCreateAndCaptureTask();
    assertFalse(actualTask.hasValidationErrors());
}
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) QueryExecution(org.motechproject.mds.query.QueryExecution) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with EventParameter

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

the class TaskServiceImplTest method shouldValidateTasksOfDependentModulesAfterChannelUpdateForInvalidTriggers.

@Test
public void shouldValidateTasksOfDependentModulesAfterChannelUpdateForInvalidTriggers() {
    Task task = new Task("name", trigger, new ArrayList<>(asList(action)), new TaskConfig(), true, false);
    task.setId(6l);
    when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
    when(tasksDataService.findById(6l)).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);
    Set<TaskError> triggerValidationErrors = new HashSet<>();
    triggerValidationErrors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName()));
    when(triggerEventService.validateTrigger(eq(trigger))).thenReturn(triggerValidationErrors);
    taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
    Task actualTask = verifyUpdateAndCaptureTask(times(2));
    assertFalse(actualTask.isEnabled());
    List<Object> errors = new ArrayList<Object>(actualTask.getValidationErrors());
    assertEquals(1, errors.size());
    assertThat(errors, hasItem(hasProperty("message", equalTo("task.validation.error.triggerNotExist"))));
}
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) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) QueryExecution(org.motechproject.mds.query.QueryExecution) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with EventParameter

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

Aggregations

EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)23 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)22 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)15 Task (org.motechproject.tasks.domain.mds.task.Task)14 Channel (org.motechproject.tasks.domain.mds.channel.Channel)13 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)12 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)12 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)9 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)9 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)8 HashMap (java.util.HashMap)6 TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)6 HashSet (java.util.HashSet)5 MotechEvent (org.motechproject.event.MotechEvent)5 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)5 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)5 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)5 Matchers.anyString (org.mockito.Matchers.anyString)4 DataProvider (org.motechproject.commons.api.DataProvider)4