Search in sources :

Example 1 with MVELReturnValueEvaluatorBuilder

use of org.jbpm.process.builder.dialect.mvel.MVELReturnValueEvaluatorBuilder in project jbpm by kiegroup.

the class MVELReturnValueConstraintEvaluatorBuilderTest method testSimpleReturnValueConstraintEvaluator.

@Test
public void testSimpleReturnValueConstraintEvaluator() throws Exception {
    final InternalKnowledgePackage pkg = new KnowledgePackageImpl("pkg1");
    ReturnValueDescr descr = new ReturnValueDescr();
    descr.setText("return value");
    KnowledgeBuilderImpl pkgBuilder = new KnowledgeBuilderImpl(pkg);
    DialectCompiletimeRegistry dialectRegistry = pkgBuilder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
    MVELDialect mvelDialect = (MVELDialect) dialectRegistry.getDialect("mvel");
    PackageBuildContext context = new PackageBuildContext();
    context.init(pkgBuilder, pkg, null, dialectRegistry, mvelDialect, null);
    pkgBuilder.addPackageFromDrl(new StringReader("package pkg1;\nglobal Boolean value;"));
    ReturnValueConstraintEvaluator node = new ReturnValueConstraintEvaluator();
    final MVELReturnValueEvaluatorBuilder builder = new MVELReturnValueEvaluatorBuilder();
    builder.build(context, node, descr, null);
    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);
    MVELDialectRuntimeData data = (MVELDialectRuntimeData) pkgBuilder.getPackage("pkg1").getDialectRuntimeRegistry().getDialectData("mvel");
    ((MVELReturnValueEvaluator) node.getReturnValueEvaluator()).compile(data);
    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) MVELReturnValueEvaluator(org.jbpm.process.instance.impl.MVELReturnValueEvaluator) MVELDialect(org.drools.compiler.rule.builder.dialect.mvel.MVELDialect) ReturnValueConstraintEvaluator(org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator) MVELReturnValueEvaluatorBuilder(org.jbpm.process.builder.dialect.mvel.MVELReturnValueEvaluatorBuilder) SplitInstance(org.jbpm.workflow.instance.node.SplitInstance) MVELDialectRuntimeData(org.drools.core.rule.MVELDialectRuntimeData) PackageBuildContext(org.drools.compiler.rule.builder.PackageBuildContext) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) StringReader(java.io.StringReader) 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)

Aggregations

StringReader (java.io.StringReader)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)1 ReturnValueDescr (org.drools.compiler.compiler.ReturnValueDescr)1 PackageBuildContext (org.drools.compiler.rule.builder.PackageBuildContext)1 MVELDialect (org.drools.compiler.rule.builder.dialect.mvel.MVELDialect)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)1 MVELReturnValueEvaluatorBuilder (org.jbpm.process.builder.dialect.mvel.MVELReturnValueEvaluatorBuilder)1 MVELReturnValueEvaluator (org.jbpm.process.instance.impl.MVELReturnValueEvaluator)1 ReturnValueConstraintEvaluator (org.jbpm.process.instance.impl.ReturnValueConstraintEvaluator)1 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)1 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)1 SplitInstance (org.jbpm.workflow.instance.node.SplitInstance)1 Test (org.junit.Test)1 KieSession (org.kie.api.runtime.KieSession)1