You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ge...@apache.org on 2002/06/13 18:11:28 UTC

cvs commit: jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl JexlTest.java

geirm       2002/06/13 09:11:28

  Modified:    jexl/src/test/org/apache/commons/jexl JexlTest.java
  Log:
  Added test for resolver
  
  Revision  Changes    Path
  1.11      +53 -2     jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/JexlTest.java
  
  Index: JexlTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/JexlTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- JexlTest.java	7 Jun 2002 03:37:07 -0000	1.10
  +++ JexlTest.java	13 Jun 2002 16:11:28 -0000	1.11
  @@ -60,6 +60,7 @@
   import org.apache.commons.jexl.parser.SimpleNode;
   import org.apache.commons.jexl.Expression;
   import org.apache.commons.jexl.ExpressionFactory;
  +import org.apache.commons.jexl.resolver.FlatResolver;
   
   import java.io.StringReader;
   import java.util.ArrayList;
  @@ -668,6 +669,56 @@
   //        assertEquals("dot form failed", GET_METHOD_ARRAY2[1][1], o2);
       }
   
  +    public void testResolver()
  +        throws Exception
  +    {
  +        /*
  +         * first, a simple override
  +         */
  +
  +        Expression expr =
  +            ExpressionFactory.createExpression("foo.bar");
  +
  +        expr.addPreResolver(new FlatResolver());
  +
  +        JexlContext jc = JexlHelper.createContext();
  +
  +        Foo foo = new Foo();
  +
  +        jc.getVars().put("foo.bar", "flat value");
  +        jc.getVars().put("foo", foo );
  +
  +        Object o = expr.evaluate(jc);
  +
  +        assertEquals("flat override", o,"flat value");
  +
  +        /*
  +         * now, let the resolver not find it and have it drop to jexl
  +         */
  +
  +        expr =
  +            ExpressionFactory.createExpression("foo.bar.length()");
  +
  +        expr.addPreResolver(new FlatResolver());
  +
  +        o = expr.evaluate(jc);
  +
  +        assertEquals("flat override 1", o,new Integer(GET_METHOD_STRING.length()));
  +
  +        /*
  +         * now, let the resolver not find it and NOT drop to jexl
  +         */
  +
  +        expr =
  +            ExpressionFactory.createExpression("foo.bar.length()");
  +
  +        expr.addPreResolver(new FlatResolver(false));
  +
  +        o = expr.evaluate(jc);
  +
  +        assertEquals("flat override 2", o, null);
  +
  +    }
   
       public class Foo
       {
  @@ -695,7 +746,7 @@
           {
               return "Boolean : " + b;
           }
  -        
  +
           public int getCount() {
               return 5;
           }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>