use of org.jbpm.compiler.xml.compiler.SemanticKnowledgeBuilderConfigurationImpl in project kogito-runtimes by kiegroup.
the class MVELDecisionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("list.add( 'hello world' )");
builder = new KnowledgeBuilderImpl(pkg, new SemanticKnowledgeBuilderConfigurationImpl());
PackageRegistry pkgReg = builder.getPackageRegistry(pkg.getName());
MVELDialect mvelDialect = (MVELDialect) pkgReg.getDialectCompiletimeRegistry().getDialect("mvel");
PackageBuildContext context = new PackageBuildContext();
context.init(builder, pkg, null, pkgReg.getDialectCompiletimeRegistry(), mvelDialect, null);
builder.addPackageFromDrl(new StringReader("package pkg1;\nglobal java.util.List list;\n"));
ActionNode actionNode = new ActionNode();
DroolsAction action = new DroolsConsequenceAction("java", null);
actionNode.setAction(action);
final MVELActionBuilder actionBuilder = new MVELActionBuilder();
actionBuilder.build(context, action, actionDescr, actionNode);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
List<String> list = new ArrayList<String>();
kruntime.getKieSession().setGlobal("list", list);
MVELDialectRuntimeData data = (MVELDialectRuntimeData) builder.getPackage("pkg1").getDialectRuntimeRegistry().getDialectData("mvel");
KogitoProcessContext processContext = new KogitoProcessContextImpl(kruntime.getKieSession());
((MVELAction) actionNode.getAction().getMetaData("Action")).compile(data);
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("hello world", list.get(0));
}
use of org.jbpm.compiler.xml.compiler.SemanticKnowledgeBuilderConfigurationImpl in project kogito-runtimes by kiegroup.
the class MVELReturnValueConstraintEvaluatorBuilderTest method testSimpleReturnValueConstraintEvaluator.
@Test
public void testSimpleReturnValueConstraintEvaluator() throws Exception {
final InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("pkg1");
ReturnValueDescr descr = new ReturnValueDescr();
descr.setText("return value");
builder = new KnowledgeBuilderImpl(pkg, new SemanticKnowledgeBuilderConfigurationImpl());
DialectCompiletimeRegistry dialectRegistry = builder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
MVELDialect mvelDialect = (MVELDialect) dialectRegistry.getDialect("mvel");
PackageBuildContext context = new PackageBuildContext();
context.init(builder, pkg, null, dialectRegistry, mvelDialect, null);
builder.addPackageFromDrl(new StringReader("package pkg1;\nglobal Boolean value;"));
ReturnValueConstraintEvaluator node = new ReturnValueConstraintEvaluator();
final MVELReturnValueEvaluatorBuilder evaluatorBuilder = new MVELReturnValueEvaluatorBuilder();
evaluatorBuilder.build(context, node, descr, null);
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
kruntime.getKieSession().setGlobal("value", true);
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) kruntime.getKieSession());
SplitInstance splitInstance = new SplitInstance();
splitInstance.setProcessInstance(processInstance);
MVELDialectRuntimeData data = (MVELDialectRuntimeData) builder.getPackage("pkg1").getDialectRuntimeRegistry().getDialectData("mvel");
((MVELReturnValueEvaluator) node.getReturnValueEvaluator()).compile(data);
assertTrue(node.evaluate(splitInstance, null, null));
kruntime.getKieSession().setGlobal("value", false);
assertFalse(node.evaluate(splitInstance, null, null));
}
use of org.jbpm.compiler.xml.compiler.SemanticKnowledgeBuilderConfigurationImpl in project kogito-runtimes by kiegroup.
the class DumperTestHelper method XmlFile.
public static void XmlFile(String filename) throws Exception {
SemanticKnowledgeBuilderConfigurationImpl conf = new SemanticKnowledgeBuilderConfigurationImpl();
XmlPackageReader xmlPackageReader = new XmlPackageReader(conf.getSemanticModules());
xmlPackageReader.getParser().setClassLoader(DumperTestHelper.class.getClassLoader());
xmlPackageReader.read(new InputStreamReader(DumperTestHelper.class.getResourceAsStream(filename)));
final PackageDescr pkgOriginal = xmlPackageReader.getPackageDescr();
final XmlDumper dumper = new XmlDumper();
final String result = dumper.dump(pkgOriginal);
String buffer = readFile(filename);
System.out.println(buffer);
System.out.println(result);
assertThat(buffer).isEqualToIgnoringWhitespace(result);
assertThat(result).isNotNull();
}
use of org.jbpm.compiler.xml.compiler.SemanticKnowledgeBuilderConfigurationImpl in project kogito-runtimes by kiegroup.
the class JavaActionBuilderTest method testSimpleAction.
@Test
public void testSimpleAction() throws Exception {
final InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("pkg1");
ActionDescr actionDescr = new ActionDescr();
actionDescr.setText("list.add( \"hello world\" );");
builder = new KnowledgeBuilderImpl(pkg, new SemanticKnowledgeBuilderConfigurationImpl());
DialectCompiletimeRegistry dialectRegistry = builder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
JavaDialect javaDialect = (JavaDialect) dialectRegistry.getDialect("java");
ProcessDescr processDescr = new ProcessDescr();
processDescr.setClassName("Process1");
processDescr.setName("Process1");
WorkflowProcessImpl process = new WorkflowProcessImpl();
process.setName("Process1");
process.setPackageName("pkg1");
ProcessBuildContext context = new ProcessBuildContext(builder, builder.getPackage("pkg1"), null, processDescr, dialectRegistry, javaDialect);
context.init(builder, pkg, null, dialectRegistry, javaDialect, null);
builder.addPackageFromDrl(new StringReader("package pkg1;\nglobal java.util.List list;\n"));
ActionNode actionNode = new ActionNode();
DroolsAction action = new DroolsConsequenceAction("java", null);
actionNode.setAction(action);
ProcessDialect dialect = ProcessDialectRegistry.getDialect("java");
dialect.getActionBuilder().build(context, action, actionDescr, actionNode);
dialect.addProcess(context);
javaDialect.compileAll();
assertEquals(0, javaDialect.getResults().size());
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
List<String> list = new ArrayList<String>();
kruntime.getKieSession().setGlobal("list", list);
KogitoProcessContext processContext = new KogitoProcessContextImpl(kruntime.getKieRuntime());
((Action) actionNode.getAction().getMetaData("Action")).execute(processContext);
assertEquals("hello world", list.get(0));
}
use of org.jbpm.compiler.xml.compiler.SemanticKnowledgeBuilderConfigurationImpl in project kogito-runtimes by kiegroup.
the class JavaReturnValueConstraintEvaluatorBuilderTest method testSimpleReturnValueConstraintEvaluator.
@Test
public void testSimpleReturnValueConstraintEvaluator() throws Exception {
final InternalKnowledgePackage pkg = CoreComponentFactory.get().createKnowledgePackage("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;");
builder = new KnowledgeBuilderImpl(pkg, new SemanticKnowledgeBuilderConfigurationImpl());
DialectCompiletimeRegistry dialectRegistry = builder.getPackageRegistry(pkg.getName()).getDialectCompiletimeRegistry();
JavaDialect javaDialect = (JavaDialect) dialectRegistry.getDialect("java");
ProcessBuildContext context = new ProcessBuildContext(builder, pkg, process, processDescr, dialectRegistry, javaDialect);
builder.addPackageFromDrl(new StringReader("package pkg1;\nglobal Boolean value;"));
ReturnValueConstraintEvaluator node = new ReturnValueConstraintEvaluator();
final JavaReturnValueEvaluatorBuilder evaluatorBuilder = new JavaReturnValueEvaluatorBuilder();
evaluatorBuilder.build(context, node, descr, null);
ProcessDialectRegistry.getDialect(JavaDialect.ID).addProcess(context);
javaDialect.compileAll();
assertEquals(0, javaDialect.getResults().size());
KogitoProcessRuntime kruntime = createKogitoProcessRuntime();
kruntime.getKieSession().setGlobal("value", true);
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) kruntime.getKieSession());
SplitInstance splitInstance = new SplitInstance();
splitInstance.setProcessInstance(processInstance);
assertTrue(node.evaluate(splitInstance, null, null));
kruntime.getKieSession().setGlobal("value", false);
assertFalse(node.evaluate(splitInstance, null, null));
}
Aggregations