예제 #1
0
  public void testTypeCalculation() {
    ParserContext ctx = ParserContext.create().stronglyTyped();
    ctx.addInput("foo", Foo.class);

    Class cls = MVEL.analyze("foo.bar.testList.get(0)", ctx);

    assertTrue(Integer.class.isAssignableFrom(cls));
  }
예제 #2
0
  public void testGenericInference2() {
    ParserContext ctx;
    MVEL.analysisCompile(
        "$result = person.maptributes['fooey'].name",
        ctx = ParserContext.create().stronglyTyped().withInput("person", Person.class));

    assertEquals(String.class, ctx.getVarOrInputTypeOrNull("$result"));
  }
예제 #3
0
  public void testEgressTypeCorrect() {
    ExecutableStatement stmt =
        (ExecutableStatement)
            MVEL.compileExpression(
                "type", ParserContext.create().stronglyTyped().withInput("this", Cheese.class));

    assertEquals(String.class, stmt.getKnownEgressType());
  }
예제 #4
0
  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());
  }
예제 #5
0
  public void testGenericInference() {
    String expression = "$result = person.footributes[0].name";

    ParserContext ctx;
    MVEL.analysisCompile(
        expression, ctx = ParserContext.create().stronglyTyped().withInput("person", Person.class));

    assertEquals(String.class, ctx.getVarOrInputTypeOrNull("$result"));

    Serializable s =
        MVEL.compileExpression(
            expression, ParserContext.create().stronglyTyped().withInput("person", Person.class));

    Map<String, Object> vars = new HashMap<String, Object>();
    Person p = new Person();
    p.setFootributes(new ArrayList<Foo>());
    p.getFootributes().add(new Foo());

    vars.put("person", p);

    assertEquals("dog", executeExpression(s, vars));
  }
예제 #6
0
  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"));
  }
예제 #7
0
  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());
  }
예제 #8
0
  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"));
  }
예제 #9
0
  public void testForLoopTypeCoercion() {
    ParserContext pCtx = ParserContext.create();
    pCtx.setStrongTyping(true);
    pCtx.addInput("$type", String.class);
    pCtx.addInput("l", List.class);

    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put("$type", "pc!!");
    List list = new ArrayList();
    vars.put("l", list);
    ExecutableStatement stmt =
        (ExecutableStatement)
            MVEL.compileExpression("for (byte bt:$type.getBytes()) {l.add( bt);}", pCtx);
    MVEL.executeExpression(stmt, null, vars);

    byte[] exp = "pc!!".getBytes();
    //  byte[] res = new byte[list.size()];

    for (int i = 0; i < exp.length; i++) {
      assertEquals(exp[i], list.get(i));
    }
  }
예제 #10
0
 public void testMVEL190a() {
   Serializable compiled =
       MVEL.compileExpression(
           "a.toString()", ParserContext.create().stronglyTyped().withInput("a", String.class));
 }