Beispiel #1
0
  public void testNullProperties() {
    Foo foo = new Foo();
    foo.setALong(88);

    Map context = Ognl.createDefaultContext(foo);

    ognlUtil.setProperties(null, foo, context);
    assertEquals(88, foo.getALong());

    Map props = new HashMap();
    props.put("aLong", "99");
    ognlUtil.setProperties(props, foo, context);
    assertEquals(99, foo.getALong());
  }
Beispiel #2
0
  public void testStringToLong() {
    Foo foo = new Foo();

    Map context = Ognl.createDefaultContext(foo);

    Map props = new HashMap();
    props.put("aLong", "123");

    ognlUtil.setProperties(props, foo, context);
    assertEquals(123, foo.getALong());

    props.put("aLong", new String[] {"123"});

    foo.setALong(0);
    ognlUtil.setProperties(props, foo, context);
    assertEquals(123, foo.getALong());
  }
Beispiel #3
0
  public void testGetBeanMap() throws Exception {
    Bar bar = new Bar();
    bar.setTitle("I have beer");

    Foo foo = new Foo();
    foo.setALong(123);
    foo.setNumber(44);
    foo.setBar(bar);
    foo.setTitle("Hello Santa");
    foo.setUseful(true);

    // just do some of the 15 tests
    Map beans = ognlUtil.getBeanMap(foo);
    assertNotNull(beans);
    assertEquals(19, beans.size());
    assertEquals("Hello Santa", beans.get("title"));
    assertEquals(new Long("123"), beans.get("ALong"));
    assertEquals(new Integer("44"), beans.get("number"));
    assertEquals(bar, beans.get("bar"));
    assertEquals(Boolean.TRUE, beans.get("useful"));
  }