use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class TestStatefulKnowledgeSession method getProcessInstance.
public ProcessInstance getProcessInstance(long arg0, boolean readOnly) {
RuleFlowProcessInstance pi = new RuleFlowProcessInstance();
pi.setId(arg0);
ProcessImpl processImpl = new ProcessImpl();
processImpl.setId("" + arg0);
pi.setProcess(processImpl);
return pi;
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class ProcessRuleFlowGroupTest method testRuleSetProcessContext.
@Test
public void testRuleSetProcessContext() throws Exception {
Reader source = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.ruleset\" package-name=\"org.jbpm\" version=\"1\" >\n" + "\n" + " <header>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <ruleSet id=\"2\" name=\"RuleSet\" ruleFlowGroup=\"MyGroup\" >\n" + " </ruleSet>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>");
Reader source2 = new StringReader("package org.jbpm;\n" + "\n" + "import org.jbpm.integrationtests.test.Person;\n" + "import org.kie.api.runtime.process.ProcessContext;\n" + "\n" + "rule MyRule ruleflow-group \"MyGroup\" dialect \"mvel\" \n" + " when\n" + " Person( age > 25 )\n" + " then\n" + " System.out.println(drools.getContext(ProcessContext).getProcessInstance().getProcessName());\n" + "end");
builder.addRuleFlow(source);
builder.addPackageFromDrl(source2);
KieSession workingMemory = createKieSession(builder.getPackages());
workingMemory.getEnvironment().set("org.jbpm.rule.task.waitstate", "true");
Person person = new Person();
person.setAge(30);
workingMemory.insert(person);
// start process
RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) workingMemory.startProcess("org.drools.ruleset");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
workingMemory.fireAllRules();
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class ProcessInstanceResolverStrategyTest method testAccept.
@Test
public void testAccept() {
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
WorkflowProcessImpl process = new WorkflowProcessImpl();
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setState(ProcessInstance.STATE_ACTIVE);
processInstance.setProcess(process);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
ProcessInstanceResolverStrategy strategy = new ProcessInstanceResolverStrategy();
assertTrue(strategy.accept(processInstance));
Object object = new Object();
assertTrue(!strategy.accept(object));
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class JavaReturnValueConstraintEvaluatorBuilderTest method testSimpleReturnValueConstraintEvaluator.
@Test
public void testSimpleReturnValueConstraintEvaluator() throws Exception {
final InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1");
ProcessDescr processDescr = new ProcessDescr();
processDescr.setClassName("Process1");
processDescr.setName("Process1");
WorkflowProcessImpl process = new WorkflowProcessImpl();
process.setName("Process1");
process.setPackageName("pkg1");
ReturnValueDescr descr = new ReturnValueDescr();
descr.setText("return value;");
KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg);
DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
JavaDialect javaDialect = (JavaDialect) dialectRegistry.getDialect("java");
ProcessBuildContext context = new ProcessBuildContext(pkgBuilder, pkg, process, processDescr, dialectRegistry, javaDialect);
pkgBuilder.addPackageFromDrl(new StringReader("package pkg1;\nglobal Boolean value;"));
ReturnValueConstraintEvaluator node = new ReturnValueConstraintEvaluator();
final JavaReturnValueEvaluatorBuilder builder = new JavaReturnValueEvaluatorBuilder();
builder.build(context, node, descr, null);
ProcessDialectRegistry.getDialect(JavaDialect.ID).addProcess(context);
javaDialect.compileAll();
assertEquals(0, javaDialect.getResults().size());
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Arrays.asList(pkgBuilder.getPackages()));
final KieSession ksession = kbase.newKieSession();
ksession.setGlobal("value", true);
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
SplitInstance splitInstance = new SplitInstance();
splitInstance.setProcessInstance(processInstance);
assertTrue(node.evaluate(splitInstance, null, null));
ksession.setGlobal("value", false);
assertFalse(node.evaluate(splitInstance, null, null));
}
use of org.jbpm.ruleflow.instance.RuleFlowProcessInstance in project jbpm by kiegroup.
the class EndNodeInstanceTest method testEndNode.
@Test
public void testEndNode() {
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
MockNode mockNode = new MockNode();
MockNodeInstanceFactory factory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), factory);
WorkflowProcessImpl process = new WorkflowProcessImpl();
Node endNode = new EndNode();
endNode.setId(1);
endNode.setName("end node");
mockNode.setId(2);
new ConnectionImpl(mockNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
process.addNode(mockNode);
process.addNode(endNode);
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setState(ProcessInstance.STATE_ACTIVE);
processInstance.setProcess(process);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
MockNodeInstance mockNodeInstance = (MockNodeInstance) processInstance.getNodeInstance(mockNode);
mockNodeInstance.triggerCompleted();
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Aggregations