Search in sources :

Example 1 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testSignalEvent.

@Test(timeout = 10000)
public void testSignalEvent() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("Event Process").version("1").packageName("org.jbpm").variable("eventData", new org.jbpm.process.core.datatype.impl.type.StringDataType()).startNode(1).name("Start").done().eventNode(2).name("Event1").eventType("testEvent").variableName("eventData").done().actionNode(3).name("simpleActionNode").action("java", "System.out.println(\"test event action\");").done().endNode(4).name("End").done().connection(1, 2).connection(2, 3).connection(3, 4);
    RuleFlowProcess process = factory.validate().getProcess();
    assertNotNull(process);
    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");
    assertNotNull(pi);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi.getState());
    pi.signalEvent("testEvent", null);
    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 2 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testBoundaryTimerTimeCycle.

@Test(timeout = 10000)
public void testBoundaryTimerTimeCycle() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent", 1);
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done().endNode(3).name("End1").terminate(false).done().boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeCycle("1s###5s").cancelActivity(false).done().endNode(5).name("End2").terminate(false).done().connection(1, 2).connection(2, 3).connection(4, 5);
    RuleFlowProcess process = factory.validate().getProcess();
    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);
    TestWorkItemHandler testHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
    ksession.addEventListener(countDownListener);
    ProcessInstance pi = ksession.startProcess("org.jbpm.process");
    assertProcessInstanceActive(pi);
    // wait for boundary timer firing
    countDownListener.waitTillCompleted();
    assertNodeTriggered(pi.getId(), "End2");
    // still active because CancelActivity = false
    assertProcessInstanceActive(pi);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceCompleted(pi);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) 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 3 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testProcessFactory.

@Test
public void testProcessFactory() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().actionNode(2).name("Action").action("java", "System.out.println(\"Action\");").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
    RuleFlowProcess process = factory.validate().getProcess();
    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);
    ksession.startProcess("org.jbpm.process");
    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) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Example 4 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testBoundaryTimerTimeDuration.

@Test(timeout = 10000)
public void testBoundaryTimerTimeDuration() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent", 1);
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.name("My process").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done().endNode(3).name("End1").terminate(false).done().boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeDuration("1s").cancelActivity(false).done().endNode(5).name("End2").terminate(false).done().connection(1, 2).connection(2, 3).connection(4, 5);
    RuleFlowProcess process = factory.validate().getProcess();
    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);
    TestWorkItemHandler testHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
    ksession.addEventListener(countDownListener);
    ProcessInstance pi = ksession.startProcess("org.jbpm.process");
    assertProcessInstanceActive(pi);
    // wait for boundary timer firing
    countDownListener.waitTillCompleted();
    assertNodeTriggered(pi.getId(), "End2");
    // still active because CancelActivity = false
    assertProcessInstanceActive(pi);
    ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
    assertProcessInstanceCompleted(pi);
    ksession.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) 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 5 with RuleFlowProcessFactory

use of org.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.

the class ProcessFactoryTest method testAdHocSimple.

@Test(timeout = 10000)
public void testAdHocSimple() throws Exception {
    RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
    factory.dynamic(true).name("Event Process").version("1").packageName("org.jbpm");
    RuleFlowProcess process = factory.validate().getProcess();
    assertNotNull(process);
    assertTrue(process.isDynamic());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) RuleFlowProcessFactory(org.jbpm.ruleflow.core.RuleFlowProcessFactory) Test(org.junit.Test)

Aggregations

RuleFlowProcessFactory (org.jbpm.ruleflow.core.RuleFlowProcessFactory)9 Test (org.junit.Test)9 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)8 KieBase (org.kie.api.KieBase)7 Resource (org.kie.api.io.Resource)7 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)7 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)5 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)3 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)2 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)1 RegistryContext (org.drools.core.command.impl.RegistryContext)1 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 HumanTaskNode (org.jbpm.workflow.core.node.HumanTaskNode)1 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)1 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)1 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)1 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)1 ProcessStartedEvent (org.kie.api.event.process.ProcessStartedEvent)1 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)1