Exemplo n.º 1
0
  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();
    }
  }
Exemplo n.º 2
0
  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);
  }
Exemplo n.º 3
0
  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");
    }
  }
Exemplo n.º 4
0
  public void testMVEL236() {
    StringBuffer buffer = new StringBuffer();

    buffer.append("MyInterface2 var2 = (MyInterface2)var1;");

    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("var1", MyInterface3.class);
    ctx.addImport(MyInterface2.class);
    ctx.addImport(MyInterface3.class);

    try {
      CompiledExpression compiled =
          (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
Exemplo n.º 5
0
  public void testMVEL235() {
    StringBuffer buffer = new StringBuffer();

    buffer.append("if(var1.equals(var2)) {");
    buffer.append("return true;");
    buffer.append("}");

    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("var1", MyInterface2.class);
    ctx.addInput("var2", MyInterface2.class);

    try {
      Serializable compiled = (Serializable) MVEL.compileExpression(buffer.toString(), ctx);
      System.out.println(compiled);
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
Exemplo n.º 6
0
  public void testMVEL234() {
    StringBuffer buffer = new StringBuffer();

    buffer.append("import java.text.SimpleDateFormat;");
    buffer.append("if (\"test\".matches(\"[0-9]\")) {");
    buffer.append("  return false;");
    buffer.append("}else{");
    buffer.append("  SimpleDateFormat sqf = new SimpleDateFormat(\"yyyyMMdd\");");
    buffer.append("}");

    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);

    try {
      CompiledExpression compiled =
          (CompiledExpression) MVEL.compileExpression(buffer.toString(), ctx);
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
Exemplo n.º 7
0
  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();
    }
  }