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