Search in sources :

Example 21 with TriggerEvent

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

the class SchedulerChannelProviderBundleIT method getExpectedTriggers.

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

Example 22 with TriggerEvent

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

the class SchedulerChannelProviderBundleIT method shouldGetTrigger.

@Test
public void shouldGetTrigger() {
    TaskTriggerInformation information = new TaskTriggerInformation("Job: test-event-job_id", "Channel name", "Module name", "Module version", "test-event-job_id", TEST_EVENT);
    TriggerEvent trigger = channelProvider.getTrigger(information);
    assertEquals(getExpectedTrigger(), trigger);
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Test(org.junit.Test)

Example 23 with TriggerEvent

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

the class ChannelBuilder method fromChannelRequest.

/**
 * Creates a builder, which allows building Channels based on the given {@code channelRequest}.
 *
 * @param channelRequest  the channel request
 * @return the created builder
 */
public static ChannelBuilder fromChannelRequest(ChannelRequest channelRequest) {
    ChannelBuilder builder = new ChannelBuilder().setDisplayName(channelRequest.getDisplayName()).setModuleName(channelRequest.getModuleName()).setModuleVersion(channelRequest.getModuleVersion());
    List<TriggerEvent> triggerEvents = new ArrayList<>();
    for (TriggerEventRequest triggerEventRequest : channelRequest.getTriggerTaskEvents()) {
        triggerEvents.add(TriggerEventBuilder.fromTriggerEventRequest(triggerEventRequest).build());
    }
    builder.setTriggerTaskEvents(triggerEvents);
    List<ActionEvent> actionEvents = new ArrayList<>();
    for (ActionEventRequest actionEventRequest : channelRequest.getActionTaskEvents()) {
        actionEvents.add(ActionEventBuilder.fromActionEventRequest(actionEventRequest).build());
    }
    builder.setActionTaskEvents(actionEvents);
    return builder;
}
Also used : TriggerEventRequest(org.motechproject.tasks.contract.TriggerEventRequest) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) ArrayList(java.util.ArrayList) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest)

Example 24 with TriggerEvent

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

the class TaskServiceImplTest method shouldValidateTasksAfterChannelUpdateForValidTaskDataProviders.

@Test
public void shouldValidateTasksAfterChannelUpdateForValidTaskDataProviders() {
    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);
    Set<TaskError> existingErrors = new HashSet<>();
    existingErrors.add(new TaskError("task.validation.error.providerObjectLookupNotExist"));
    task.addValidationErrors(existingErrors);
    TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", null, null)));
    provider.setId(1234L);
    LinkedHashMap<String, Object> hashMap = new LinkedHashMap<>();
    hashMap.put("displayName", "id");
    ArrayList<String> list = new ArrayList<>();
    list.add("id");
    hashMap.put("fields", list);
    provider.getObjects().get(0).setLookupFields(asList((Object) hashMap));
    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.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 = verifyCreateAndCaptureTask();
    assertTrue(task.isEnabled());
    assertTrue(actualTask.getValidationErrors().isEmpty());
}
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) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) LinkedHashMap(java.util.LinkedHashMap) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with TriggerEvent

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

Aggregations

TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)34 Test (org.junit.Test)24 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)22 ArrayList (java.util.ArrayList)17 Task (org.motechproject.tasks.domain.mds.task.Task)16 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)9 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)8 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)7 TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)6 MotechEvent (org.motechproject.event.MotechEvent)5 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)5 Matchers.anyString (org.mockito.Matchers.anyString)4