public void testAnalysisCompile() { ParserContext pCtx = new ParserContext(); ExpressionCompiler e = new ExpressionCompiler("foo.aValue = 'bar'"); e.setVerifyOnly(true); e.compile(pCtx); assertTrue(pCtx.getInputs().keySet().contains("foo")); assertEquals(1, pCtx.getInputs().size()); assertEquals(0, pCtx.getVariables().size()); }
public void testAnalyzer() { ParserContext ctx = new ParserContext(); MVEL.compileExpression("order.id == 10", ctx); for (String input : ctx.getInputs().keySet()) { System.out.println("input>" + input); } assertEquals(1, ctx.getInputs().size()); assertTrue(ctx.getInputs().containsKey("order")); }
public void testTypeCast3() { Map map = new HashMap(); map.put("foo", new Foo()); ParserContext pCtx = new ParserContext(); pCtx.setStrongTyping(true); pCtx.addInput("foo", Foo.class); Serializable s = MVEL.compileExpression("((org.mvel2.tests.core.res.Bar) foo.getBar()).name != null", pCtx); assertEquals(true, executeExpression(s, map)); assertEquals(1, pCtx.getInputs().size()); assertEquals(true, pCtx.getInputs().containsKey("foo")); }
public void testVarInputs5() { ParserContext pCtx = ParserContext.create().withInput("list", List.class); MVEL.analysisCompile( "String nodeName = list[0];\nSystem.out.println(nodeName);nodeName = list[1];\nSystem.out.println(nodeName);", pCtx); assertEquals(1, pCtx.getInputs().size()); assertTrue(pCtx.getInputs().containsKey("list")); assertEquals(1, pCtx.getVariables().size()); assertTrue(pCtx.getVariables().containsKey("nodeName")); assertEquals(List.class, pCtx.getVarOrInputType("list")); assertEquals(String.class, pCtx.getVarOrInputType("nodeName")); }
public void testStaticFieldAccessForInputs() { MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; ParserContext pCtx = ParserContext.create(); MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx); assertFalse(pCtx.getInputs().containsKey("java")); assertEquals(0, pCtx.getInputs().size()); // MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; // // pCtx = ParserContext.create(); // MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx); // // assertFalse(pCtx.getInputs().containsKey("java")); // // assertEquals(0, // pCtx.getInputs().size()); }
public void testStaticFieldAccessForInputsWithStrictStrong() { ParserContext pCtx = ParserContext.create(); pCtx.setStrictTypeEnforcement(true); pCtx.setStrongTyping(true); MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx); assertFalse(pCtx.getInputs().containsKey("java")); assertEquals(0, pCtx.getInputs().size()); MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true; pCtx = ParserContext.create(); pCtx.setStrictTypeEnforcement(true); pCtx.setStrongTyping(true); MVEL.analysisCompile("java.math.BigDecimal.TEN", pCtx); assertFalse(pCtx.getInputs().containsKey("java")); assertEquals(0, pCtx.getInputs().size()); }
public void testVarInputs() { ParserContext pCtx = ParserContext.create(); MVEL.analysisCompile( "test != foo && bo.addSomething(trouble) " + "&& 1 + 2 / 3 == 1; String bleh = foo; twa = bleh;", pCtx); assertEquals(4, pCtx.getInputs().size()); assertTrue(pCtx.getInputs().containsKey("test")); assertTrue(pCtx.getInputs().containsKey("foo")); assertTrue(pCtx.getInputs().containsKey("bo")); assertTrue(pCtx.getInputs().containsKey("trouble")); assertEquals(2, pCtx.getVariables().size()); assertTrue(pCtx.getVariables().containsKey("bleh")); assertTrue(pCtx.getVariables().containsKey("twa")); assertEquals(String.class, pCtx.getVarOrInputType("bleh")); }
public void testStaticMethodsInInputsBug() { String text = " getList( java.util.Formatter )"; ParserConfiguration pconf = new ParserConfiguration(); for (Method m : CoreConfidenceTests.StaticMethods.class.getMethods()) { if (Modifier.isStatic(m.getModifiers())) { pconf.addImport(m.getName(), m); } } ParserContext pctx = new ParserContext(pconf); pctx.setStrictTypeEnforcement(false); pctx.setStrongTyping(false); Map<String, Object> vars = new HashMap<String, Object>(); Serializable expr = MVEL.compileExpression(text, pctx); List list = (List) MVEL.executeExpression(expr, null, vars); assertEquals(Formatter.class, list.get(0)); assertEquals(0, pctx.getInputs().size()); }