1 package org.apache.velocity.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23 import org.apache.velocity.VelocityContext;
24 import org.apache.velocity.context.InternalContextAdapterImpl;
25 import org.apache.velocity.context.VMContext;
26 import org.apache.velocity.runtime.RuntimeConstants;
27 import org.apache.velocity.runtime.RuntimeInstance;
28
29
30
31
32
33
34
35 public class VMContextLocalscopeTestCase extends TestCase {
36
37 private RuntimeInstance instance;
38
39 public void setUp() throws Exception
40 {
41 this.instance = new RuntimeInstance();
42 this.instance.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);
43 this.instance.init();
44 }
45
46 public void testLocalscopePutDoesntLeakButGetDoes()
47 {
48 VelocityContext base = new VelocityContext();
49 base.put("outsideVar", "value1");
50
51 VMContext vm = new VMContext(new InternalContextAdapterImpl(base), this.instance);
52 vm.put("newLocalVar", "value2");
53
54
55 assertNull(base.get("newLocalVar"));
56 assertEquals("value2", vm.get("newLocalVar"));
57
58
59 assertEquals("value1", vm.get("outsideVar"));
60
61
62 vm.put("outsideVar", "value3");
63 assertEquals("value3", vm.get("outsideVar"));
64 assertEquals("value1", base.get("outsideVar"));
65 }
66
67 }