Search in sources :

Example 11 with RuleFlowProcessInstance

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;
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessImpl(org.jbpm.process.core.impl.ProcessImpl)

Example 12 with RuleFlowProcessInstance

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());
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) KieSession(org.kie.api.runtime.KieSession) Person(org.jbpm.integrationtests.test.Person) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 13 with RuleFlowProcessInstance

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));
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) ProcessInstanceResolverStrategy(org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 14 with RuleFlowProcessInstance

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));
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ReturnValueDescr(org.drools.compiler.compiler.ReturnValueDescr) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) ProcessDescr(org.drools.compiler.lang.descr.ProcessDescr) ReturnValueConstraintEvaluator(org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) JavaDialect(org.drools.compiler.rule.builder.dialect.java.JavaDialect) SplitInstance(org.jbpm.workflow.instance.node.SplitInstance) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) StringReader(java.io.StringReader) JavaReturnValueEvaluatorBuilder(org.jbpm.process.builder.dialect.java.JavaReturnValueEvaluatorBuilder) KieSession(org.kie.api.runtime.KieSession) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 15 with RuleFlowProcessInstance

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());
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) EndNode(org.jbpm.workflow.core.node.EndNode) KieBase(org.kie.api.KieBase) EndNode(org.jbpm.workflow.core.node.EndNode) Node(org.jbpm.workflow.core.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)23 KieSession (org.kie.api.runtime.KieSession)14 Test (org.junit.Test)12 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)11 RegistryContext (org.drools.core.command.impl.RegistryContext)6 KieBase (org.kie.api.KieBase)6 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)5 StringReader (java.io.StringReader)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 WorkflowProcessImpl (org.jbpm.workflow.core.impl.WorkflowProcessImpl)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)3 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)3 ReturnValueDescr (org.drools.compiler.compiler.ReturnValueDescr)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)3 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)3 ReturnValueConstraintEvaluator (org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator)3 TimerManager (org.jbpm.process.instance.timer.TimerManager)3 ArrayList (java.util.ArrayList)2 ProcessDescr (org.drools.compiler.lang.descr.ProcessDescr)2