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.StringWriter;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import org.apache.velocity.Template;
28 import org.apache.velocity.VelocityContext;
29 import org.apache.velocity.app.VelocityEngine;
30 import org.apache.velocity.runtime.RuntimeConstants;
31 import org.apache.velocity.test.misc.TestLogChute;
32
33
34
35
36
37
38
39
40
41 public class MacroForwardDefineTestCase
42 extends BaseTestCase
43 {
44
45
46
47
48 private final static String FILE_RESOURCE_LOADER_PATH = TEST_COMPARE_DIR + "/macroforwarddefine";
49
50
51
52
53 private static final String RESULTS_DIR = TEST_RESULT_DIR + "/macroforwarddefine";
54
55
56
57
58 private static final String COMPARE_DIR = TEST_COMPARE_DIR + "/macroforwarddefine/compare";
59
60
61
62
63 private TestLogChute logger = new TestLogChute();
64
65 VelocityEngine engine;
66
67
68
69
70 public MacroForwardDefineTestCase(String name)
71 {
72 super(name);
73 }
74
75 public void setUp()
76 throws Exception
77 {
78 assureResultsDirectoryExists(RESULTS_DIR);
79
80 engine = new VelocityEngine();
81
82
83 engine.setProperty(RuntimeConstants.RESOURCE_LOADER,"file");
84 engine.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH );
85 engine.setProperty(RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID,"true");
86
87
88 logger = new TestLogChute(true, false);
89 engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,logger);
90 engine.setProperty(TestLogChute.TEST_LOGGER_LEVEL, "debug");
91 engine.init();
92 }
93
94 public static Test suite()
95 {
96 return new TestSuite(MacroForwardDefineTestCase.class);
97 }
98
99 public void testLogResult()
100 throws Exception
101 {
102 VelocityContext context = new VelocityContext();
103 Template template = engine.getTemplate("macros.vm");
104
105
106 logger.startCapture();
107 template.merge(context, new StringWriter());
108 logger.stopCapture();
109
110 String resultLog = logger.getLog();
111 if ( !isMatch(resultLog, COMPARE_DIR, "velocity.log", "cmp"))
112 {
113 String compare = getFileContents(COMPARE_DIR, "velocity.log", CMP_FILE_EXT);
114
115 String msg = "Log output was incorrect\n"+
116 "-----Result-----\n"+ resultLog +
117 "----Expected----\n"+ compare +
118 "----------------";
119
120 fail(msg);
121 }
122 }
123 }