use of org.jbpm.bpmn2.test.RequirePersistence in project jbpm by kiegroup.
the class IntermediateEventTest method testEventTypesLifeCycle.
@Test
@RequirePersistence
public void testEventTypesLifeCycle() throws Exception {
// JBPM-4246
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2");
EntityManagerFactory separateEmf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
Environment env = createEnvironment(separateEmf);
ksession = createKnowledgeSession(kbase, null, env);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.startProcess("BPMN2-IntermediateCatchSignalBetweenUserTasks");
int signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is not waiting for signal
assertThat(signalListSize).isEqualTo(0);
ksession.getWorkItemManager().completeWorkItem(1, null);
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is waiting for signal now
assertThat(signalListSize).isEqualTo(1);
ksession.signalEvent("MySignal", null);
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is not waiting for signal
assertThat(signalListSize).isEqualTo(0);
ksession.getWorkItemManager().completeWorkItem(2, null);
ksession.dispose();
ksession = null;
separateEmf.close();
}
use of org.jbpm.bpmn2.test.RequirePersistence in project jbpm by kiegroup.
the class IntermediateEventTest method testTimerBoundaryEventCycleISOWithPersistence.
@Test(timeout = 10000)
@RequirePersistence
public void testTimerBoundaryEventCycleISOWithPersistence() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("TimerEvent", 2);
// load up the knowledge base
KieBase kbase = createKnowledgeBase("BPMN2-TimerBoundaryEventCycleISO.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new DoNothingWorkItemHandler());
ProcessInstance processInstance = ksession.startProcess("TimerBoundaryEvent");
assertProcessInstanceActive(processInstance);
countDownListener.waitTillCompleted();
assertProcessInstanceActive(processInstance);
logger.info("dispose");
ksession.dispose();
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
ksession.addEventListener(countDownListener);
assertProcessInstanceActive(processInstance);
ksession.abortProcessInstance(processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.test.RequirePersistence in project jbpm by kiegroup.
the class IntermediateEventTest method testIntermediateCatchEventTimerDurationWithError.
@Test(timeout = 10000)
@RequirePersistence
public void testIntermediateCatchEventTimerDurationWithError() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 1);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerDurationWithError.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 0);
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
long waitTime = 2;
assertProcessInstanceActive(processInstance);
// now wait for 1 second for timer to trigger
countDownListener.waitTillCompleted(waitTime * 1000);
assertProcessInstanceActive(processInstance);
processInstance = ksession.getProcessInstance(processInstance.getId());
// reschedule it to allow to move on
ksession.setGlobal("TestOK", Boolean.TRUE);
ksession.execute(new UpdateTimerCommand(processInstance.getId(), "timer", waitTime + 1));
countDownListener.reset(1);
countDownListener.waitTillCompleted();
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.jbpm.bpmn2.test.RequirePersistence in project jbpm by kiegroup.
the class ActivityTest method testCallActivitySkipAbortParent.
@Test
@RequirePersistence
public void testCallActivitySkipAbortParent() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-CallActivitySkipAbortParent.bpmn2", "BPMN2-UserTask.bpmn2");
ksession = createKnowledgeSession(kbase);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "oldValue");
ProcessInstance processInstance = ksession.startProcess("ParentProcess", params);
assertProcessInstanceActive(processInstance);
ksession = restoreSession(ksession, true);
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
long childPI = workItem.getProcessInstanceId();
assertNotEquals("Child process instance must be different", processInstance.getId(), childPI);
ksession.abortProcessInstance(childPI);
assertProcessInstanceFinished(processInstance, ksession);
ProcessInstanceLog log = logService.findProcessInstance(childPI);
assertNotNull(log);
assertEquals(ProcessInstance.STATE_ABORTED, log.getStatus().intValue());
// parent process instance should not be aborted
log = logService.findProcessInstance(processInstance.getId());
assertNotNull(log);
assertEquals("Parent process should be completed and not aborted", ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
}
use of org.jbpm.bpmn2.test.RequirePersistence in project jbpm by kiegroup.
the class ActivityTest method testScriptTaskWithHistoryLog.
@Test
@RequirePersistence
public void testScriptTaskWithHistoryLog() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ScriptTask.bpmn2");
ksession = createKnowledgeSession(kbase);
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertProcessInstanceCompleted(processInstance);
AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment());
List<NodeInstanceLog> logs = logService.findNodeInstances(processInstance.getId());
assertNotNull(logs);
assertEquals(6, logs.size());
for (NodeInstanceLog log : logs) {
assertNotNull(log.getDate());
}
ProcessInstanceLog pilog = logService.findProcessInstance(processInstance.getId());
assertNotNull(pilog);
assertNotNull(pilog.getEnd());
List<ProcessInstanceLog> pilogs = logService.findActiveProcessInstances(processInstance.getProcessId());
assertNotNull(pilogs);
assertEquals(0, pilogs.size());
logService.dispose();
}
Aggregations