use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testUserTaskFailure.
@SuppressWarnings("unchecked")
@Test
public void testUserTaskFailure() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ksession1.startProcess("UserTaskWithRollback");
TaskService taskService = runtime1.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
try {
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {
@Override
public void afterTaskStartedEvent(TaskEvent event) {
throw new TaskExecutionException("On purpose");
}
});
taskService.start(taskId, "john");
fail("Start task should fail due to broken script");
} catch (Throwable e) {
// expected
}
manager.disposeRuntimeEngine(runtime1);
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(1, errors.size());
assertExecutionError(errors.get(0), "Task", "UserTaskWithRollback", "Hello");
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithContentAndVarListener.
protected void testCompleteWithContentAndVarListener(TaskLifeCycleEventListener listener) {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
str += "name = 'This is my task name' })";
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(listener);
Map<String, Object> params = new HashMap<String, Object>();
params.put("input", "simple input");
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, params);
long taskId = task.getId();
// start task
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// complete task with output
params = new HashMap<String, Object>();
params.put("content", "content");
taskService.complete(taskId, "Darth Vader", params);
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithMergeOfResults.
@Test
public void testCompleteWithMergeOfResults() {
final Map<String, Object> outputsAfterCompletion = new HashMap<String, Object>();
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator') ],}),";
str += "name = 'This is my task name' })";
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {
@Override
public void afterTaskCompletedEvent(TaskEvent event) {
Map<String, Object> outs = event.getTask().getTaskData().getTaskOutputVariables();
if (outs != null) {
outputsAfterCompletion.putAll(outs);
}
}
});
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
task1 = taskService.getTaskById(taskId);
Map<String, Object> outputs = getTaskOutput(task1);
assertEquals(0, outputs.size());
taskService.complete(taskId, "Darth Vader", null);
task1 = taskService.getTaskById(taskId);
assertEquals(Status.Completed, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
outputs = getTaskOutput(task1);
assertEquals(0, outputs.size());
// now let's check what was actually given to listeners
assertEquals(0, outputsAfterCompletion.size());
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithMergeOfResultsNoDataBeforeCompletion.
@Test
public void testCompleteWithMergeOfResultsNoDataBeforeCompletion() {
final Map<String, Object> outputsAfterCompletion = new HashMap<String, Object>();
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator') ],}),";
str += "name = 'This is my task name' })";
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {
@Override
public void afterTaskCompletedEvent(TaskEvent event) {
outputsAfterCompletion.putAll(event.getTask().getTaskData().getTaskOutputVariables());
}
});
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
task1 = taskService.getTaskById(taskId);
Map<String, Object> outputs = getTaskOutput(task1);
assertEquals(0, outputs.size());
Map<String, Object> params = new HashMap<String, Object>();
params.put("response", "let's do it");
params.put("feedback", "ok");
taskService.complete(taskId, "Darth Vader", params);
task1 = taskService.getTaskById(taskId);
assertEquals(Status.Completed, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
outputs = getTaskOutput(task1);
assertEquals(2, outputs.size());
assertEquals("let's do it", outputs.get("response"));
assertEquals("ok", outputs.get("feedback"));
// now let's check what was actually given to listeners
assertEquals(2, outputsAfterCompletion.size());
assertEquals("let's do it", outputsAfterCompletion.get("response"));
assertEquals("ok", outputsAfterCompletion.get("feedback"));
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class AdminAPIsWithListenerTest method automaticCleanUpTest.
@SuppressWarnings("unchecked")
@Test
public void automaticCleanUpTest() throws Exception {
createRuntimeManager("org/jbpm/test/functional/task/patient-appointment.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
ksession.addEventListener(new TaskCleanUpProcessEventListener(taskService));
// let check how many listeners we have
assertEquals(2, ((EventService<TaskLifeCycleEventListener>) taskService).getTaskEventListeners().size());
assertEquals(2, ((EventService<TaskLifeCycleEventListener>) taskService).getTaskEventListeners().size());
logger.info("### Starting process ###");
Map<String, Object> parameters = new HashMap<String, Object>();
ProcessInstance process = ksession.startProcess("org.jbpm.PatientAppointment", parameters);
// The process is in the first Human Task waiting for its completion
assertEquals(ProcessInstance.STATE_ACTIVE, process.getState());
// gets frontDesk's tasks
List<TaskSummary> frontDeskTasks = taskService.getTasksAssignedAsPotentialOwner("frontDesk", "en-UK");
assertEquals(1, frontDeskTasks.size());
// doctor doesn't have any task
List<TaskSummary> doctorTasks = taskService.getTasksAssignedAsPotentialOwner("doctor", "en-UK");
Assert.assertTrue(doctorTasks.isEmpty());
// manager doesn't have any task
List<TaskSummary> managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
Assert.assertTrue(managerTasks.isEmpty());
taskService.start(frontDeskTasks.get(0).getId(), "frontDesk");
taskService.complete(frontDeskTasks.get(0).getId(), "frontDesk", null);
// Now doctor has 1 task
doctorTasks = taskService.getTasksAssignedAsPotentialOwner("doctor", "en-UK");
assertEquals(1, doctorTasks.size());
// No tasks for manager yet
managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
Assert.assertTrue(managerTasks.isEmpty());
taskService.start(doctorTasks.get(0).getId(), "doctor");
taskService.complete(doctorTasks.get(0).getId(), "doctor", null);
// tasks for manager
managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
assertEquals(1, managerTasks.size());
taskService.start(managerTasks.get(0).getId(), "manager");
taskService.complete(managerTasks.get(0).getId(), "manager", null);
// since persisted process instance is completed it should be null
process = ksession.getProcessInstance(process.getId());
Assert.assertNull(process);
final EntityManager em = emfTasks.createEntityManager();
assertEquals(0, em.createQuery("select t from TaskImpl t").getResultList().size());
assertEquals(0, em.createQuery("select i from I18NTextImpl i").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_BAs").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_ExclOwners").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_PotOwners").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Recipients").getResultList().size());
assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Stakeholders").getResultList().size());
assertEquals(0, em.createQuery("select c from ContentImpl c").getResultList().size());
em.close();
}
Aggregations