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.drools.core.process");
factory.name("My process").packageName("org.drools").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);
factory.validate().getProcess();
}
use of org.jbpm.ruleflow.core.RuleFlowProcessFactory 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.jbpm.ruleflow.core.RuleFlowProcessFactory 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.jbpm.ruleflow.core.RuleFlowProcessFactory in project jbpm by kiegroup.
the class DynamicProcessTest method testDynamicProcess.
@Test
public void testDynamicProcess() throws Exception {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory.name("HelloWorldProcess").version("1.0").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task1").actorId("krisv").taskName("MyTask").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
final RuleFlowProcess process = factory.validate().getProcess();
Resource resource = ResourceFactory.newByteArrayResource(XmlRuleFlowProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
resource.setSourcePath("/tmp/dynamicProcess.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(resource);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
ksession.addEventListener(new ProcessEventListener() {
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void beforeProcessStarted(ProcessStartedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
logger.info("{}", arg0);
}
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void afterProcessStarted(ProcessStartedEvent arg0) {
}
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
}
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
}
});
final ProcessInstanceImpl processInstance = (ProcessInstanceImpl) ksession.startProcess("org.jbpm.HelloWorld");
HumanTaskNode node = new HumanTaskNode();
node.setName("Task2");
node.setId(4);
insertNodeInBetween(process, 2, 3, node);
((CommandBasedStatefulKnowledgeSession) ksession).getRunner().execute(new ExecutableCommand<Void>() {
public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
return null;
}
});
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
Aggregations