use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class ProcessPersistenceHumanTaskTest method testTransactions.
@Test
public void testTransactions() throws Exception {
createRuntimeManager("org/jbpm/test/functional/task/humantask.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
long processId;
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
try {
ut.begin();
ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
processId = processInstance.getId();
} finally {
ut.rollback();
}
assertNull(ksession.getProcessInstance(processId));
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, list.size());
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class SerializedTimerRollbackTest method testSerizliableTestsWithExternalRollback.
@Test
public void testSerizliableTestsWithExternalRollback() {
try {
createRuntimeManager("org/jbpm/test/functional/timer/HumanTaskWithBoundaryTimer.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
logger.debug("Created knowledge session");
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
List<Long> committedProcessInstanceIds = new ArrayList<Long>();
for (int i = 0; i < 10; i++) {
tm.begin();
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
logger.debug("Creating process instance: {}", i);
ProcessInstance pi = ksession.startProcess("PROCESS_1", params);
if (i % 2 == 0) {
committedProcessInstanceIds.add(pi.getId());
tm.commit();
} else {
tm.rollback();
}
}
Connection c = getDs().getConnection();
Statement st = c.createStatement();
ResultSet rs = st.executeQuery("select rulesbytearray from sessioninfo");
rs.next();
Blob b = rs.getBlob("rulesbytearray");
assertNotNull(b);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
ProtobufMarshaller marshaller = new ProtobufMarshaller(builder.newKieBase(), new MarshallingConfigurationImpl());
StatefulKnowledgeSession session = marshaller.unmarshall(b.getBinaryStream());
assertNotNull(session);
TimerManager timerManager = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) session).getProcessRuntime()).getTimerManager();
assertNotNull(timerManager);
Collection<TimerInstance> timers = timerManager.getTimers();
assertNotNull(timers);
assertEquals(5, timers.size());
for (TimerInstance timerInstance : timers) {
assertTrue(committedProcessInstanceIds.contains(timerInstance.getProcessInstanceId()));
ksession.abortProcessInstance(timerInstance.getProcessInstanceId());
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, tasks.size());
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown");
}
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class WorkitemAssignmentTest method testWorkitemAssignment.
@Test
public void testWorkitemAssignment() {
manager = createRuntimeManager("org/jbpm/test/functional/workitem/workitemAssignmentTest.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
KieSession kieSession = runtimeEngine.getKieSession();
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager();
workItemManager.registerWorkItemHandler("SampleUserWorkitem", new UserAssignmentWorkitemHandler());
Map<String, Object> initEmptyVars = new HashMap<String, Object>();
initEmptyVars.put("firstName", "initValue");
initEmptyVars.put("lastName", "initValue");
ProcessInstance pi = kieSession.startProcess("workitemassignmenttest", initEmptyVars);
// values should be from initial state when process instance started -- "initValue", "initValue"
String varFirstNameOrig = (String) ((WorkflowProcessInstance) pi).getVariable("firstName");
String varLasttNameOrig = (String) ((WorkflowProcessInstance) pi).getVariable("lastName");
assertEquals("initValue", varFirstNameOrig);
assertEquals("initValue", varLasttNameOrig);
// advance process execution past first user task
// it will then go through the custom workitem and
// get into the second user task
TaskService taskService = runtimeEngine.getTaskService();
assertProcessInstanceActive(pi.getId());
assertNodeTriggered(pi.getId(), "myFirstUserTask");
assertNodeActive(pi.getId(), kieSession, "myFirstUserTask");
List<TaskSummary> firstTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, firstTasks.size());
TaskSummary firstTaskSummary = firstTasks.get(0);
taskService.start(firstTaskSummary.getId(), "john");
taskService.complete(firstTaskSummary.getId(), "john", null);
// get process instance again to get updated process var values which were set
// by the assignments in custom workitem handler
ProcessInstance processInstance = kieSession.getProcessInstance(pi.getId());
String varFirstName = (String) ((WorkflowProcessInstance) processInstance).getVariable("firstName");
String varLasttName = (String) ((WorkflowProcessInstance) processInstance).getVariable("lastName");
assertNotNull(varFirstName);
assertNotNull(varLasttName);
assertEquals(UserAssignmentWorkitemHandler.fnameStr, varFirstName);
assertEquals(UserAssignmentWorkitemHandler.lnameStr, varLasttName);
// make sure we passed the custom workitem
assertNodeTriggered(pi.getId(), "SampleUserWorkitem");
assertNodeActive(pi.getId(), kieSession, "mySecondUserTask");
List<TaskSummary> secondTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, secondTasks.size());
// advance paste the second user task to complete the process instance
TaskSummary secondTaskSummary = secondTasks.get(0);
taskService.start(secondTaskSummary.getId(), "john");
taskService.complete(secondTaskSummary.getId(), "john", null);
assertProcessInstanceCompleted(processInstance.getId());
// now we can check audit service to see process vars
// and how they chaged throughout process execution
AuditService auditService = runtimeEngine.getAuditService();
List<? extends VariableInstanceLog> firstNameVars = auditService.findVariableInstances(processInstance.getId(), "firstName");
List<? extends VariableInstanceLog> lastNameVars = auditService.findVariableInstances(processInstance.getId(), "lastName");
assertNotNull(firstNameVars);
assertNotNull(lastNameVars);
assertEquals(2, firstNameVars.size());
assertEquals("initValue", firstNameVars.get(0).getValue());
assertEquals(UserAssignmentWorkitemHandler.fnameStr, firstNameVars.get(1).getValue());
assertEquals(2, lastNameVars.size());
assertEquals("initValue", lastNameVars.get(0).getValue());
assertEquals(UserAssignmentWorkitemHandler.lnameStr, lastNameVars.get(1).getValue());
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class TimerEventTest method testCancelledTimerNotScheduled.
@Test
@BZ("1148304")
public void testCancelledTimerNotScheduled() {
for (int i = 0; i < 5; i++) {
createRuntimeManager(Strategy.PROCESS_INSTANCE, (String) null, CANCELLED_TIMER);
KieSession ksession = getRuntimeEngine().getKieSession();
TaskService taskService = getRuntimeEngine().getTaskService();
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance pi = ksession.startProcess(CANCELLED_TIMER_ID, params);
System.out.println("A process instance started : pid = " + pi.getId());
List<Long> list = taskService.getTasksByProcessInstanceId(pi.getId());
for (long taskId : list) {
Task task = taskService.getTaskById(taskId);
System.out.println("taskId = " + task.getId() + ", status = " + task.getTaskData().getStatus());
}
Date before = new Date();
disposeRuntimeManager();
// Check if engine did not waited for timer
Date after = new Date();
long seconds = (after.getTime() - before.getTime()) / 1000;
Assertions.assertThat(seconds).as("Cancelled timer has been scheduled").isLessThan(5);
}
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanTaskTest method testOnExitScriptException.
@Test
@BZ("1120122")
public void testOnExitScriptException() {
createRuntimeManager(ON_EXIT_SCRIPT_EXCEPTION);
KieSession ksession = getRuntimeEngine().getKieSession();
TaskService taskService = getRuntimeEngine().getTaskService();
long pid = ksession.startProcess(ON_EXIT_SCRIPT_EXCEPTION_ID).getId();
List<Long> tasks = taskService.getTasksByProcessInstanceId(pid);
Assertions.assertThat(tasks).hasSize(1);
long taskId = tasks.get(0);
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
tasks = taskService.getTasksByProcessInstanceId(pid);
Assertions.assertThat(tasks).hasSize(2);
Task task1 = taskService.getTaskById(Math.min(tasks.get(0), tasks.get(1)));
Assertions.assertThat(task1.getNames().get(0).getText()).isEqualTo("Human task 1");
Assertions.assertThat(task1.getTaskData().getStatus()).isEqualTo(Status.Completed);
Task task2 = taskService.getTaskById(Math.max(tasks.get(0), tasks.get(1)));
Assertions.assertThat(task2.getNames().get(0).getText()).isEqualTo("Human task 2");
Assertions.assertThat(task2.getTaskData().getStatus()).isEqualTo(Status.Reserved);
}
Aggregations