01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: }
|