Search in sources :

Example 11 with ActionEventBuilder

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

the class TaskServiceImplTest method shouldImportTask.

@Test
public void shouldImportTask() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    action.getValues().put("phone", "{{ad.providerName.Test#1.id}}");
    List<String> filtersManipulations = new ArrayList<>();
    Task given = new TaskBuilder().withName("test").withTrigger(trigger).addAction(action).addDataSource(new DataSource("providerName", 1234L, 1L, "Test", "id", asList(new Lookup("id", "trigger.value")), true)).addFilterSet(new FilterSet(asList(new Filter("displayName", "ad.providerName.Test#1.id", UNICODE, true, OperatorType.EXIST.getValue(), "", filtersManipulations)))).isEnabled(true).build();
    TaskDataProvider provider = new TaskDataProvider();
    provider.setName("providerName");
    provider.setId(56789L);
    provider.setObjects(asList(new TaskDataProviderObject("display", "Test", asList(new LookupFieldsParameter("id", asList("id"))), asList(new FieldParameter("display", "id", UNICODE)))));
    Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null);
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE").setDescription("").setActionParameters(null).build();
    actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Phone").setKey("phone").build(), true);
    Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(actionEvent));
    when(providerService.getProviders()).thenReturn(asList(provider));
    when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
    when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel);
    when(triggerEventService.triggerExists(given.getTrigger())).thenReturn(true);
    when(providerService.getProvider("providerName")).thenReturn(provider);
    String json = mapper.writeValueAsString(given);
    taskService.importTask(json);
    action.getValues().put("phone", "{{ad.providerName.Test#1.id}}");
    Task expected = new TaskBuilder().withName("test").withTrigger(trigger).addAction(action).addDataSource(new DataSource("providerName", 56789L, 1L, "Test", "id", asList(new Lookup("id", "trigger.value")), true)).addFilterSet(new FilterSet(asList(new Filter("displayName", "ad.providerName.Test#1.id", UNICODE, true, OperatorType.EXIST.getValue(), "", filtersManipulations)))).isEnabled(true).build();
    Task actual = verifyCreateAndCaptureTask();
    assertEquals(expected, actual);
    verify(taskMigrationManager).migrateTask(actual);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) 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) ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) Filter(org.motechproject.tasks.domain.mds.task.Filter) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) FieldParameter(org.motechproject.tasks.domain.mds.task.FieldParameter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 12 with ActionEventBuilder

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

the class TaskServiceImplTest method shouldFindActionForGivenInformation.

@Test
public void shouldFindActionForGivenInformation() throws ActionNotFoundException {
    ActionEvent expected = new ActionEventBuilder().build();
    expected.setSubject(action.getSubject());
    expected.setDisplayName("receive");
    Channel c = new Channel();
    c.setActionTaskEvents(asList(expected));
    when(channelService.getChannel("test-action")).thenReturn(c);
    TaskEvent actual = taskService.getActionEventFor(action);
    assertEquals(expected, actual);
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskEvent(org.motechproject.tasks.domain.mds.channel.TaskEvent) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test)

Example 13 with ActionEventBuilder

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

the class TaskAnnotationBeanPostProcessor method addActionTaskEvent.

private void addActionTaskEvent(Channel channel, String serviceInterface, Method method, TaskAction taskAction) {
    ActionEvent action = getAction(channel, serviceInterface, method, taskAction.displayName());
    boolean foundAction = action != null;
    if (!foundAction) {
        action = new ActionEventBuilder().build();
    }
    action.setDisplayName(taskAction.displayName());
    action.setServiceInterface(serviceInterface);
    action.setServiceMethod(method.getName());
    action.setActionParameters(getActionParams(method));
    action.setPostActionParameters(getPostActionParams(method));
    if (!foundAction) {
        channel.addActionTaskEvent(action);
        LOGGER.debug("Action task event: {} added to channel: {}", action.getName(), channel.getDisplayName());
    }
    channelService.addOrUpdate(channel);
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)

Example 14 with ActionEventBuilder

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

the class TaskActionExecutorTest method shouldThrowExceptionIfBundleContextIsNotAvailable.

@Test(expected = TaskHandlerException.class)
public void shouldThrowExceptionIfBundleContextIsNotAvailable() throws TaskHandlerException, ActionNotFoundException {
    TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").setActionParameters(new TreeSet<>()).build();
    actionEvent.setActionParameters(new TreeSet<>());
    when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
    Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
    taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 15 with ActionEventBuilder

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

the class TaskActionExecutorTest method shouldThrowExceptionIfActionHasNeitherEventNorService.

@Test(expected = TaskHandlerException.class)
public void shouldThrowExceptionIfActionHasNeitherEventNorService() throws TaskHandlerException, ActionNotFoundException {
    TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").setActionParameters(new TreeSet<>()).build();
    actionEvent.setActionParameters(new TreeSet<>());
    when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
    Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
    taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskContext(org.motechproject.tasks.service.util.TaskContext) HashMap(java.util.HashMap) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) TreeSet(java.util.TreeSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Aggregations

ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)26 Test (org.junit.Test)23 Task (org.motechproject.tasks.domain.mds.task.Task)19 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)18 Channel (org.motechproject.tasks.domain.mds.channel.Channel)14 HashMap (java.util.HashMap)12 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)12 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)12 TreeSet (java.util.TreeSet)11 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)10 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)9 ArrayList (java.util.ArrayList)8 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)8 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)8 ObjectTest (org.motechproject.tasks.domain.ObjectTest)7 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)7 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)7 TaskContext (org.motechproject.tasks.service.util.TaskContext)7 TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)6 MotechEvent (org.motechproject.event.MotechEvent)5