Ejemplo n.º 1
0
  public void test_Set_Chain_Indexed_Property() throws Exception {
    Root root = new Root();
    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);

    context.setRoot(root);
    context.setCurrentObject(root);

    SimpleNode node =
        (SimpleNode) Ognl.parseExpression("tab.searchCriteriaSelections[index1][index2]");
    node.setValue(context, root, Boolean.FALSE);
  }
Ejemplo n.º 2
0
  public void test_Set_Get_Multiple_Generic_Types_Property() throws Exception {
    BaseGeneric<GameGenericObject, Long> root = new GameGeneric();
    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);

    context.setRoot(root);
    context.setCurrentObject(root);

    SimpleNode node = (SimpleNode) Ognl.parseExpression("ids");
    node.setValue(context, root, new String[] {"0", "20", "43"});

    isEqual(new Long[] {new Long(0), new Long(20), new Long(43)}, root.getIds());
    isEqual(node.getValue(context, root), root.getIds());
  }
Ejemplo n.º 3
0
  public void test_Get_Generic_Property() throws Exception {
    GenericRoot root = new GenericRoot();
    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);

    context.setRoot(root);
    context.setCurrentObject(root);

    SimpleNode node = (SimpleNode) Ognl.parseExpression("cracker.param");
    node.setValue(context, root, "0");

    assertEquals(new Integer(0), node.getValue(context, root));

    node.setValue(context, root, "10");

    assertEquals(new Integer(10), node.getValue(context, root));
  }
Ejemplo n.º 4
0
  public void testSetList() throws Exception {
    ChainingInterceptor foo = new ChainingInterceptor();
    ChainingInterceptor foo2 = new ChainingInterceptor();

    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
    SimpleNode expression = (SimpleNode) Ognl.parseExpression("{'a','ruby','b','tom'}");

    Ognl.getValue(expression, context, "aksdj");

    final ValueStack stack = ActionContext.getContext().getValueStack();

    Object result = Ognl.getValue(ognlUtil.compile("{\"foo\",'ruby','b','tom'}"), context, foo);
    foo.setIncludes((Collection) result);

    assertEquals(4, foo.getIncludes().size());
    assertEquals("foo", foo.getIncludes().toArray()[0]);
    assertEquals("ruby", foo.getIncludes().toArray()[1]);
    assertEquals("b", "" + foo.getIncludes().toArray()[2]);
    assertEquals("tom", foo.getIncludes().toArray()[3]);

    Object result2 = Ognl.getValue(ognlUtil.compile("{\"foo\",'ruby','b','tom'}"), context, foo2);
    ognlUtil.setProperty("includes", result2, foo2, context);

    assertEquals(4, foo.getIncludes().size());
    assertEquals("foo", foo.getIncludes().toArray()[0]);
    assertEquals("ruby", foo.getIncludes().toArray()[1]);
    assertEquals("b", "" + foo.getIncludes().toArray()[2]);
    assertEquals("tom", foo.getIncludes().toArray()[3]);

    result = ActionContext.getContext().getValueStack().findValue("{\"foo\",'ruby','b','tom'}");

    foo.setIncludes((Collection) result);
    assertEquals(ArrayList.class, result.getClass());

    assertEquals(4, foo.getIncludes().size());
    assertEquals("foo", foo.getIncludes().toArray()[0]);
    assertEquals("ruby", foo.getIncludes().toArray()[1]);
    assertEquals("b", "" + foo.getIncludes().toArray()[2]);
    assertEquals("tom", foo.getIncludes().toArray()[3]);
  }