Exemple #1
0
        public void testObjectIndexInSubclass()         // throws OgnlException
        {
            SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");

            context ["ka"] = (new Test2());
            Ognl.getValue(expression, context, "aksdj");
        }
Exemple #2
0
 public SimpleNode getExpression()         // throws OgnlException
 {
     if (expression == null)
     {
         expression = (SimpleNode)Ognl.parseExpression(expressionString);
     }
     return(expression);
 }
Exemple #3
0
 /*===================================================================
 *       Constructors
 *  ===================================================================*/
 public Performance(string name, string expressionString, string javaMethodName)         // throws OgnlException
 {
     this.name  = name;
     expression = (SimpleNode)Ognl.parseExpression(expressionString);
     try
     {
         method = GetType().GetMethod(javaMethodName, new Type[] {});
     }
     catch (Exception ex)
     {
         throw new OgnlException("java method not found", ex);
     }
 }
Exemple #4
0
 public virtual object evaluate(string expression)
 {
     try
     {
         Check.notNull(this.Fixture, "Root object is null");
         Check.notNull(expression, "Expression to evaluate cannot be null");
         return Ognl.getValue(expression, this.OgnlContext, this.Fixture);
     }
     catch (OgnlException ognlException)
     {
         throw ognlException.getReason();
     }
 }
Exemple #5
0
        protected override void setValueBody(OgnlContext context, object target, object value) // throws OgnlException
        {
            object expr         = children[0].getValue(context, target),
                   previousRoot = context.getRoot();
            Node node;

            target = children[1].getValue(context, target);
            node   = (expr is Node) ? (Node)expr : (Node)Ognl.parseExpression(expr.ToString());
            try {
                context.setRoot(target);
                node.setValue(context, target, value);
            } finally {
                context.setRoot(previousRoot);
            }
        }
Exemple #6
0
        public void testMultipleObjectIndexMethodPairs()         // throws OgnlException
        {
            SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");

            context ["ka"] = (new Test5());
            try
            {
                Ognl.getValue(expression, context, "aksdj");
                Assert.Fail();
            }
            catch (OgnlException ex)
            {
                /* Should throw */
            }
        }
Exemple #7
0
        protected override object getValueBody(OgnlContext context, object source) // throws OgnlException
        {
            object result,
                   expr         = children[0].getValue(context, source),
                   previousRoot = context.getRoot();
            Node node;

            source = children[1].getValue(context, source);
            node   = (expr is Node) ? (Node)expr : (Node)Ognl.parseExpression(expr.ToString());
            try {
                context.setRoot(source);
                result = node.getValue(context, source);
            } finally {
                context.setRoot(previousRoot);
            }
            return(result);
        }
Exemple #8
0
 public Results testExpression(bool compiled)         // throws OgnlException
 {
     if (compiled)
     {
         context.Add("_compile", true);
     }
     else
     {
         context.Remove("_compile");
     }
     Ognl.getValue(expression, context, root);
     startTest();
     do
     {
         Ognl.getValue(expression, context, root);
     } while (!done());
     return(endTest());
 }
Exemple #9
0
        /*===================================================================
        *       Overridden methods
        *  ===================================================================*/
        protected internal virtual void runTest()         // throws Exception
        {
            object testedResult = null;

            setUp();
            try
            {
                SimpleNode expr;

                testedResult = expectedResult;
                expr         = getExpression();

                /*
                 * PrintWriter writer = new PrintWriter(System.err);
                 * System.err.println(expr.toString());
                 * expr.dump(writer, "");
                 * writer.flush();
                 */
                Assert.IsTrue(isEqual(Ognl.getValue(expr, context, root), expectedResult));
                if (hasSetValue)
                {
                    testedResult = hasExpectedAfterSetResult ? expectedAfterSetResult : setValue;
                    Ognl.setValue(expr, context, root, setValue);
                    Assert.IsTrue(isEqual(Ognl.getValue(expr, context, root), testedResult));
                }
            }
            catch (Exception ex)
            {
                if (testedResult is Type)
                {
                    Assert.IsTrue(((Type)testedResult).IsAssignableFrom(ex.GetType()));
                }
                else
                {
                    Console.WriteLine(ex);
                    throw ex;
                }
            }
        }
Exemple #10
0
        public object Eval(string code, IDictionary <string, object> context)
        {
            object      root        = context;
            IDictionary dictContext = new DictionaryWrapper <string, object>(context);
            IDictionary variables   = Ognl.addDefaultContext(root, TypeResolver, dictContext);

            try {
                object res = Ognl.getValue(code, variables, root);
                if (log.IsEnabledFor(LogEvent.Debug))
                {
                    log.Write(
                        LogEvent.Debug,
                        new{ Action = "getting value", Expression = code, Result = res, Context = context }
                        );
                }
                return(res);
            } catch (Exception ex) {
                log.Write(
                    LogEvent.Error,
                    new { Action = "getting value", Exception = ex, Expression = code, Context = context });
                throw new Exception("OGNL code evaluation failed (" + code + "): " + ex.Message, ex);
            }
        }
Exemple #11
0
 protected void setUp()
 {
     context = (OgnlContext)Ognl.createDefaultContext(null);
 }
Exemple #12
0
 /*===================================================================
 *       Overridden methods
 *  ===================================================================*/
 protected internal override void runTest()
 {
     Assert.IsTrue(Ognl.isSimpleProperty(getExpression(), context) == ((bool)getExpectedResult()));
 }
 public void testPrivateField()         // throws OgnlException
 {
     NUnit.Framework.Assert.AreEqual(Ognl.getValue("_privateProperty", context, this), _privateProperty);
 }
 public void testPrivateAccessor()         // throws OgnlException
 {
     NUnit.Framework.Assert.AreEqual(Ognl.getValue("privateProperty", context, this), getPrivateProperty());
 }
 public void setUp()
 {
     context = (OgnlContext)Ognl.createDefaultContext(null);
     context.setMemberAccess(new DefaultMemberAccess(true));
 }
 public virtual object Evaluate(string expression)
 {
     Check.NotNull(Fixture, "Root object is null");
     Check.NotNull(expression, "Expression to evaluate cannot be null");
     return(Ognl.getValue(expression, OgnlContext, Fixture));
 }
Exemple #17
0
 public virtual void setUp()
 {
     context = (OgnlContext)Ognl.createDefaultContext(null);
 }
 /*===================================================================
 *       Overridden methods
 *  ===================================================================*/
 protected internal override void runTest()         // throws OgnlException
 {
     setUp();
     NUnit.Framework.Assert.IsTrue(Ognl.isConstant(getExpression(), context) == ((bool)getExpectedResult()));
 }
Exemple #19
0
 /*===================================================================
 *       Overridden methods
 *  ===================================================================*/
 protected internal override void runTest()
 {
     NUnit.Framework.Assert.IsTrue(Ognl.isSimpleNavigationChain(getExpression(), context) == ((bool)getExpectedResult()));
 }