Author: rahul Date: Fri Jun 15 14:31:30 2007 New Revision: 547791 URL: http://svn.apache.org/viewvc?view=rev&rev=547791 Log: Adding information to evaluation error messages SCXML-41
Also added tests for the evaluators, including those that make sure that the failing expression is echoed in the error message. Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/JexlEvaluatorTest.java (with props) jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/ELEvaluatorTest.java (with props) Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java?view=diff&rev=547791&r1=547790&r2=547791 ============================================================================== --- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java (original) +++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jexl/JexlEvaluator.java Fri Jun 15 14:31:30 2007 @@ -83,7 +83,8 @@ exp = ExpressionFactory.createExpression(evalExpr); return exp.evaluate(getEffectiveContext(jexlCtx)); } catch (Exception e) { - throw new SCXMLExpressionException(e); + throw new SCXMLExpressionException("eval('" + expr + "'):" + + e.getMessage(), e); } } @@ -110,7 +111,8 @@ exp = ExpressionFactory.createExpression(evalExpr); return (Boolean) exp.evaluate(getEffectiveContext(jexlCtx)); } catch (Exception e) { - throw new SCXMLExpressionException(e); + throw new SCXMLExpressionException("eval('" + expr + "'):" + + e.getMessage(), e); } } @@ -139,7 +141,8 @@ exp = ExpressionFactory.createExpression(evalExpr); return (Node) exp.evaluate(getEffectiveContext(jexlCtx)); } catch (Exception e) { - throw new SCXMLExpressionException(e); + throw new SCXMLExpressionException("eval('" + expr + "'):" + + e.getMessage(), e); } } Modified: jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java?view=diff&rev=547791&r1=547790&r2=547791 ============================================================================== --- jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java (original) +++ jakarta/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/env/jsp/ELEvaluator.java Fri Jun 15 14:31:30 2007 @@ -110,7 +110,8 @@ } return rslt; } catch (ELException e) { - throw new SCXMLExpressionException(e); + throw new SCXMLExpressionException("eval('" + expr + "'):" + + e.getMessage(), e); } } @@ -140,7 +141,8 @@ } return rslt; } catch (ELException e) { - throw new SCXMLExpressionException(e); + throw new SCXMLExpressionException("eval('" + expr + "'):" + + e.getMessage(), e); } } @@ -172,7 +174,8 @@ } return rslt; } catch (ELException e) { - throw new SCXMLExpressionException(e); + throw new SCXMLExpressionException("eval('" + expr + "'):" + + e.getMessage(), e); } } Modified: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java?view=diff&rev=547791&r1=547790&r2=547791 ============================================================================== --- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java (original) +++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/EnvJexlTestSuite.java Fri Jun 15 14:31:30 2007 @@ -49,6 +49,7 @@ TestSuite suite = new TestSuite(); suite.setName("Commons-SCXML JEXL Environment Tests"); suite.addTest(JexlContextTest.suite()); + suite.addTest(JexlEvaluatorTest.suite()); suite.addTest(StaticMethodTest.suite()); return suite; } Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/JexlEvaluatorTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/JexlEvaluatorTest.java?view=auto&rev=547791 ============================================================================== --- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/JexlEvaluatorTest.java (added) +++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/JexlEvaluatorTest.java Fri Jun 15 14:31:30 2007 @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.scxml.env.jexl; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.commons.scxml.Context; +import org.apache.commons.scxml.Evaluator; +import org.apache.commons.scxml.SCXMLExpressionException; + +public class JexlEvaluatorTest extends TestCase { + + private String BAD_EXPRESSION = ">"; + private Context ctx = new JexlContext(); + + public JexlEvaluatorTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(JexlEvaluatorTest.class); + } + + public static void main(String args[]) { + String[] testCaseName = {JexlEvaluatorTest.class.getName()}; + junit.textui.TestRunner.main(testCaseName); + } + + public void testPristine() throws SCXMLExpressionException { + Evaluator eval = new JexlEvaluator(); + assertNotNull(eval); + assertTrue(((Boolean) eval.eval(ctx, "1+1 eq 2")).booleanValue()); + } + + public void testErrorMessage() { + Evaluator eval = new JexlEvaluator(); + assertNotNull(eval); + try { + eval.eval(ctx, BAD_EXPRESSION); + fail("JexlEvaluator should throw SCXMLExpressionException"); + } catch (SCXMLExpressionException e) { + assertTrue("JexlEvaluator: Incorrect error message", + e.getMessage().startsWith("eval('" + BAD_EXPRESSION + "'):")); + } + } + +} Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/JexlEvaluatorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jexl/JexlEvaluatorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Added: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/ELEvaluatorTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/ELEvaluatorTest.java?view=auto&rev=547791 ============================================================================== --- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/ELEvaluatorTest.java (added) +++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/ELEvaluatorTest.java Fri Jun 15 14:31:30 2007 @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.scxml.env.jsp; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.commons.scxml.Context; +import org.apache.commons.scxml.Evaluator; +import org.apache.commons.scxml.SCXMLExpressionException; + +public class ELEvaluatorTest extends TestCase { + + private String BAD_EXPRESSION = "${${}"; + private Context ctx = new ELContext(); + + public ELEvaluatorTest(String testName) { + super(testName); + } + + public static Test suite() { + return new TestSuite(ELEvaluatorTest.class); + } + + public static void main(String args[]) { + String[] testCaseName = {ELEvaluatorTest.class.getName()}; + junit.textui.TestRunner.main(testCaseName); + } + + public void testPristine() throws SCXMLExpressionException { + Evaluator eval = new ELEvaluator(); + assertNotNull(eval); + assertTrue(((Boolean) eval.eval(ctx, "${1+1 eq 2}")).booleanValue()); + } + + public void testErrorMessage() { + Evaluator eval = new ELEvaluator(); + assertNotNull(eval); + try { + eval.eval(ctx, BAD_EXPRESSION); + fail("ELEvaluator should throw SCXMLExpressionException"); + } catch (SCXMLExpressionException e) { + assertTrue("ELEvaluator: Incorrect error message", + e.getMessage().startsWith("eval('" + BAD_EXPRESSION + "'):")); + } + } + +} Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/ELEvaluatorTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/ELEvaluatorTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java?view=diff&rev=547791&r1=547790&r2=547791 ============================================================================== --- jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java (original) +++ jakarta/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/env/jsp/EnvJspTestSuite.java Fri Jun 15 14:31:30 2007 @@ -48,6 +48,7 @@ public static Test suite() { TestSuite suite = new TestSuite(); suite.setName("Commons-SCXML JSP Environment Tests"); + suite.addTest(ELEvaluatorTest.suite()); suite.addTest(RootContextTest.suite()); return suite; } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]