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 java.io.BufferedWriter;
23 import java.io.FileOutputStream;
24 import java.io.OutputStreamWriter;
25 import java.io.Writer;
26
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29
30 import org.apache.velocity.Template;
31 import org.apache.velocity.VelocityContext;
32 import org.apache.velocity.app.Velocity;
33 import org.apache.velocity.runtime.RuntimeSingleton;
34 import org.apache.velocity.runtime.log.NullLogChute;
35
36
37
38
39
40
41
42
43 public class InlineScopeVMTestCase extends BaseTestCase implements TemplateTestBase
44 {
45 public InlineScopeVMTestCase(String name)
46 {
47 super(name);
48 }
49
50 public void setUp()
51 throws Exception
52 {
53
54
55
56
57
58 Velocity.setProperty(
59 Velocity.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, "true");
60
61 Velocity.setProperty(
62 Velocity.VM_PERM_INLINE_LOCAL, "true");
63
64 Velocity.setProperty(
65 Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
66
67 Velocity.setProperty(
68 Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName());
69
70 Velocity.init();
71 }
72
73 public static Test suite ()
74 {
75 return new TestSuite(InlineScopeVMTestCase.class);
76 }
77
78
79
80
81 public void testInlineScopeVM ()
82 throws Exception
83 {
84 assureResultsDirectoryExists(RESULT_DIR);
85
86
87
88
89
90
91 Template template2 = RuntimeSingleton.getTemplate(
92 getFileName(null, "vm_test2", TMPL_FILE_EXT));
93
94 Template template1 = RuntimeSingleton.getTemplate(
95 getFileName(null, "vm_test1", TMPL_FILE_EXT));
96
97 FileOutputStream fos1 =
98 new FileOutputStream (
99 getFileName(RESULT_DIR, "vm_test1", RESULT_FILE_EXT));
100
101 FileOutputStream fos2 =
102 new FileOutputStream (
103 getFileName(RESULT_DIR, "vm_test2", RESULT_FILE_EXT));
104
105 Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
106 Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
107
108
109
110
111
112 VelocityContext context = new VelocityContext();
113
114 template1.merge(context, writer1);
115 writer1.flush();
116 writer1.close();
117
118 template2.merge(context, writer2);
119 writer2.flush();
120 writer2.close();
121
122 if (!isMatch(RESULT_DIR,COMPARE_DIR,"vm_test1",
123 RESULT_FILE_EXT,CMP_FILE_EXT) ||
124 !isMatch(RESULT_DIR,COMPARE_DIR,"vm_test2",
125 RESULT_FILE_EXT,CMP_FILE_EXT))
126 {
127 fail("Output incorrect.");
128 }
129 }
130 }