Package org.mvel2.tests.core.res

Examples of org.mvel2.tests.core.res.Foo


      public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
        return "NULL";
      }
    });

    Foo foo = new Foo();
    Bar bar = foo.getBar();
    foo.setBar(null);

    Map map = new HashMap();
    map.put("foo", foo);

    Serializable s = MVEL.compileExpression("foo.bar");

    assertEquals("NULL", MVEL.executeExpression(s, map));
    assertEquals("NULL", MVEL.executeExpression(s, map));
    foo.setBar(bar);
    assertEquals(bar, MVEL.executeExpression(s, map));
  }
View Full Code Here


      public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
        return "NULL";
      }
    });

    Foo foo = new Foo();
    Bar bar = foo.getBar();
    foo.setBar(null);

    Map map = new HashMap();
    map.put("foo", foo);

    Serializable s = MVEL.compileExpression("foo.bar");

    assertEquals("NULL", MVEL.executeExpression(s, map));
    assertEquals("NULL", MVEL.executeExpression(s, map));
    foo.setBar(bar);
    assertEquals(bar, MVEL.executeExpression(s, map));
  }
View Full Code Here

    PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {
      public Object getProperty(String name, Object contextObj,
                                VariableResolverFactory variableFactory) {
        List someList = new ArrayList();
        someList.add(new Foo());
        return someList;
      }

      public Object setProperty(String name, Object contextObj,
                                VariableResolverFactory variableFactory, Object value) {
        return null;
      }
    });

    PropertyHandlerFactory.registerPropertyHandler(List.class, new
        PropertyHandler() {
          public Object getProperty(String name, Object contextObj,
                                    VariableResolverFactory variableFactory) {
            List list = (List) contextObj;
            int index = Integer.valueOf(name);
            while (index >= list.size()) {
              list.add(new Foo());
            }

            return list.get(index);
          }

          public Object setProperty(String name, Object contextObj,
                                    VariableResolverFactory variableFactory, Object value) {
            return null;
          }
        });

    Foo foo = new Foo();

    final Serializable fooExpr0 =
        MVEL.compileSetExpression("collectionTest[0].name");
    final Serializable fooExpr1 =
        MVEL.compileSetExpression("collectionTest[1].name");
View Full Code Here

  public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
    return new String[][]{{"2008-04-01", "2008-05-10"}, {"2007-03-01", "2007-02-12"}};
  }

  public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) {
    Foo foo = (Foo) variableFactory.getVariableResolver("foo").getValue();

    if (value == null) {
      foo.charTestFld = 0;
    }
    else {
View Full Code Here

    pCtx.setStrongTyping(true);
    pCtx.addImport(Foo.class);
    pCtx.addInput("l", ArrayList.class, new Class[]{Foo.class});

    List l = new ArrayList();
    l.add(new Foo());
    l.add(new Foo());
    l.add(new Foo());

    Map vars = new HashMap();
    vars.put("l", l);

    Serializable s = MVEL.compileExpression("String s = ''; for (Foo f : l) { s += f.name }; s", pCtx);
View Full Code Here

        user.getFirstName());
  }

  public void testSetSemantics() {
    Bar bar = new Bar();
    Foo foo = new Foo();

    assertEquals("dog",
        MVEL.getProperty("name",
            bar));
    assertEquals("dog",
View Full Code Here

    assertTrue(false);
  }

  public void testNullSafe() {
    Foo foo = new Foo();

    Map map = new HashMap();
    map.put("foo",
        foo);

    String expression = "foo.?bar.name == null";
    Serializable compiled = compileExpression(expression);

    OptimizerFactory.setDefaultOptimizer("reflective");
    assertEquals(false,
        executeExpression(compiled,
            map));
    foo.setBar(null);
    assertEquals(true,
        executeExpression(compiled,
            map)); // execute a second time (to search for optimizer problems)

    OptimizerFactory.setDefaultOptimizer("ASM");
    compiled = compileExpression(expression);
    foo.setBar(new Bar());
    assertEquals(false,
        executeExpression(compiled,
            map));
    foo.setBar(null);
    assertEquals(true,
        executeExpression(compiled,
            map)); // execute a second time (to search for optimizer problems)

    assertEquals(true,
View Full Code Here

    assertTrue(((Long) executeExpression(c,
        new HashMap())) > 0);

    Map map = new HashMap();
    map.put("foo",
        new Foo());
    c = compileExpression("foo.happy");
    assertEquals("happyBar",
        executeExpression(c,
            map));
View Full Code Here

      System.out.println("cat is running");
    }
  }

  public void testSetExpressions2() {
    Foo foo = new Foo();
    Collection col = new ArrayList();
    final Serializable fooExpr = compileSetExpression("collectionTest");
    executeSetExpression(fooExpr,
        foo,
        col);
    assertEquals(col,
        foo.getCollectionTest());
  }
View Full Code Here

    assertTrue(requiredInputs.contains("aKey"));
  }

  public void testMapsWithVariableAsKey2() {
    String ex = "objectKeyMaptributes[$aPerson] == foo";
    Foo foo = new Foo();
    Person person = new Person();
    person.setObjectKeyMaptributes(new HashMap<Object, Foo>());
    person.getObjectKeyMaptributes().put(person, foo);
    Map<String, Class> inputs = new HashMap<String, Class>();
    inputs.put("this", Person.class);
View Full Code Here

TOP

Related Classes of org.mvel2.tests.core.res.Foo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.