1 package org.apache.velocity.test.issues;
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 import org.apache.velocity.test.BaseTestCase;
36
37
38
39
40 public class Velocity285TestCase
41 extends BaseTestCase
42 {
43
44
45
46 private static final String CMP_FILE_EXT = "cmp";
47
48
49
50
51 private static final String RESULT_FILE_EXT = "res";
52
53
54
55
56 private static final String RESULTS_DIR = TEST_RESULT_DIR + "/issues/velocity-285";
57
58
59
60
61 private static final String TEMPLATE_DIR = TEST_COMPARE_DIR + "/issues/velocity-285/templates";
62
63
64
65
66 private static final String COMPARE_DIR = TEST_COMPARE_DIR + "/issues/velocity-285/compare";
67
68
69 public Velocity285TestCase(final String name)
70 throws Exception
71 {
72 super(name);
73 }
74
75 public static Test suite()
76 {
77 return new TestSuite(Velocity285TestCase.class);
78 }
79
80 public void setUp()
81 throws Exception
82 {
83
84 assureResultsDirectoryExists(RESULTS_DIR);
85
86 Velocity.addProperty(
87 Velocity.FILE_RESOURCE_LOADER_PATH, TEMPLATE_DIR);
88
89 Velocity.setProperty(
90 Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName());
91
92 Velocity.init();
93 }
94
95 public void testVelocity285()
96 throws Exception
97 {
98 executeTest("velocity285.vm");
99 }
100
101 protected Template executeTest(final String templateName)
102 throws Exception
103 {
104 Template template = RuntimeSingleton.getTemplate(templateName);
105
106 FileOutputStream fos =
107 new FileOutputStream (
108 getFileName(RESULTS_DIR, templateName, RESULT_FILE_EXT));
109
110 Writer writer = new BufferedWriter(new OutputStreamWriter(fos));
111
112 VelocityContext context = new VelocityContext();
113
114 template.merge(context, writer);
115 writer.flush();
116 writer.close();
117
118 if (!isMatch(RESULTS_DIR, COMPARE_DIR, templateName,
119 RESULT_FILE_EXT, CMP_FILE_EXT))
120 {
121 fail("Output incorrect for Template: " + templateName);
122 }
123
124 return template;
125 }
126 }