logger.info("TEST:Unit {} has been deployed", unit);
Collection<ProcessDesc> processes = processService.getProcesses();
assertNotNull(processes);
assertEquals(2, processes.size());
RuntimeManager manager = processService.getRuntimeManager(unit.getIdentifier());
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
KieSession ksession = engine.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("org.jbpm.writedocument");
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
assertNotNull(engine);
ksession = engine.getKieSession();
assertNotNull(ksession);
// check the state of process instance
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
TaskService taskService = engine.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
taskService.start(taskId, "salaboy");
taskService.complete(taskId, "salaboy", null);
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
assertNotNull(engine);
ksession = engine.getKieSession();
assertNotNull(ksession);
taskService = engine.getTaskService();
// check the state of process instance
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
try {
processService.undeployUnit(unit);
fail("It's not possible to undeploy when there are active process instances");
} catch (Exception e) {
// do nothing it's expected
}
tasks = taskService.getTasksAssignedAsPotentialOwner("translator", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "translator");
taskService.complete(taskId, "translator", null);
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
assertNotNull(engine);
ksession = engine.getKieSession();
assertNotNull(ksession);