Search in sources :

Example 21 with EventParameter

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

the class ChannelServiceImplTest method shouldRegisterChannelFromChannelRequest.

@Test
public void shouldRegisterChannelFromChannelRequest() {
    List<ActionEventRequest> actionEventRequests = asList(new TestActionEventRequestBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<ActionParameterRequest>()).setPostActionParameters(new TreeSet<ActionParameterRequest>()).createActionEventRequest());
    List<TriggerEventRequest> triggerEventsRequest = asList(new TriggerEventRequest("displayName", "subject.foo", "description", asList(new EventParameterRequest("displayName", "eventKey"))));
    ChannelRequest channelRequest = new ChannelRequest(BUNDLE_SYMBOLIC_NAME, BUNDLE_SYMBOLIC_NAME, VERSION, "", triggerEventsRequest, actionEventRequests);
    channelService.registerChannel(channelRequest);
    ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
    verify(channelsDataService).create(captor.capture());
    Channel channelToBeCreated = captor.getValue();
    assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getDisplayName());
    assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getModuleName());
    assertEquals(VERSION, channelToBeCreated.getModuleVersion());
    assertEquals(1, channelToBeCreated.getTriggerTaskEvents().size());
    TriggerEvent expectedTrigger = new TriggerEvent("displayName", "subject.foo", "description", asList(new EventParameter("displayName", "eventKey")), "");
    TriggerEvent actualTrigger = channelToBeCreated.getTriggerTaskEvents().get(0);
    assertEquals(expectedTrigger, actualTrigger);
    assertEquals(1, channelToBeCreated.getActionTaskEvents().size());
    ActionEvent expectedAction = new ActionEventBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<>()).setPostActionParameters(new TreeSet<>()).build();
    ActionEvent actualAction = channelToBeCreated.getActionTaskEvents().get(0);
    assertEquals(expectedAction, actualAction);
}
Also used : ChannelRequest(org.motechproject.tasks.contract.ChannelRequest) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) EventParameterRequest(org.motechproject.tasks.contract.EventParameterRequest) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) TestActionEventRequestBuilder(org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TriggerEventRequest(org.motechproject.tasks.contract.TriggerEventRequest) TreeSet(java.util.TreeSet) ActionParameterRequest(org.motechproject.tasks.contract.ActionParameterRequest) Test(org.junit.Test)

Example 22 with EventParameter

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

the class ChannelServiceImplTest method shouldRegisterChannel.

@Test
public void shouldRegisterChannel() {
    String triggerEvent = "{ displayName: 'displayName', subject: 'subject', eventParameters: [{ displayName: 'displayName', eventKey: 'eventKey' }] }";
    String channel = String.format("{displayName: %s, triggerTaskEvents: [%s]}", BUNDLE_SYMBOLIC_NAME, triggerEvent);
    InputStream stream = new ByteArrayInputStream(channel.getBytes(Charset.forName("UTF-8")));
    channelService.registerChannel(stream, BUNDLE_SYMBOLIC_NAME, VERSION);
    ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
    verify(channelsDataService).create(captor.capture());
    Channel c = captor.getValue();
    assertEquals(BUNDLE_SYMBOLIC_NAME, c.getDisplayName());
    assertEquals(BUNDLE_SYMBOLIC_NAME, c.getModuleName());
    assertEquals(VERSION, c.getModuleVersion());
    assertEquals(1, c.getTriggerTaskEvents().size());
    assertEquals(new TriggerEvent("displayName", "subject", null, asList(new EventParameter("displayName", "eventKey")), ""), c.getTriggerTaskEvents().get(0));
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) Test(org.junit.Test)

Example 23 with EventParameter

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

the class TaskTriggerHandlerTest method shouldNotTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundNotSelected.

@Test
public void shouldNotTriggerErrorWhenActionDoesNotFindDataSourceWithFailIfDataNotFoundNotSelected() throws Exception {
    Map<String, DataProvider> providers = new HashMap<>();
    DataProvider provider = mock(DataProvider.class);
    Map<String, String> lookup = new HashMap<>();
    lookup.put("patientId", "123");
    when(provider.lookup("Patient", null, lookup)).thenReturn(null);
    providers.put(TASK_DATA_PROVIDER_NAME, provider);
    handler.setDataProviders(providers);
    TriggerEvent trigger = new TriggerEvent();
    trigger.setSubject("trigger");
    List<EventParameter> triggerEventParameters = new ArrayList<>();
    triggerEventParameters.add(new EventParameter("patientId", "123"));
    trigger.setEventParameters(triggerEventParameters);
    ActionEvent action = new ActionEventBuilder().build();
    action.setSubject("action");
    SortedSet<ActionParameter> actionEventParameters = new TreeSet<>();
    actionEventParameters.add(new ActionParameterBuilder().setDisplayName("Patient ID").setKey("patientId").setType(UNICODE).setOrder(0).build());
    action.setActionParameters(actionEventParameters);
    Task task = new Task();
    task.setName("task");
    task.setTrigger(new TaskTriggerInformation("Trigger", "channel", "module", "0.1", "trigger", "listener"));
    Map<String, String> actionValues = new HashMap<>();
    actionValues.put("patientId", "{{ad.12345.Patient#1.patientId}}");
    task.addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "action", actionValues));
    task.setId(7l);
    task.setHasRegisteredChannel(true);
    TaskConfig taskConfig = new TaskConfig();
    task.setTaskConfig(taskConfig);
    taskConfig.add(new DataSource(TASK_DATA_PROVIDER_NAME, 3L, 1L, "Patient", "provider", "specifiedName", asList(new Lookup("patientId", "trigger.patientId")), false));
    List<Task> tasks = asList(task);
    when(taskService.findActiveTasksForTriggerSubject("trigger")).thenReturn(tasks);
    when(taskService.getActionEventFor(task.getActions().get(0))).thenReturn(action);
    setTaskActivities();
    task.setFailuresInRow(taskActivities.size());
    Map<String, Object> param = new HashMap<>(4);
    param.put("patientId", "123");
    handler.handle(new MotechEvent("trigger", param));
    verify(postExecutionHandler, never()).handleError(anyMap(), anyMap(), eq(task), any(TaskHandlerException.class), eq(TASK_ACTIVITY_ID));
    verify(taskActivityService).addWarning(eq(task), eq("task.warning.notFoundObjectForType"), eq("Patient"));
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) ArrayList(java.util.ArrayList) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) Matchers.anyString(org.mockito.Matchers.anyString) DataProvider(org.motechproject.commons.api.DataProvider) TaskHandlerException(org.motechproject.tasks.exception.TaskHandlerException) TreeSet(java.util.TreeSet) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) MotechEvent(org.motechproject.event.MotechEvent) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) ActionParameter(org.motechproject.tasks.domain.mds.channel.ActionParameter) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) 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