Search in sources :

Example 76 with StatefulKnowledgeSession

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;
}
Also used : WorkingMemoryInMemoryLogger(org.drools.core.audit.WorkingMemoryInMemoryLogger) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) JPAAuditLogService(org.jbpm.process.audit.JPAAuditLogService) DefaultProcessInstanceManagerFactory(org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory) Properties(java.util.Properties)

Example 77 with StatefulKnowledgeSession

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();
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Resource(org.kie.api.io.Resource) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Example 78 with StatefulKnowledgeSession

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();
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Resource(org.kie.api.io.Resource) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Example 79 with StatefulKnowledgeSession

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());
}
Also used : KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 80 with StatefulKnowledgeSession

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);
}
Also used : HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) SendTaskHandler(org.jbpm.bpmn2.handler.SendTaskHandler) Test(org.junit.Test)

Aggregations

StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)114 Test (org.junit.Test)79 KieBase (org.kie.api.KieBase)52 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)40 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)30 ArrayList (java.util.ArrayList)29 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)22 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)20 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)18 HashMap (java.util.HashMap)16 Environment (org.kie.api.runtime.Environment)12 KieSession (org.kie.api.runtime.KieSession)11 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)11 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)10 ClassPathResource (org.drools.core.io.impl.ClassPathResource)9 WorkItem (org.kie.api.runtime.process.WorkItem)9 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)8 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)8 Resource (org.kie.api.io.Resource)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7