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));
}
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));
}
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);
}
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);
}
Aggregations