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.TestCase;
26 import junit.framework.TestSuite;
27
28 import org.apache.velocity.VelocityContext;
29 import org.apache.velocity.app.Velocity;
30 import org.apache.velocity.runtime.log.NullLogChute;
31
32
33
34
35
36
37
38 public class VelocimacroTestCase extends TestCase
39 {
40 private String template1 = "#macro(foo $a)$a#end #macro(bar $b)#foo($b)#end #foreach($i in [1..3])#bar($i)#end";
41 private String result1 = " 123";
42
43 public VelocimacroTestCase(String name)
44 {
45 super(name);
46 }
47
48 public void setUp()
49 throws Exception
50 {
51
52
53
54 Velocity.setProperty( Velocity.VM_PERM_INLINE_LOCAL, Boolean.TRUE);
55
56 Velocity.setProperty(
57 Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, NullLogChute.class.getName());
58
59 Velocity.init();
60 }
61
62 public static Test suite()
63 {
64 return new TestSuite(VelocimacroTestCase.class);
65 }
66
67
68
69
70 public void testVelociMacro ()
71 throws Exception
72 {
73 VelocityContext context = new VelocityContext();
74
75 StringWriter writer = new StringWriter();
76 Velocity.evaluate(context, writer, "vm_chain1", template1);
77
78 String out = writer.toString();
79
80 if( !result1.equals( out ) )
81 {
82 fail("output incorrect.");
83 }
84 }
85 }