use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class JbpmBpmn2TestCase method createKnowledgeSession.
protected StatefulKnowledgeSession createKnowledgeSession(KieBase kbase, KieSessionConfiguration conf, Environment env) throws Exception {
StatefulKnowledgeSession result;
if (conf == null) {
conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
}
if (sessionPersistence) {
if (env == null) {
env = createEnvironment(emf);
}
if (pessimisticLocking) {
env.set(USE_PESSIMISTIC_LOCKING, true);
}
conf.setOption(ForceEagerActivationOption.YES);
result = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, conf, env);
AuditLoggerFactory.newInstance(Type.JPA, result, null);
logService = new JPAAuditLogService(env);
} else {
if (env == null) {
env = EnvironmentFactory.newEnvironment();
}
Properties defaultProps = new Properties();
defaultProps.setProperty("drools.processSignalManagerFactory", DefaultSignalManagerFactory.class.getName());
defaultProps.setProperty("drools.processInstanceManagerFactory", DefaultProcessInstanceManagerFactory.class.getName());
conf = SessionConfiguration.newInstance(defaultProps);
conf.setOption(ForceEagerActivationOption.YES);
result = (StatefulKnowledgeSession) kbase.newKieSession(conf, env);
logger = new WorkingMemoryInMemoryLogger(result);
}
return result;
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class ProcessFactoryTest method testCompositeNode.
@Test
public void testCompositeNode() throws Exception {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().compositeNode(2).name("SubProcess").startNode(1).name("SubProcess Start").done().actionNode(2).name("SubProcess Action").action("java", "System.out.println(\"SubProcess Action\");").done().endNode(3).name("SubProcess End").terminate(true).done().connection(1, 2).connection(2, 3).done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
RuleFlowProcess process = factory.validate().getProcess();
assertEquals("SubProcess", process.getNode(2).getName());
Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
res.setSourcePath("/tmp/processFactory.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(res);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ProcessInstance pi = ksession.startProcess("org.jbpm.process");
assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState());
ksession.dispose();
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class ProcessFactoryTest method testActionNodeIsDroolsAction.
@Test(timeout = 10000)
public void testActionNodeIsDroolsAction() throws Exception {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory.name("ActionNodeActionProcess").version("1").startNode(1).name("Start").done().endNode(3).name("End").done().actionNode(2).name("printTextActionNode").action("java", "System.out.println(\"test print\");", true).done().connection(1, 2).connection(2, 3);
RuleFlowProcess process = factory.validate().getProcess();
assertNotNull(process);
Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
res.setSourcePath("/tmp/processFactory.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(res);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ProcessInstance pi = ksession.startProcess("org.jbpm.process");
assertNotNull(pi);
assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState());
ksession.dispose();
}
use of org.kie.internal.runtime.StatefulKnowledgeSession in project jbpm by kiegroup.
the class EndEventTest method testOnEntryExitScriptDesigner.
@Test
public void testOnEntryExitScriptDesigner() throws Exception {
KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-OnEntryExitDesignerScriptProcess.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 EndEventTest method testMessageEnd.
@Test
public void testMessageEnd() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-MessageEndEvent.bpmn2");
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Send Task", new SendTaskHandler());
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "MyValue");
ProcessInstance processInstance = ksession.startProcess("MessageEndEvent", params);
assertProcessInstanceCompleted(processInstance);
}
Aggregations