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()));
}
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()));
}
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());
}
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));
}
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());
}
Aggregations