01: package org.apache.velocity.test;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: * This class tests strange Velocimacro issues.
34: *
35: * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
36: * @version $Id: VelocimacroTestCase.java 477002 2006-11-20 01:07:43Z henning $
37: */
38: public class VelocimacroTestCase extends TestCase {
39: private String template1 = "#macro(foo $a)$a#end #macro(bar $b)#foo($b)#end #foreach($i in [1..3])#bar($i)#end";
40: private String result1 = " 123";
41:
42: public VelocimacroTestCase(String name) {
43: super (name);
44: }
45:
46: public void setUp() throws Exception {
47: /*
48: * setup local scope for templates
49: */
50: Velocity.setProperty(Velocity.VM_PERM_INLINE_LOCAL,
51: Boolean.TRUE);
52:
53: Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS,
54: NullLogChute.class.getName());
55:
56: Velocity.init();
57: }
58:
59: public static Test suite() {
60: return new TestSuite(VelocimacroTestCase.class);
61: }
62:
63: /**
64: * Runs the test.
65: */
66: public void testVelociMacro() throws Exception {
67: VelocityContext context = new VelocityContext();
68:
69: StringWriter writer = new StringWriter();
70: Velocity.evaluate(context, writer, "vm_chain1", template1);
71:
72: String out = writer.toString();
73:
74: if (!result1.equals(out)) {
75: fail("output incorrect.");
76: }
77: }
78: }
|