Search in sources :

Example 6 with Foo

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

the class WithTests method testExecuteCoercionTwice.

public void testExecuteCoercionTwice() {
    OptimizerFactory.setDefaultOptimizer("reflective");
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("foo", new Foo());
    vars.put("$value", new Long(5));
    ExpressionCompiler compiler = new ExpressionCompiler("with (foo) { countTest = $value };");
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("test.mv");
    ctx.setDebugSymbols(true);
    CompiledExpression compiled = compiler.compile(ctx);
    executeExpression(compiled, null, vars);
    executeExpression(compiled, null, vars);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 7 with Foo

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

the class WithTests method testWith5.

public void testWith5() {
    String expr = "with (foo) { countTest += 5, \n" + "// foobar!\n" + "aValue = 'Hello',\n" + "/** Comment! **/\n" + "bValue = 'Goodbye'\n }; with (foo) { countTest *= 2 }; foo";
    Map vars = createTestMap();
    assertEquals(true, MVEL.eval(expr, vars) instanceof Foo);
    Foo foo = (Foo) test(expr);
    assertEquals(10, foo.getCountTest());
    assertEquals("Hello", foo.aValue);
    assertEquals("Goodbye", foo.bValue);
}
Also used : Foo(org.mvel2.tests.core.res.Foo)

Example 8 with Foo

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

the class WithTests method testExecuteCoercionTwice2.

public void testExecuteCoercionTwice2() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("foo", new Foo());
    vars.put("$value", new Long(5));
    ExpressionCompiler compiler = new ExpressionCompiler("with (foo) { countTest = $value };");
    ParserContext ctx = new ParserContext();
    ctx.setSourceFile("test.mv");
    ctx.setDebugSymbols(true);
    CompiledExpression compiled = compiler.compile(ctx);
    executeExpression(compiled, null, vars);
    executeExpression(compiled, null, vars);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 9 with Foo

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

the class WithTests method testInlineWith5.

public void testInlineWith5() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    ParserContext pCtx = new ParserContext();
    pCtx.setStrongTyping(true);
    pCtx.addInput("foo", Foo.class);
    CompiledExpression expr = new ExpressionCompiler("foo.{name='poopy', aValue='bar'}").compile(pCtx);
    Foo f = (Foo) executeExpression(expr, createTestMap());
    assertEquals("poopy", f.getName());
    assertEquals("bar", f.aValue);
}
Also used : Foo(org.mvel2.tests.core.res.Foo) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) ParserContext(org.mvel2.ParserContext) CompiledExpression(org.mvel2.compiler.CompiledExpression)

Example 10 with Foo

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

the class WithTests method testWithMultipleMethodCalls.

public void testWithMultipleMethodCalls() {
    ParserContext ctx = ParserContext.create().stronglyTyped().withInput("foo", Foo.class);
    MVEL.compileExpression("with (foo) { setName('foo'), setBar(null) }", ctx);
}
Also used : ParserContext(org.mvel2.ParserContext)

Aggregations

ExpressionCompiler (org.mvel2.compiler.ExpressionCompiler)27 Foo (org.mvel2.tests.core.res.Foo)22 ParserContext (org.mvel2.ParserContext)18 CompiledExpression (org.mvel2.compiler.CompiledExpression)15 Serializable (java.io.Serializable)14 HashMap (java.util.HashMap)12 Test (org.junit.Test)9 KieServices (org.kie.api.KieServices)9 KieFileSystem (org.kie.api.builder.KieFileSystem)9 ReleaseId (org.kie.api.builder.ReleaseId)9 KieContainer (org.kie.api.runtime.KieContainer)9 PropertyAccessException (org.mvel2.PropertyAccessException)9 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)9 KieSession (org.kie.api.runtime.KieSession)8 ConsequenceException (org.kie.api.runtime.rule.ConsequenceException)7 VariableResolverFactory (org.mvel2.integration.VariableResolverFactory)7 Map (java.util.Map)5 DefaultLocalVariableResolverFactory (org.mvel2.integration.impl.DefaultLocalVariableResolverFactory)5 Interceptor (org.mvel2.integration.Interceptor)4 ASTNode (org.mvel2.ast.ASTNode)3