Search in sources :

Example 11 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess 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 12 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess 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 13 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess 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 14 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess 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 15 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess 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

RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)85 Test (org.junit.Test)47 ArrayList (java.util.ArrayList)38 StartNode (org.jbpm.workflow.core.node.StartNode)38 EndNode (org.jbpm.workflow.core.node.EndNode)37 ActionNode (org.jbpm.workflow.core.node.ActionNode)33 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)32 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)24 KieSession (org.kie.api.runtime.KieSession)20 DroolsAction (org.jbpm.workflow.core.DroolsAction)19 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)19 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)19 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)17 Variable (org.jbpm.process.core.context.variable.Variable)16 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)16 Action (org.jbpm.process.instance.impl.Action)16 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)16 ProcessContext (org.kie.api.runtime.process.ProcessContext)16 KieBase (org.kie.api.KieBase)15