Search in sources :

Example 26 with Foo

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

the class CoreConfidenceTests method testJIRA156b.

public void testJIRA156b() throws Throwable {
    ClassProvider provider = new ClassProvider();
    provider.getPrivate().foo();
    PublicClass.class.getMethod("foo").invoke(provider.getPrivate());
    String script = "provider.getPrivate().foo()";
    Serializable s = MVEL.compileExpression(script);
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("provider", provider);
    OptimizerFactory.setDefaultOptimizer("reflective");
    executeExpression(s, vars);
    OptimizerFactory.setDefaultOptimizer("ASM");
    executeExpression(s, vars);
}
Also used : Serializable(java.io.Serializable) PublicClass(org.mvel2.tests.core.res.res2.PublicClass) ClassProvider(org.mvel2.tests.core.res.res2.ClassProvider)

Example 27 with Foo

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

the class CoreConfidenceTests method testSysoutNullVariable.

public void testSysoutNullVariable() {
    // Create our root Map object
    Map<String, String> map = new HashMap<String, String>();
    map.put("foo", null);
    VariableResolverFactory factory = new MapVariableResolverFactory(new HashMap<String, Object>());
    factory.createVariable("this", map);
    org.mvel2.MVEL.executeExpression(org.mvel2.MVEL.compileExpression("System.out.println(foo);"), 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 28 with Foo

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

the class CoreConfidenceTests method testJIRA156.

public void testJIRA156() throws Throwable {
    ClassProvider provider = new ClassProvider();
    provider.getPrivate().foo();
    PublicClass.class.getMethod("foo").invoke(provider.getPrivate());
    String script = "provider.getPrivate().foo()";
    HashMap<String, Object> vars = new HashMap<String, Object>();
    vars.put("provider", provider);
    MVEL.eval(script, vars);
}
Also used : PublicClass(org.mvel2.tests.core.res.res2.PublicClass) ClassProvider(org.mvel2.tests.core.res.res2.ClassProvider)

Example 29 with Foo

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

the class CoreConfidenceTests method testThisReferenceMapVirtualObjects1.

// compiled - reflective
public void testThisReferenceMapVirtualObjects1() {
    // 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);
    OptimizerFactory.setDefaultOptimizer("reflective");
    // 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 30 with Foo

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

the class FailureTests method testShouldFail7.

public void testShouldFail7() {
    try {
        ParserContext pctx = new ParserContext();
        pctx.setStrongTyping(true);
        MVEL.compileExpression("String x = 'foo'; int y = 2; new int[] { x, y }", pctx);
    } catch (Exception e) {
        // e.printStackTrace();
        return;
    }
    shouldThrowException();
}
Also used : ParserContext(org.mvel2.ParserContext) CompileException(org.mvel2.CompileException)

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