1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.env.jexl;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 import org.apache.commons.scxml.Builtin;
27
28 public class JexlContextTest extends TestCase {
29
30 public JexlContextTest(String testName) {
31 super(testName);
32 }
33
34 public static Test suite() {
35 return new TestSuite(JexlContextTest.class);
36 }
37
38 public static void main(String args[]) {
39 String[] testCaseName = {JexlContextTest.class.getName()};
40 junit.textui.TestRunner.main(testCaseName);
41 }
42
43 public void testNew() {
44 JexlContext ctx = new JexlContext();
45 assertNotNull(ctx);
46 assertEquals(1, ctx.getVars().size());
47 assertTrue(ctx.get("_builtin") instanceof Builtin);
48 }
49
50 public void testPrepopulated() {
51 Map m = new HashMap();
52 m.put("foo", "bar");
53 JexlContext ctx = new JexlContext(m);
54 assertNotNull(ctx);
55 assertEquals(2, ctx.getVars().size());
56 assertTrue(ctx.get("_builtin") instanceof Builtin);
57 String fooValue = (String) ctx.get("foo");
58 assertEquals("bar", fooValue);
59 }
60
61 public void testSetVars() {
62 JexlContext ctx = new JexlContext();
63 assertNotNull(ctx);
64 assertEquals(1, ctx.getVars().size());
65 assertTrue(ctx.get("_builtin") instanceof Builtin);
66 Map m = new HashMap();
67 m.put("foo", "bar");
68 ctx.setVars(m);
69 assertEquals(2, ctx.getVars().size());
70 String fooValue = (String) ctx.get("foo");
71 assertTrue(ctx.get("_builtin") instanceof Builtin);
72 assertEquals("bar", fooValue);
73 }
74
75 }