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 junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.velocity.app.Velocity;
26 import org.apache.velocity.runtime.RuntimeConstants;
27 import org.apache.velocity.test.misc.TestLogChute;
28 import org.apache.velocity.Template;
29 import org.apache.velocity.VelocityContext;
30
31 import java.io.*;
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
66
67
68 public MacroForwardDefineTestCase(String name)
69 {
70 super(name);
71 }
72
73 public void setUp()
74 throws Exception
75 {
76 assureResultsDirectoryExists(RESULTS_DIR);
77
78
79 Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER,"file");
80 Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH );
81 Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID,"true");
82
83
84 logger = new TestLogChute();
85 logger.off();
86 Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,logger);
87 Velocity.setProperty(TestLogChute.TEST_LOGGER_LEVEL, "debug");
88 Velocity.init();
89 }
90
91 public static Test suite()
92 {
93 return new TestSuite(MacroForwardDefineTestCase.class);
94 }
95
96 public void testLogResult()
97 throws Exception
98 {
99 VelocityContext context = new VelocityContext();
100 Template template = Velocity.getTemplate("macros.vm");
101
102
103 logger.on();
104 template.merge(context, new StringWriter());
105 logger.off();
106
107 String resultLog = logger.getLog();
108 if ( !isMatch(resultLog, COMPARE_DIR, "velocity.log", "cmp"))
109 {
110 String compare = getFileContents(COMPARE_DIR, "velocity.log", CMP_FILE_EXT);
111
112 String msg = "Log output was incorrect\n"+
113 "-----Result-----\n"+ resultLog +
114 "----Expected----\n"+ compare +
115 "----------------";
116
117 fail(msg);
118 }
119 }
120 }