Search in sources :

Example 21 with ActionEvent

use of org.motechproject.tasks.domain.mds.channel.ActionEvent 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 22 with ActionEvent

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

Example 23 with ActionEvent

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

the class TaskServiceImplTest method shouldThrowActionNotFoundException.

@Test(expected = ActionNotFoundException.class)
public void shouldThrowActionNotFoundException() throws ActionNotFoundException {
    List<ActionEvent> actionEvents = new ArrayList<>();
    actionEvents.add(new ActionEventBuilder().build());
    Channel c = new Channel();
    c.setActionTaskEvents(actionEvents);
    when(channelService.getChannel("test-action")).thenReturn(c);
    taskService.getActionEventFor(action);
}
Also used : 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) Test(org.junit.Test)

Example 24 with ActionEvent

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

the class TaskServiceImplTest method shouldSaveTask.

@Test
public void shouldSaveTask() {
    Map<String, String> map = new HashMap<>();
    map.put("phone", "12345");
    TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true));
    action.setValues(map);
    Task task = new Task("name", trigger, asList(action), config, true, false);
    task.setNumberOfRetries(5);
    task.setRetryTaskOnFailure(true);
    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));
    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.getProvider("TestProvider")).thenReturn(provider);
    when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
    taskService.save(task);
    verify(triggerHandler).registerHandlerFor(task.getTrigger().getEffectiveListenerSubject());
    // Because task has set number of retries to 5, it should register retries handler for this task
    verify(triggerHandler).registerHandlerFor(task.getTrigger().getEffectiveListenerRetrySubject(), true);
    verifyCreateAndCaptureTask();
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) 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) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TaskDataProvider(org.motechproject.tasks.domain.mds.task.TaskDataProvider) TaskDataProviderObject(org.motechproject.tasks.domain.mds.task.TaskDataProviderObject) ActionParameterBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder) LookupFieldsParameter(org.motechproject.tasks.domain.mds.task.LookupFieldsParameter) Lookup(org.motechproject.tasks.domain.mds.task.Lookup) Test(org.junit.Test)

Example 25 with ActionEvent

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

the class TaskAnnotationBeanPostProcessorTest method shouldAddActionWithParams.

@Test
public void shouldAddActionWithParams() throws Exception {
    Channel channel = new Channel(CHANNEL_NAME, MODULE_NAME, MODULE_VERSION);
    channel.addActionTaskEvent(new ActionEventBuilder().setDisplayName(ACTION_DISPLAY_NAME).setSubject(ACTION_DISPLAY_NAME).setDescription("").setActionParameters(null).build());
    channel.addActionTaskEvent(new ActionEventBuilder().setDisplayName(ACTION_DISPLAY_NAME).setDescription("").setServiceInterface(TestAction.class.getName()).setServiceMethod("action").setActionParameters(null).build());
    when(channelService.getChannel(MODULE_NAME)).thenReturn(channel);
    ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
    processor.postProcessAfterInitialization(new TestActionWithParam(), null);
    verify(channelService).addOrUpdate(captor.capture());
    Channel actualChannel = captor.getValue();
    assertNotNull(actualChannel);
    assertEquals(CHANNEL_NAME, actualChannel.getDisplayName());
    assertEquals(MODULE_NAME, actualChannel.getModuleName());
    assertEquals(MODULE_VERSION, actualChannel.getModuleVersion());
    assertNotNull(actualChannel.getActionTaskEvents());
    assertEquals(channel.getActionTaskEvents().size(), actualChannel.getActionTaskEvents().size());
    ActionEvent actualActionEvent = (ActionEvent) find(actualChannel.getActionTaskEvents(), new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            return object instanceof ActionEvent && ((ActionEvent) object).hasService() && ((ActionEvent) object).getActionParameters().size() > 1 && ((ActionEvent) object).getPostActionParameters().size() > 0;
        }
    });
    assertNotNull(actualActionEvent);
    assertEquals(ACTION_DISPLAY_NAME, actualActionEvent.getDisplayName());
    assertEquals(TestAction.class.getName(), actualActionEvent.getServiceInterface());
    assertEquals(METHOD_NAME, actualActionEvent.getServiceMethod());
    assertEquals(getExpectedActionParameters(), actualActionEvent.getActionParameters());
    assertEquals(getExpectedPostActionParameters(), actualActionEvent.getPostActionParameters());
}
Also used : ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) TaskChannel(org.motechproject.tasks.annotations.TaskChannel) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) Predicate(org.apache.commons.collections.Predicate) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)32 Test (org.junit.Test)21 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)18 Task (org.motechproject.tasks.domain.mds.task.Task)13 TreeSet (java.util.TreeSet)12 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)12 HashMap (java.util.HashMap)10 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)9 Channel (org.motechproject.tasks.domain.mds.channel.Channel)8 TaskContext (org.motechproject.tasks.service.util.TaskContext)8 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)7 MotechEvent (org.motechproject.event.MotechEvent)6 ArrayList (java.util.ArrayList)5 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)5 ActionParameterBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionParameterBuilder)5 ActionParameter (org.motechproject.tasks.domain.mds.channel.ActionParameter)4 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)4 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)4 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)3