Search in sources :

Example 1 with MVELDialectConfiguration

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");
    }
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) MVELDialectConfiguration(org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration) Test(org.junit.Test)

Example 2 with MVELDialectConfiguration

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());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) MVELDialectConfiguration(org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration) Test(org.junit.Test)

Example 3 with MVELDialectConfiguration

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();
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) MVELDialectConfiguration(org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration) Test(org.junit.Test)

Aggregations

KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)3 MVELDialectConfiguration (org.drools.compiler.rule.builder.dialect.mvel.MVELDialectConfiguration)3 Test (org.junit.Test)3 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)2 HashMap (java.util.HashMap)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 KnowledgeBuilderError (org.kie.internal.builder.KnowledgeBuilderError)1 KnowledgeBuilderErrors (org.kie.internal.builder.KnowledgeBuilderErrors)1