use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.
the class TaskActionExecutorTest method shouldExecuteTaskIfActionMapParameterHasValueWithMixedTypes.
@Test
public void shouldExecuteTaskIfActionMapParameterHasValueWithMixedTypes() throws Exception {
TaskActionInformation actionInformation = prepareTaskActionInformationWithTrigger();
ActionEvent actionEvent = prepareActionEvent();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
taskActionExecutor.setBundleContext(bundleContext);
taskActionExecutor.execute(task, actionInformation, 0, prepareTaskContext(task), TASK_ACTIVITY_ID);
verify(eventRelay).sendEventMessage(eq(prepareMotechEvent()));
}
use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.
the class TaskActionExecutorTest method shouldAddActivityNotificationIfServiceIsNotAvailable.
@Test
public void shouldAddActivityNotificationIfServiceIsNotAvailable() 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<>()).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(activityService).addWarning(task, "task.warning.serviceUnavailable", "serviceInterface");
}
use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.
the class TaskActionExecutorTest method shouldRaiseEventIfActionHasSubject.
@Test
public void shouldRaiseEventIfActionHasSubject() throws ActionNotFoundException, TaskHandlerException {
TaskActionInformation actionInformation = new TaskActionInformation("action", "channel", "module", "0.1", "actionSubject");
ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("Action").setSubject("actionSubject").setDescription("").setActionParameters(new TreeSet<>()).build();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
Task task = new TaskBuilder().addAction(new TaskActionInformation("Action", "channel", "module", "0.1", "actionSubject")).build();
task.setId(11L);
Map<String, Object> metadata = new HashMap<>();
metadata.put(EventDataKeys.TASK_ID, 11L);
metadata.put(EventDataKeys.TASK_RETRY, null);
metadata.put(EventDataKeys.TASK_ACTIVITY_ID, TASK_ACTIVITY_ID);
taskActionExecutor.setBundleContext(bundleContext);
taskActionExecutor.execute(task, actionInformation, 0, new TaskContext(task, new HashMap<>(), metadata, activityService), TASK_ACTIVITY_ID);
MotechEvent raisedEvent = new MotechEvent("actionSubject", new HashMap<>(), TasksEventCallbackService.TASKS_EVENT_CALLBACK_NAME, metadata);
verify(eventRelay).sendEventMessage(raisedEvent);
}
use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder in project motech by motech.
the class TaskActionExecutorTest method shouldNotRaiseEventIfActionHasSubjectAndService_IfServiceIsAvailable.
@Test
public void shouldNotRaiseEventIfActionHasSubjectAndService_IfServiceIsAvailable() throws ActionNotFoundException, TaskHandlerException {
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<>()).build();
when(taskService.getActionEventFor(actionInformation)).thenReturn(actionEvent);
ServiceReference serviceReference = mock(ServiceReference.class);
when(bundleContext.getServiceReference("serviceInterface")).thenReturn(serviceReference);
when(bundleContext.getService(serviceReference)).thenReturn(new 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);
verify(eventRelay, never()).sendEventMessage(any(MotechEvent.class));
}
use of org.motechproject.tasks.domain.mds.task.builder.TaskBuilder 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);
}
Aggregations