1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.beanshell;
17
18 import junit.framework.Test;
19 import junit.framework.TestCase;
20 import junit.framework.TestSuite;
21 import junit.textui.TestRunner;
22
23 import org.apache.commons.jelly.JellyContext;
24 import org.apache.commons.jelly.expression.Expression;
25 import org.apache.commons.jelly.expression.ExpressionFactory;
26 import org.apache.commons.jelly.tags.beanshell.BeanShellExpressionFactory;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31
32 /*** Tests the BeanShell EL
33 *
34 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
35 * @version $Revision: 1.4 $
36 */
37 public class TestBeanShellEL extends TestCase {
38
39 /*** The Log to which logging calls will be made. */
40 private static final Log log = LogFactory.getLog( TestBeanShellEL.class );
41
42 /*** Jelly context */
43 protected JellyContext context;
44
45 /*** The factory of Expression objects */
46 protected ExpressionFactory factory;
47
48
49 public static void main( String[] args ) {
50 TestRunner.run( suite() );
51 }
52
53 public static Test suite() {
54 return new TestSuite(TestBeanShellEL.class);
55 }
56
57 public TestBeanShellEL(String testName) {
58 super(testName);
59 }
60
61 public void setUp() {
62 context = new JellyContext();
63 context.setVariable( "foo", "abc" );
64 context.setVariable( "bar", new Integer( 123 ) );
65 factory = new BeanShellExpressionFactory();
66 }
67
68 public void testEL() throws Exception {
69 assertExpression( "foo", "abc" );
70 assertExpression( "bar * 2", new Integer( 246 ) );
71 assertExpression( "bar == 123", Boolean.TRUE );
72 assertExpression( "bar == 124", Boolean.FALSE );
73 assertExpression( "foo.equals( \"abc\" )", Boolean.TRUE );
74 assertExpression( "foo.equals( \"xyz\" )", Boolean.FALSE );
75 }
76
77 /*** Evaluates the given expression text and tests it against the expected value */
78 protected void assertExpression( String expressionText, Object expectedValue ) throws Exception {
79 Expression expr = factory.createExpression( expressionText );
80 Object value = expr.evaluate( context );
81 assertEquals( "Value of expression: " + expressionText, expectedValue, value );
82 }
83 }
84