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.VelocityContext;
28 import org.apache.velocity.app.Velocity;
29 import org.apache.velocity.test.misc.TestLogChute;
30
31
32
33
34
35
36
37
38 public class VelocityAppTestCase extends BaseTestCase implements TemplateTestBase
39 {
40 private StringWriter compare1 = new StringWriter();
41 private String input1 = "My name is $name -> $Floog";
42 private String result1 = "My name is jason -> floogie woogie";
43
44 public VelocityAppTestCase(String name)
45 {
46 super(name);
47 }
48
49 public void setUp()
50 throws Exception
51 {
52 Velocity.setProperty(
53 Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
54
55 Velocity.setProperty(
56 Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, TestLogChute.class.getName());
57
58 Velocity.init();
59 }
60
61 public static Test suite()
62 {
63 return new TestSuite(VelocityAppTestCase.class);
64 }
65
66
67
68
69 public void testVelocityApp ()
70 throws Exception
71 {
72 VelocityContext context = new VelocityContext();
73 context.put("name", "jason");
74 context.put("Floog", "floogie woogie");
75
76 Velocity.evaluate(context, compare1, "evaltest", input1);
77
78
79
80
81
82
83
84
85
86
87
88 if (!result1.equals(compare1.toString()))
89 {
90 fail("Output incorrect.");
91 }
92 }
93 }