Search in sources :

Example 1 with DefaultKnowledgeHelper

use of org.mvel2.tests.core.res.DefaultKnowledgeHelper in project mvel by mvel.

the class CoreConfidenceTests method testInterfaceMethodCallWithSpace.

@SuppressWarnings({ "unchecked" })
public void testInterfaceMethodCallWithSpace() {
    Map map = new HashMap();
    DefaultKnowledgeHelper helper = new DefaultKnowledgeHelper();
    map.put("drools", helper);
    Cheese cheese = new Cheese("stilton", 15);
    map.put("cheese", cheese);
    executeExpression(compileExpression("drools.retract (cheese)"), map);
    assertSame(cheese, helper.retracted.get(0));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DefaultKnowledgeHelper(org.mvel2.tests.core.res.DefaultKnowledgeHelper) Cheese(org.mvel2.tests.core.res.Cheese) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with DefaultKnowledgeHelper

use of org.mvel2.tests.core.res.DefaultKnowledgeHelper in project mvel by mvel.

the class CoreConfidenceTests method testInterfaceMethodCallWithMacro.

@SuppressWarnings({ "unchecked" })
public void testInterfaceMethodCallWithMacro() {
    Map macros = new HashMap(1);
    macros.put("retract", new Macro() {

        public String doMacro() {
            return "drools.retract";
        }
    });
    Map map = new HashMap();
    DefaultKnowledgeHelper helper = new DefaultKnowledgeHelper();
    map.put("drools", helper);
    Cheese cheese = new Cheese("stilton", 15);
    map.put("cheese", cheese);
    executeExpression(compileExpression(parseMacros("retract(cheese)", macros)), map);
    assertSame(cheese, helper.retracted.get(0));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Macro(org.mvel2.Macro) DefaultKnowledgeHelper(org.mvel2.tests.core.res.DefaultKnowledgeHelper) Cheese(org.mvel2.tests.core.res.Cheese) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with DefaultKnowledgeHelper

use of org.mvel2.tests.core.res.DefaultKnowledgeHelper in project mvel by mvel.

the class CoreConfidenceTests method testsequentialAccessorsThenMethodCall.

public void testsequentialAccessorsThenMethodCall() {
    String expr = "System.out.println(drools.workingMemory); " + "drools.workingMemory.ruleBase.removeRule(\"org.drools.examples\", \"some rule\"); ";
    ParserContext context = new ParserContext();
    context.setStrictTypeEnforcement(true);
    context.addInput("drools", KnowledgeHelper.class);
    RuleBase ruleBase = new RuleBaseImpl();
    WorkingMemory wm = new WorkingMemoryImpl(ruleBase);
    KnowledgeHelper drools = new DefaultKnowledgeHelper(wm);
    Map vars = new HashMap();
    vars.put("drools", drools);
    ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
    executeExpression(compiler.compile(), vars);
}
Also used : WorkingMemoryImpl(org.mvel2.tests.core.res.WorkingMemoryImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WorkingMemory(org.mvel2.tests.core.res.WorkingMemory) DefaultKnowledgeHelper(org.mvel2.tests.core.res.DefaultKnowledgeHelper) DefaultKnowledgeHelper(org.mvel2.tests.core.res.DefaultKnowledgeHelper) KnowledgeHelper(org.mvel2.tests.core.res.KnowledgeHelper) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) RuleBaseImpl(org.mvel2.tests.core.res.RuleBaseImpl) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RuleBase(org.mvel2.tests.core.res.RuleBase)

Example 4 with DefaultKnowledgeHelper

use of org.mvel2.tests.core.res.DefaultKnowledgeHelper in project mvel by mikebrock.

the class CoreConfidenceTests method testsequentialAccessorsThenMethodCall.

public void testsequentialAccessorsThenMethodCall() {
    String expr = "System.out.println(drools.workingMemory); " + "drools.workingMemory.ruleBase.removeRule(\"org.drools.examples\", \"some rule\"); ";
    ExpressionCompiler compiler = new ExpressionCompiler(expr);
    ParserContext context = new ParserContext();
    context.setStrictTypeEnforcement(true);
    context.addInput("drools", KnowledgeHelper.class);
    RuleBase ruleBase = new RuleBaseImpl();
    WorkingMemory wm = new WorkingMemoryImpl(ruleBase);
    KnowledgeHelper drools = new DefaultKnowledgeHelper(wm);
    Map vars = new HashMap();
    vars.put("drools", drools);
    executeExpression(compiler.compile(context), vars);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Aggregations

HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 DefaultKnowledgeHelper (org.mvel2.tests.core.res.DefaultKnowledgeHelper)3 ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)2 Cheese (org.mvel2.tests.core.res.Cheese)2 Macro (org.mvel2.Macro)1 ParserContext (org.mvel2.ParserContext)1 KnowledgeHelper (org.mvel2.tests.core.res.KnowledgeHelper)1 RuleBase (org.mvel2.tests.core.res.RuleBase)1 RuleBaseImpl (org.mvel2.tests.core.res.RuleBaseImpl)1 WorkingMemory (org.mvel2.tests.core.res.WorkingMemory)1 WorkingMemoryImpl (org.mvel2.tests.core.res.WorkingMemoryImpl)1