public void testStrictStrongTypingCompilationErrors2() throws Exception { ParserContext ctx = new ParserContext(); ctx.setStrictTypeEnforcement(true); ctx.setStrongTyping(true); ctx.addImport(Foo.class); ctx.addInput("$bar", Bar.class); try { MVEL.compileExpression("x_a = new Foo244( $ba ); x_a.equals($ba);", ctx); fail("This should not compileShared"); } catch (Exception e) { e.printStackTrace(); } }
public void testStrongTyping2() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("blah", String.class); try { new ExpressionCompiler("1-blah").compile(ctx); } catch (Exception e) { e.printStackTrace(); return; } assertTrue(false); }
public void testMVEL232() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.setStrictTypeEnforcement(true); String script = "for(int i=0;i<2;i++) { " + " System.out.println(i+\"\");" + "} " + " return true;"; try { CompiledExpression compiled = (CompiledExpression) MVEL.compileExpression(script, ctx); HashMap<String, Object> map = new HashMap<String, Object>(); MVEL.executeExpression(compiled, map); } catch (Exception e) { e.printStackTrace(); fail("should now throw an exception"); } }
public void testStaticMethodCallThrowsException() { String text = " ( throwException( ) ) "; 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(true); pctx.setStrongTyping(true); Map<String, Object> vars = new HashMap<String, Object>(); Serializable expr = MVEL.compileExpression(text, pctx); try { MVEL.executeExpression(expr); fail("this should throw an exception"); } catch (Exception e) { e.printStackTrace(); } }