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 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
68
69
70 public MultipleFileResourcePathTestCase(String name)
71 {
72 super(name);
73 }
74
75 public static Test suite ()
76 {
77 return new TestSuite(MultipleFileResourcePathTestCase.class);
78 }
79
80 public void setUp()
81 throws Exception
82 {
83 assureResultsDirectoryExists(RESULTS_DIR);
84
85 Velocity.addProperty(
86 Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH1);
87
88 Velocity.addProperty(
89 Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH2);
90
91 Velocity.setProperty(
92 Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName());
93
94 Velocity.init();
95 }
96
97
98
99
100 public void testMultipleFileResources ()
101 throws Exception
102 {
103 Template template1 = RuntimeSingleton.getTemplate(
104 getFileName(null, "path1", TMPL_FILE_EXT));
105
106 Template template2 = RuntimeSingleton.getTemplate(
107 getFileName(null, "path2", TMPL_FILE_EXT));
108
109 FileOutputStream fos1 =
110 new FileOutputStream (
111 getFileName(RESULTS_DIR, "path1", RESULT_FILE_EXT));
112
113 FileOutputStream fos2 =
114 new FileOutputStream (
115 getFileName(RESULTS_DIR, "path2", RESULT_FILE_EXT));
116
117 Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
118 Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
119
120
121
122
123
124 VelocityContext context = new VelocityContext();
125
126 template1.merge(context, writer1);
127 writer1.flush();
128 writer1.close();
129
130 template2.merge(context, writer2);
131 writer2.flush();
132 writer2.close();
133
134 if (!isMatch(RESULTS_DIR, COMPARE_DIR, "path1",
135 RESULT_FILE_EXT, CMP_FILE_EXT) ||
136 !isMatch(RESULTS_DIR, COMPARE_DIR, "path2",
137 RESULT_FILE_EXT, CMP_FILE_EXT))
138 {
139 fail("Output incorrect.");
140 }
141 }
142 }