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();
}
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();
}
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();
}
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();
}
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());
}
Aggregations