use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class EndEventTest method testOnEntryExitNamespacedScript.
@Test
public void testOnEntryExitNamespacedScript() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-OnEntryExitNamespacedScriptProcess.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("MyTask", new SystemOutWorkItemHandler());
List<String> myList = new ArrayList<String>();
ksession.setGlobal("list", myList);
ProcessInstance processInstance = ksession.startProcess("OnEntryExitScriptProcess");
assertProcessInstanceCompleted(processInstance);
assertEquals(4, myList.size());
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class IntermediateEventTest method testSignalBoundaryEventNoInteruptOnMultiInstanceSubprocess.
@Test
public void testSignalBoundaryEventNoInteruptOnMultiInstanceSubprocess() throws Exception {
KieBase kbase = createKnowledgeBase("subprocess/BPMN2-MultiInstanceSubprocessWithBoundarySignalNoInterupting.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler handler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
List<String> approvers = new ArrayList<String>();
approvers.add("john");
approvers.add("john");
params.put("approvers", approvers);
ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params);
assertProcessInstanceActive(processInstance);
List<WorkItem> workItems = handler.getWorkItems();
assertThat(workItems).isNotNull();
assertThat(workItems.size()).isEqualTo(2);
ksession.signalEvent("Outside", null, processInstance.getId());
assertProcessInstanceActive(processInstance.getId(), ksession);
for (WorkItem wi : workItems) {
ksession.getWorkItemManager().completeWorkItem(wi.getId(), null);
}
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class IntermediateEventTest method testIntermediateCatchEventTimerCycleWithErrorWithPersistence.
@Test(timeout = 10000)
@RequirePersistence
public void testIntermediateCatchEventTimerCycleWithErrorWithPersistence() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 2);
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventTimerCycleWithError.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.addEventListener(countDownListener);
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertProcessInstanceActive(processInstance);
final long piId = processInstance.getId();
ksession.execute(new ExecutableCommand<Void>() {
public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(piId);
processInstance.setVariable("x", 0);
return null;
}
});
// now wait for 1 second for timer to trigger
countDownListener.waitTillCompleted();
assertProcessInstanceActive(processInstance);
Integer xValue = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.getProcessInstance(piId);
return (Integer) processInstance.getVariable("x");
}
});
assertThat(xValue).isEqualTo(2);
ksession.abortProcessInstance(processInstance.getId());
assertProcessInstanceFinished(processInstance, ksession);
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class ActivityTest method testUserTaskWithDataStoreScenario.
@Test
public void testUserTaskWithDataStoreScenario() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithDataStore.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.startProcess("UserProcess");
// we can't test further as user tasks are asynchronous.
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class DynamicProcessTest method testDynamicProcess.
@Test
public void testDynamicProcess() throws Exception {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory.name("HelloWorldProcess").version("1.0").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task1").actorId("krisv").taskName("MyTask").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
final RuleFlowProcess process = factory.validate().getProcess();
Resource resource = ResourceFactory.newByteArrayResource(XmlRuleFlowProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
resource.setSourcePath("/tmp/dynamicProcess.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(resource);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
ksession.addEventListener(new ProcessEventListener() {
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void beforeProcessStarted(ProcessStartedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
logger.info("{}", arg0);
}
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void afterProcessStarted(ProcessStartedEvent arg0) {
}
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
}
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
}
});
final ProcessInstanceImpl processInstance = (ProcessInstanceImpl) ksession.startProcess("org.jbpm.HelloWorld");
HumanTaskNode node = new HumanTaskNode();
node.setName("Task2");
node.setId(4);
insertNodeInBetween(process, 2, 3, node);
((CommandBasedStatefulKnowledgeSession) ksession).getRunner().execute(new ExecutableCommand<Void>() {
public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
return null;
}
});
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
Aggregations