use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanTaskTest method testInputTransformation.
@Test
@BZ("1081508")
public void testInputTransformation() {
KieSession ksession = createKSession(INPUT_TRANSFORMATION);
ProcessInstance pi = ksession.startProcess(INPUT_TRANSFORMATION_ID);
RuntimeEngine engine = getRuntimeEngine();
TaskService taskService = engine.getTaskService();
List<TaskSummary> taskList = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
Long taskId = taskList.get(0).getId();
taskService.start(taskId, "john");
Map<String, Object> taskById = taskService.getTaskContent(taskId);
Assertions.assertThat(taskById).containsEntry("Input", "Transformed String");
taskService.complete(taskId, "john", null);
assertProcessInstanceCompleted(pi.getId());
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanTaskTest method testAbortWorkItemTaskStatus.
@Test
@BZ("1145046")
public void testAbortWorkItemTaskStatus() {
for (int i = 0; i < 5; i++) {
createRuntimeManager(Strategy.PROCESS_INSTANCE, "abortWorkItemTaskStatus" + i, ABORT_WORKITEM_TASK_STATUS);
RuntimeEngine runtime = getRuntimeEngine();
KieSession ksession = runtime.getKieSession();
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance pi = ksession.startProcess(ABORT_WORKITEM_TASK_STATUS_ID, params);
TaskService taskService = runtime.getTaskService();
List<Long> list = taskService.getTasksByProcessInstanceId(pi.getId());
for (long taskId : list) {
Task task = taskService.getTaskById(taskId);
Assertions.assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Exited);
}
disposeRuntimeManager();
}
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class SingleRuntimeManagerTest method testProcessStartOnManager.
private void testProcessStartOnManager(RuntimeEngine runtime, RuntimeManager manager) {
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertNotNull(processInstance);
TaskService taskService = runtime.getTaskService();
String deploymentId = taskService.execute(new TaskCommand<String>() {
@Override
public String execute(Context context) {
return (String) context.get(EnvironmentName.DEPLOYMENT_ID);
}
});
assertNotNull(deploymentId);
assertEquals(manager.getIdentifier(), deploymentId);
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Reserved);
List<TaskSummary> tasks = taskService.getTasksOwnedByStatus("john", statuses, "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskService.start(tasks.get(0).getId(), "john");
taskService.complete(tasks.get(0).getId(), "john", null);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class SingleRuntimeManagerWithListenersTest method testProcessStartOnManager.
private void testProcessStartOnManager(RuntimeEngine runtime) {
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
Collection<ProcessEventListener> pListeners = ksession.getProcessEventListeners();
assertNotNull(pListeners);
// prepare listeners class names for assertion
List<String> listenerCLassNames = new ArrayList<String>();
for (Object o : pListeners) {
listenerCLassNames.add(o.getClass().getName());
}
// DebugProcessEventListener was added by custom producer
assertTrue(listenerCLassNames.contains(DebugProcessEventListener.class.getName()));
// JPAWorkingMemoryDbLogger one is always added to deal with user tasks
assertTrue(listenerCLassNames.contains(JPAWorkingMemoryDbLogger.class.getName()));
if (((RuntimeEngineImpl) runtime).getManager() instanceof PerProcessInstanceRuntimeManager) {
assertEquals(3, pListeners.size());
} else {
assertEquals(2, pListeners.size());
}
TaskService taskService = runtime.getTaskService();
assertNotNull(taskService);
List<?> listeners = ((EventService<?>) taskService).getTaskEventListeners();
assertNotNull(listeners);
assertEquals(3, listeners.size());
// prepare listeners class names for assertion
listenerCLassNames = new ArrayList<String>();
for (Object o : listeners) {
System.out.println("###### " + o.getClass().getName());
listenerCLassNames.add(o.getClass().getName());
}
assertEquals(3, listenerCLassNames.size());
// JPATaskLifeCycleEventListener was added by custom producer
assertTrue(listenerCLassNames.contains(JPATaskLifeCycleEventListener.class.getName()));
// external one is always added to deal with user tasks
assertTrue(listenerCLassNames.contains(ExternalTaskEventListener.class.getName()));
// BAMTaskEventListener was added by custom producer
assertTrue(listenerCLassNames.contains(BAMTaskEventListener.class.getName()));
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertNotNull(processInstance);
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Reserved);
List<TaskSummary> tasks = taskService.getTasksOwnedByStatus("john", statuses, "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskService.start(tasks.get(0).getId(), "john");
taskService.complete(tasks.get(0).getId(), "john", null);
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class SupportProcessBaseTest method testSupportProcess.
@Test
public void testSupportProcess() {
DeploymentUnit deploymentUnitSupport = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnitSupport);
units.add(deploymentUnitSupport);
Map<String, Object> params = new HashMap<String, Object>();
params.put("customer", "polymita");
RuntimeManager managerSupport = deploymentService.getRuntimeManager(deploymentUnitSupport.getIdentifier());
assertNotNull(managerSupport);
int currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(0, currentNumberOfEvents);
RuntimeEngine engine = managerSupport.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
ProcessInstance pI = engine.getKieSession().startProcess("support.process", params);
assertNotNull(pI);
TaskService taskService = engine.getTaskService();
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(2, currentNumberOfEvents);
// Configure Release
List<TaskSummary> tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, tasksAssignedToSalaboy.size());
assertEquals("Create Support", tasksAssignedToSalaboy.get(0).getName());
TaskSummary createSupportTask = tasksAssignedToSalaboy.get(0);
taskService.start(createSupportTask.getId(), "salaboy");
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(4, currentNumberOfEvents);
Map<String, Object> taskContent = ((InternalTaskService) taskService).getTaskContent(createSupportTask.getId());
assertEquals("polymita", taskContent.get("input_customer"));
Map<String, String> taskOutputMappings = bpmn2Service.getTaskOutputMappings(deploymentUnitSupport.getIdentifier(), "support.process", createSupportTask.getName());
assertEquals(1, taskOutputMappings.size());
assertEquals("output_customer", taskOutputMappings.keySet().iterator().next());
Map<String, Object> output = new HashMap<String, Object>();
output.put("output_customer", "polymita/redhat");
taskService.complete(createSupportTask.getId(), "salaboy", output);
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(8, currentNumberOfEvents);
tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, tasksAssignedToSalaboy.size());
assertEquals("Resolve Support", tasksAssignedToSalaboy.get(0).getName());
TaskSummary resolveSupportTask = tasksAssignedToSalaboy.get(0);
taskService.start(resolveSupportTask.getId(), "salaboy");
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(10, currentNumberOfEvents);
taskService.complete(resolveSupportTask.getId(), "salaboy", null);
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(14, currentNumberOfEvents);
tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertEquals(1, tasksAssignedToSalaboy.size());
assertEquals("Notify Customer", tasksAssignedToSalaboy.get(0).getName());
TaskSummary notifySupportTask = tasksAssignedToSalaboy.get(0);
taskService.start(notifySupportTask.getId(), "salaboy");
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(16, currentNumberOfEvents);
output = new HashMap<String, Object>();
output.put("output_solution", "solved today");
taskService.complete(notifySupportTask.getId(), "salaboy", output);
currentNumberOfEvents = DebugTaskLifeCycleEventListener.getEventCounter();
assertEquals(18, currentNumberOfEvents);
}
Aggregations