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.VelocityEngine;
33 import org.apache.velocity.runtime.RuntimeConstants;
34 import org.apache.velocity.test.misc.TestLogChute;
35
36
37
38
39
40
41
42 public class MultipleFileResourcePathTestCase extends BaseTestCase
43 {
44
45
46
47
48
49 private final static String FILE_RESOURCE_LOADER_PATH1 = TEST_COMPARE_DIR + "/multi/path1";
50
51
52
53
54
55 private final static String FILE_RESOURCE_LOADER_PATH2 = TEST_COMPARE_DIR + "/multi/path2";
56
57
58
59
60 private static final String RESULTS_DIR = TEST_RESULT_DIR + "/multi";
61
62
63
64
65 private static final String COMPARE_DIR = TEST_COMPARE_DIR + "/multi/compare";
66
67 VelocityEngine engine;
68
69
70
71
72 public MultipleFileResourcePathTestCase(String name)
73 {
74 super(name);
75 }
76
77 public static Test suite ()
78 {
79 return new TestSuite(MultipleFileResourcePathTestCase.class);
80 }
81
82 public void setUp()
83 throws Exception
84 {
85 assureResultsDirectoryExists(RESULTS_DIR);
86
87 engine = new VelocityEngine();
88
89 engine.addProperty(
90 RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH1);
91
92 engine.addProperty(
93 RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH2);
94
95 engine.setProperty(
96 RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, TestLogChute.class.getName());
97
98 engine.init();
99 }
100
101
102
103
104 public void testMultipleFileResources ()
105 throws Exception
106 {
107 Template template1 = engine.getTemplate(
108 getFileName(null, "path1", TMPL_FILE_EXT));
109
110 Template template2 = engine.getTemplate(
111 getFileName(null, "path2", TMPL_FILE_EXT));
112
113 FileOutputStream fos1 =
114 new FileOutputStream (
115 getFileName(RESULTS_DIR, "path1", RESULT_FILE_EXT));
116
117 FileOutputStream fos2 =
118 new FileOutputStream (
119 getFileName(RESULTS_DIR, "path2", RESULT_FILE_EXT));
120
121 Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
122 Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
123
124
125
126
127
128 VelocityContext context = new VelocityContext();
129
130 template1.merge(context, writer1);
131 writer1.flush();
132 writer1.close();
133
134 template2.merge(context, writer2);
135 writer2.flush();
136 writer2.close();
137
138 if (!isMatch(RESULTS_DIR, COMPARE_DIR, "path1",
139 RESULT_FILE_EXT, CMP_FILE_EXT) ||
140 !isMatch(RESULTS_DIR, COMPARE_DIR, "path2",
141 RESULT_FILE_EXT, CMP_FILE_EXT))
142 {
143 fail("Output incorrect.");
144 }
145 }
146 }