Exemplo 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);
  }
Exemplo 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());
  }
Exemplo 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));
  }
 @Before
 public void setup() {
   this.handler = new ReflectionBasedNullHandler();
   this.context = (OgnlContext) Ognl.createDefaultContext(null);
   context.setTraceEvaluations(true);
   this.mockery = new VRaptorMockery(true);
   this.container = mockery.mock(Container.class);
   context.put(Container.class, container);
   this.removal = mockery.mock(EmptyElementsRemoval.class);
   this.converters = mockery.mock(Converters.class);
   mockery.checking(
       new Expectations() {
         {
           allowing(container).instanceFor(EmptyElementsRemoval.class);
           will(returnValue(removal));
           allowing(container).instanceFor(Converters.class);
           will(returnValue(converters));
         }
       });
   OgnlRuntime.setPropertyAccessor(List.class, new ListAccessor());
   OgnlRuntime.setPropertyAccessor(Object[].class, new ArrayAccessor());
 }
Exemplo n.º 5
0
  public void test_Set_Source() throws Throwable {
    ASTProperty p = new ASTProperty(0);
    p.setIndexedAccess(false);
    ASTConst pRef = new ASTConst(0);
    pRef.setValue("nested");
    pRef.jjtSetParent(p);
    p.jjtAddChild(pRef, 0);

    Map root = new Root().getMap();

    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
    context.setRoot(root);
    context.setCurrentObject(root);
    context.setCurrentNode(pRef);

    assertEquals(".put(\"nested\", $3)", p.toSetSourceString(context, root));
    assertEquals(Object.class, context.getCurrentType());
    assertEquals(root.get("nested"), context.getCurrentObject());

    assert Map.class.isAssignableFrom(context.getCurrentAccessor());

    assertEquals(root.getClass(), context.getPreviousType());
    assertEquals(null, context.getPreviousAccessor());
  }
Exemplo n.º 6
0
  public void test_Get_Value_Body() throws Exception {
    ASTProperty p = new ASTProperty(0);
    p.setIndexedAccess(false);
    ASTConst pRef = new ASTConst(0);
    pRef.setValue("nested");
    pRef.jjtSetParent(p);
    p.jjtAddChild(pRef, 0);

    Map root = new Root().getMap();

    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
    context.setRoot(root);
    context.setCurrentObject(root);
    context.setCurrentNode(pRef);

    assertEquals(root.getClass(), context.getCurrentType());
    assertEquals(null, context.getPreviousType());
    assertEquals(root, context.getCurrentObject());
    assertEquals(null, context.getCurrentAccessor());
    assertEquals(null, context.getPreviousAccessor());

    Object value = p.getValue(context, root);

    assertEquals(root.get("nested"), value);
    assertEquals(root.getClass(), context.getCurrentType());
    assertEquals(null, context.getPreviousType());
    assertEquals(null, context.getCurrentAccessor());
    assertEquals(null, context.getPreviousAccessor());
  }
Exemplo n.º 7
0
  public void test_Indexed_Object_Type() throws Throwable {
    // ASTChain chain = new ASTChain(0);

    ASTProperty listp = new ASTProperty(0);
    listp.setIndexedAccess(false);
    // listp.jjtSetParent(chain);

    ASTConst listc = new ASTConst(0);
    listc.setValue("list");
    listc.jjtSetParent(listp);
    listp.jjtAddChild(listc, 0);

    // chain.jjtAddChild(listp, 0);

    ASTProperty p = new ASTProperty(0);
    p.setIndexedAccess(true);

    ASTProperty pindex = new ASTProperty(0);

    ASTConst pRef = new ASTConst(0);
    pRef.setValue("genericIndex");
    pRef.jjtSetParent(pindex);
    pindex.jjtAddChild(pRef, 0);

    p.jjtAddChild(pindex, 0);
    // chain.jjtAddChild(p, 1);

    Root root = new Root();

    OgnlContext context = (OgnlContext) Ognl.createDefaultContext(null);
    context.setRoot(root);
    context.setCurrentObject(root);
    context.setCurrentNode(listp);

    assertEquals(".getList()", listp.toGetSourceString(context, root));
    assertEquals(List.class, context.getCurrentType());
    assertEquals(Root.class, context.getCurrentAccessor());
    assertEquals(null, context.getPreviousAccessor());
    assertEquals(root.getClass(), context.getPreviousType());
    assertEquals(root.getList(), context.getCurrentObject());

    // re test with chain

    context = (OgnlContext) Ognl.createDefaultContext(null);
    context.setRoot(root);
    context.setCurrentObject(root);

    ASTChain chain = new ASTChain(0);
    listp.jjtSetParent(chain);
    chain.jjtAddChild(listp, 0);

    context.setCurrentNode(chain);

    assertEquals(".getList()", chain.toGetSourceString(context, root));
    assertEquals(List.class, context.getCurrentType());
    assertEquals(Root.class, context.getCurrentAccessor());
    assertEquals(null, context.getPreviousAccessor());
    assertEquals(Root.class, context.getPreviousType());
    assertEquals(root.getList(), context.getCurrentObject());

    // test with only getIndex

    assertEquals(
        ".get(ognl.OgnlOps#getIntValue(((org.ognl.test.objects.Root)$2)..getGenericIndex().toString()))",
        p.toGetSourceString(context, root.getList()));
    assertEquals(root.getArray(), context.getCurrentObject());
    assertEquals(Object.class, context.getCurrentType());
  }