Search in sources :

Example 6 with TaskBuilder

use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.

the class TaskContextTest method testGetNullTriggerKey.

@Test
public void testGetNullTriggerKey() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    MotechEvent event = mock(MotechEvent.class);
    KeyInformation key = parse(String.format("%s.%s", TRIGGER_PREFIX, EVENT_KEY));
    Map<String, String> child = new HashMap<>();
    child.put("key", null);
    parameters.put("event", child);
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    assertEquals(null, new TaskContext(task, parameters, null, activityService).getTriggerValue(key.getKey()));
    // should not throw any exceptions
    assertNull(new TaskContext(task, parameters, null, activityService).getTriggerValue(key.getKey()));
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) MotechEvent(org.motechproject.event.MotechEvent) KeyInformation(org.motechproject.tasks.domain.KeyInformation) Test(org.junit.Test)

Example 7 with TaskBuilder

use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.

the class TaskContextTest method shouldNotThrowExceptionWhenDataSourceFieldValueEvaluationThrowsException_IfFailNotFoundIsFalse.

@Test
public void shouldNotThrowExceptionWhenDataSourceFieldValueEvaluationThrowsException_IfFailNotFoundIsFalse() throws Exception {
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    TaskContext taskContext = new TaskContext(task, null, null, activityService);
    taskContext.addDataSourceObject("1", new TestDataSourceObject(), false);
    KeyInformation key = parse("ad.1.Integer#1.providerId");
    assertNull(taskContext.getDataSourceObjectValue(key.getObjectId().toString(), key.getKey(), key.getObjectType()));
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) KeyInformation(org.motechproject.tasks.domain.KeyInformation) Test(org.junit.Test)

Example 8 with TaskBuilder

use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.

the class TaskBuilderTest method shouldReturnEmptyTaskObject.

@Test
public void shouldReturnEmptyTaskObject() throws Exception {
    TaskBuilder builder = new TaskBuilder();
    Task task = builder.withName(TASK_NAME).withDescription(TASK_DESCRIPTION).isEnabled(isEnabled).withTrigger(new TaskTriggerInformation()).addAction(new TaskActionInformation()).withTaskConfig(new TaskConfig()).addFilterSet(new FilterSet()).addDataSource(new DataSource()).clear().build();
    assertNotNull(task);
    assertTrue(task.getName().isEmpty());
    assertTrue(task.getDescription().isEmpty());
    assertEquals(false, task.isEnabled());
    assertNull(task.getTrigger());
    assertNotNull(task.getActions());
    assertTrue(task.getActions().isEmpty());
    assertNotNull(task.getTaskConfig());
    assertTrue(task.getTaskConfig().getSteps().isEmpty());
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) Test(org.junit.Test)

Example 9 with TaskBuilder

use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.

the class TaskActionExecutorTest method shouldRaiseEventWhenActionHasSubjectAndService_IfServiceIsNotAvailable.

@Test
public void shouldRaiseEventWhenActionHasSubjectAndService_IfServiceIsNotAvailable() throws TaskHandlerException, ActionNotFoundException {
    TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "serviceInterface", "serviceMethod");
    ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setSubject("actionSubject").setDescription("").setServiceInterface("serviceInterface").setServiceMethod("serviceMethod").setActionParameters(new TreeSet<ActionParameter>()).build();
    actionEvent.setActionParameters(new TreeSet<>());
    when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
    when(bundleContext.getServiceReference("serviceInterface")).thenReturn(null);
    Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
    taskActionExecutor.setBundleContext(bundleContext);
    taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
    verify(eventRelay).sendEventMessage(any(MotechEvent.class));
}
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) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Example 10 with TaskBuilder

use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.

the class TaskActionExecutorTest method shouldInvokeServiceIfActionHasService.

@Test
public void shouldInvokeServiceIfActionHasService() throws ActionNotFoundException, TaskHandlerException {
    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();
    when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
    ServiceReference serviceReference = mock(ServiceReference.class);
    when(bundleContext.getServiceReference("serviceInterface")).thenReturn(serviceReference);
    TestService testService = new TestService();
    when(bundleContext.getService(serviceReference)).thenReturn(testService);
    Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
    taskActionExecutor.setBundleContext(bundleContext);
    taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), new HashMap<>(), activityService), TASK_ACTIVITY_ID);
    assertTrue(testService.serviceMethodInvoked());
}
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) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) ObjectTest(org.motechproject.tasks.domain.ObjectTest)

Aggregations

Test (org.junit.Test)26 Task (org.motechproject.tasks.domain.mds.task.Task)26 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)26 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)24 HashMap (java.util.HashMap)11 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)8 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)8 TreeSet (java.util.TreeSet)7 TaskContext (org.motechproject.tasks.service.util.TaskContext)7 MotechEvent (org.motechproject.event.MotechEvent)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)4 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)4 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)4 ArrayList (java.util.ArrayList)3 Filter (org.motechproject.tasks.domain.mds.task.Filter)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 Matchers.anyString (org.mockito.Matchers.anyString)2