use of org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration in project drools by kiegroup.
the class RHSTest method testRHSClone.
@Test
public void testRHSClone() {
// JBRULES-3539
final String str = "import java.util.Map;\n" + "dialect \"mvel\"\n" + "rule \"RHSClone\"\n" + "when\n" + " Map($valOne : this['keyOne'] !=null)\n" + "then\n" + " System.out.println( $valOne.clone() );\n" + "end\n";
final KnowledgeBuilderConfigurationImpl pkgBuilderCfg = new KnowledgeBuilderConfigurationImpl();
final MVELDialectConfiguration mvelConf = (MVELDialectConfiguration) pkgBuilderCfg.getDialectConfiguration("mvel");
mvelConf.setStrict(false);
mvelConf.setLangLevel(5);
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pkgBuilderCfg);
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
final KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (final KnowledgeBuilderError error : errors) {
System.err.println(error);
}
fail("Could not parse knowledge");
}
}
use of org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration in project drools by kiegroup.
the class Misc2Test method testExtendsWithStrictModeOff.
@Test
public void testExtendsWithStrictModeOff() {
// DROOLS-475
String str = "import java.util.HashMap;\n" + "dialect \"mvel\"\n" + "declare HashMap end\n" + "\n" + "declare Test extends HashMap end\n" + "\n" + "rule \"Insert\" salience 0\n" + "when\n" + "then\n" + "Test t = new Test();\n" + "t.Price = 10;\n" + "t.put(\"A\", \"a\");\n" + "t.OtherPrices = new HashMap();\n" + "t.OtherPrices.OldPrice = 8;\n" + "System.out.println(\"Inserting t=\"+t);\n" + "insert(t);\n" + "end\n" + "\n" + "rule \"Test HashMap\" salience -1\n" + "when\n" + "t: HashMap( Price < 11 )\n" + "then\n" + "t.Price = 11;\n" + "System.out.println(\"In Test HashMap\");\n" + "end\n" + "\n" + "rule \"Test Inherited\" salience -1\n" + "when\n" + "t: Test( Price < 100 )\n" + "then\n" + "t.Price = 12;\n" + "System.out.println(\"In Test Inherited!\");\n" + "end\n" + "\n" + "rule \"Print Result\" salience -5\n" + "when\n" + "t: Test()\n" + "then\n" + "System.out.println(\"Finally Price is =\"+t.Price);\n" + "//This as well doesn't print content as per toString() of HashMap is there a way to do that?\n" + "System.out.println(\"Finally t=\"+t);\n" + "end\n";
KnowledgeBuilderConfigurationImpl pkgBuilderCfg = new KnowledgeBuilderConfigurationImpl();
MVELDialectConfiguration mvelConf = (MVELDialectConfiguration) pkgBuilderCfg.getDialectConfiguration("mvel");
mvelConf.setStrict(false);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pkgBuilderCfg);
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.hasErrors());
}
use of org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration in project drools by kiegroup.
the class FromTest method testFromWithStrictModeOff.
@Test
public void testFromWithStrictModeOff() {
// JBRULES-3533
final String str = "import java.util.Map;\n" + "dialect \"mvel\"\n" + "rule \"LowerCaseFrom\"\n" + "when\n" + " Map($valOne : this['keyOne'] !=null)\n" + " $lowerValue : String() from $valOne.toLowerCase()\n" + "then\n" + " System.out.println( $valOne.toLowerCase() );\n" + "end\n";
final KnowledgeBuilderConfigurationImpl pkgBuilderCfg = new KnowledgeBuilderConfigurationImpl();
final MVELDialectConfiguration mvelConf = (MVELDialectConfiguration) pkgBuilderCfg.getDialectConfiguration("mvel");
mvelConf.setStrict(false);
mvelConf.setLangLevel(5);
final KieBase kbase = loadKnowledgeBaseFromString(pkgBuilderCfg, str);
final KieSession ksession = kbase.newKieSession();
final Map<String, String> testMap = new HashMap<String, String>();
testMap.put("keyOne", "valone");
testMap.put("valTwo", "valTwo");
ksession.insert(testMap);
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
}
Aggregations