Example #1
0
  public void testProtoWithOtherProtoRef() {
    if (!run) return;

    String ex =
        "proto Parent { Child child = new Child(); }; proto Child { Parent parent; }; "
            + "Parent parent = new Parent(); if (parent.child.parent == null) { 'YEP' } else { 'NOPE' }";
    Object o = MVEL.eval(ex, new HashMap<String, Object>());
    assertEquals("YEP", o);
  }
Example #2
0
  public void testProtoFieldAccess() {
    if (!run) return;

    Object o =
        MVEL.eval(
            "proto Person { int age = 5; String name; }; (p = new Person()).age",
            new HashMap<String, Object>());
    assertEquals(5, o);
  }
Example #3
0
  public void testBasicProtoConstruct() {
    if (!run) return;

    assertTrue(
        MVEL.eval(
                "proto Person { int age; String name; }; new Person();",
                new HashMap<String, Object>())
            instanceof Proto.ProtoInstance);
  }
Example #4
0
  public void testMVEL() throws Exception {
    Marshaller marshaller = new Marshaller();

    // run once to generate templates
    Object data1 = getData();
    String str = marshaller.marshallToString(data1);
    System.out.println(str);
    Object data2 = MVEL.eval(str);
    assertNotSame(data1, data2);
    assertEquals(data1, data2);

    long start = System.currentTimeMillis();
    for (int i = 0; i < COUNT; i++) {
      data1 = getData();
      str = marshaller.marshallToString(data1);
      data2 = MVEL.eval(str);
      assertNotSame(data1, data2);
      assertEquals(data1, data2);
    }
    long end = System.currentTimeMillis();

    System.out.println("mvel : " + (end - start));
  }
Example #5
0
  public void testProtoWithFunction() {
    if (!run) return;

    Object o =
        MVEL.eval(
            "proto Person { "
                + "               int age = 2; "
                + "               def multAge() { "
                + "                   age * 10 "
                + "               }; "
                + "             };"
                + "             p = new Person(); "
                + "             p.multAge();",
            new HashMap<String, Object>());
    assertEquals(20, o);
  }
Example #6
0
  public void testProtoWithFunction2() {
    if (!run) return;

    String ex =
        "proto Adder {"
            + "int count = 0;"
            + "def accumulate() {"
            + "if (count < 10) {"
            + "System.out.println('counting:' + count);"
            + "count++;"
            + "accumulate();"
            + "}"
            + "}"
            + "};"
            + "adder = new Adder();"
            + "adder.accumulate();"
            + "adder.count;";

    Object o = MVEL.eval(ex, new HashMap<String, Object>());
    assertEquals(10, o);
  }