Search in sources :

Example 1 with MVELDialectConfiguration

use of org.drools.mvel.builder.MVELDialectConfiguration in project drools by kiegroup.

the class Misc2Test method testExtendsWithStrictModeOff.

@Test
public void testExtendsWithStrictModeOff() {
    // not for exec-model test. Cannot change DialectConfiguration by kieModuleConfigurationProperties
    // 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) FactWithString(org.drools.mvel.integrationtests.facts.FactWithString) MVELDialectConfiguration(org.drools.mvel.builder.MVELDialectConfiguration) Test(org.junit.Test)

Aggregations

KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 MVELDialectConfiguration (org.drools.mvel.builder.MVELDialectConfiguration)1 FactWithString (org.drools.mvel.integrationtests.facts.FactWithString)1 Test (org.junit.Test)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1