Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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));
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }