Search in sources :

Example 46 with Foo

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

the class TypesAndInferenceTests method testProvidedExternalTypes.

public void testProvidedExternalTypes() {
    ExpressionCompiler compiler = new ExpressionCompiler("foo.bar");
    ParserContext ctx = new ParserContext();
    ctx.setStrictTypeEnforcement(true);
    ctx.addInput("foo", Foo.class);
    compiler.compile(ctx);
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 47 with Foo

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

the class MacroProcessorTest method testMacroSupportWithDebugging.

public void testMacroSupportWithDebugging() {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("foo", new Foo());
    Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
    Map<String, Macro> macros = new HashMap<String, Macro>();
    interceptors.put("Modify", new Interceptor() {

        public int doBefore(ASTNode node, VariableResolverFactory factory) {
            ((WithNode) node).getNestedStatement().getValue(null, factory);
            factory.createVariable("mod", "FOOBAR!");
            return 0;
        }

        public int doAfter(Object val, ASTNode node, VariableResolverFactory factory) {
            return 0;
        }
    });
    macros.put("modify", new Macro() {

        public String doMacro() {
            return "@Modify with";
        }
    });
    ExpressionCompiler compiler = new ExpressionCompiler(parseMacros("System.out.println('hello');\n" + "System.out.println('bye');\n" + "modify (foo) { aValue = 'poo', \n" + " aValue = 'poo' };\n mod", macros));
    // compiler.setDebugSymbols(true);
    ParserContext ctx = new ParserContext(null, interceptors, null);
    ctx.setSourceFile("test.mv");
    ctx.setDebugSymbols(true);
    CompiledExpression compiled = compiler.compile(ctx);
    MVELRuntime.setThreadDebugger(new Debugger() {

        public int onBreak(Frame frame) {
            System.out.println(frame.getSourceName() + ":" + frame.getLineNumber());
            return Debugger.STEP;
        }
    });
    MVELRuntime.registerBreakpoint("test.mv", 3);
    System.out.println(DebugTools.decompile(compiled));
    Assert.assertEquals("FOOBAR!", MVEL.executeDebugger(compiled, null, new MapVariableResolverFactory(vars)));
}
Also used : Debugger(org.mvel2.debug.Debugger) Frame(org.mvel2.debug.Frame) HashMap(java.util.HashMap) Foo(org.mvel2.tests.core.res.Foo) WithNode(org.mvel2.ast.WithNode) CompiledExpression(org.mvel2.compiler.CompiledExpression) VariableResolverFactory(org.mvel2.integration.VariableResolverFactory) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ASTNode(org.mvel2.ast.ASTNode) MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler) Interceptor(org.mvel2.integration.Interceptor)

Example 48 with Foo

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

the class PropertyAccessTests method testInterfaceResolution.

public void testInterfaceResolution() {
    Serializable ex = compileExpression("foo.collectionTest.size()");
    Map map = createTestMap();
    Foo foo = (Foo) map.get("foo");
    foo.setCollectionTest(new HashSet());
    Object result1 = executeExpression(ex, foo, map);
    foo.setCollectionTest(new ArrayList());
    Object result2 = executeExpression(ex, foo, map);
    assertEquals(result1, result2);
}
Also used : Serializable(java.io.Serializable) Foo(org.mvel2.tests.core.res.Foo)

Example 49 with Foo

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

the class CoreConfidenceTests method testConcatWithLineBreaks.

public void testConcatWithLineBreaks() {
    ExpressionCompiler parser = new ExpressionCompiler("\"foo\"+\n\"bar\"");
    ParserContext ctx = new ParserContext();
    ctx.setDebugSymbols(true);
    ctx.setSourceFile("source.mv");
    assertEquals("foobar", executeExpression(parser.compile(ctx)));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 50 with Foo

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

the class CoreConfidenceTests method testLateResolveOfClass.

public void testLateResolveOfClass() {
    ExpressionCompiler compiler = new ExpressionCompiler("System.out.println(new Foo());");
    ParserContext ctx = new ParserContext();
    ctx.addImport(Foo.class);
    compiler.removeParserContext();
    System.out.println(executeExpression(compiler.compile(ctx)));
}
Also used : ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

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