Search in sources :

Example 36 with Foo

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

the class IntegrationTests method testIndexedVariableFactory.

public void testIndexedVariableFactory() {
    ParserContext ctx = ParserContext.create();
    String[] vars = { "a", "b" };
    Object[] vals = { "foo", "bar" };
    ctx.setIndexAllocation(true);
    ctx.addIndexedInput(vars);
    String expr = "def myfunc(z) { a + b + z }; myfunc('poop');";
    SharedVariableSpaceModel model = VariableSpaceCompiler.compileShared(expr, ctx, vals);
    Serializable s = MVEL.compileExpression(expr, ctx);
    // VariableResolverFactory locals = new CachingMapVariableResolverFactory(new HashMap<String, Object>());
    // VariableResolverFactory injected = new IndexedVariableResolverFactory(vars, vals, locals);
    assertEquals("foobarpoop", MVEL.executeExpression(s, model.createFactory()));
}
Also used : Serializable(java.io.Serializable) SharedVariableSpaceModel(org.mvel2.util.SharedVariableSpaceModel) ParserContext(org.mvel2.ParserContext)

Example 37 with Foo

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

the class AbstractTest method createTestMap.

protected static Map createTestMap() {
    Map map = new HashMap();
    map.put("foo", new Foo());
    map.put("a", null);
    map.put("b", null);
    map.put("c", "cat");
    map.put("BWAH", "");
    map.put("misc", new MiscTestClass());
    map.put("pi", "3.14");
    map.put("hour", 60);
    map.put("zero", 0);
    map.put("array", new String[] { "", "blip" });
    map.put("order", new Order());
    map.put("$id", 20);
    map.put("five", 5);
    map.put("testImpl", new TestInterface() {

        public String getName() {
            return "FOOBAR!";
        }

        public boolean isFoo() {
            return true;
        }
    });
    map.put("derived", new DerivedClass());
    map.put("ipaddr", "10.1.1.2");
    map.put("dt1", new Date(currentTimeMillis() - 100000));
    map.put("dt2", new Date(currentTimeMillis()));
    return map;
}
Also used : Foo(org.mvel2.tests.core.res.Foo) TestInterface(org.mvel2.tests.core.res.TestInterface) DerivedClass(org.mvel2.tests.core.res.DerivedClass)

Example 38 with Foo

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

the class CoreConfidenceTests method testThisReferenceMapVirtualObjects.

// interpreted
public void testThisReferenceMapVirtualObjects() {
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", "bar");
    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this", map);
    assertEquals(true, eval("this.foo == 'bar'", map, factory));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 39 with Foo

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

the class CoreConfidenceTests method testThisReferenceMapVirtualObjects2.

// compiled - asm
public void testThisReferenceMapVirtualObjects2() {
    // Create our root Map object
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", "bar");
    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this", map);
    if (!Boolean.getBoolean("mvel2.disable.jit"))
        OptimizerFactory.setDefaultOptimizer("ASM");
    // Run test
    assertEquals(true, executeExpression(compileExpression("this.foo == 'bar'"), map, factory));
}
Also used : DefaultLocalVariableResolverFactory(org.mvel2.integration.impl.DefaultLocalVariableResolverFactory) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory)

Example 40 with Foo

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

the class ComparisonTests method testIsDefOperator6.

public void testIsDefOperator6() {
    Foo foo = new Foo();
    assertEquals(true, MVEL.eval("isdef name", foo));
    assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("isdef name"), foo));
}
Also used : Foo(org.mvel2.tests.core.res.Foo)

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