KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > test > VelocimacroTestCase


1 package org.apache.velocity.test;
2
3 /*
4  * Copyright 2001,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.BufferedWriter JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21 import java.io.OutputStreamWriter JavaDoc;
22 import java.io.StringWriter JavaDoc;
23
24 import java.util.Vector JavaDoc;
25
26 import org.apache.velocity.VelocityContext;
27
28 import org.apache.velocity.Template;
29 import org.apache.velocity.app.Velocity;
30 import org.apache.velocity.test.provider.TestProvider;
31 import org.apache.velocity.util.StringUtils;
32
33 import org.apache.velocity.app.Velocity;
34
35 import junit.framework.TestCase;
36
37 /**
38  * This class tests strange Velocimacro issues.
39  *
40  * @author <a HREF="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
41  * @version $Id: VelocimacroTestCase.java,v 1.1.10.1 2004/03/03 23:23:04 geirm Exp $
42  */

43 public class VelocimacroTestCase extends TestCase
44 {
45     private String JavaDoc template1 = "#macro(foo $a)$a#end #macro(bar $b)#foo($b)#end #foreach($i in [1..3])#bar($i)#end";
46     private String JavaDoc result1 = " 123";
47     
48     public VelocimacroTestCase()
49     {
50         super("VelocimacroTestCase");
51
52         try
53         {
54             /*
55              * setup local scope for templates
56              */

57             Velocity.setProperty( Velocity.VM_PERM_INLINE_LOCAL, Boolean.TRUE);
58             Velocity.init();
59         }
60         catch (Exception JavaDoc e)
61         {
62             System.err.println("Cannot setup VelocimacroTestCase!");
63             System.exit(1);
64         }
65     }
66
67     public static junit.framework.Test suite()
68     {
69         return new VelocimacroTestCase();
70     }
71
72     /**
73      * Runs the test.
74      */

75     public void runTest ()
76     {
77         VelocityContext context = new VelocityContext();
78
79         try
80         {
81             StringWriter JavaDoc writer = new StringWriter JavaDoc();
82             Velocity.evaluate(context, writer, "vm_chain1", template1);
83
84             String JavaDoc out = writer.toString();
85
86             if( !result1.equals( out ) )
87             {
88                 fail("output incorrect.");
89             }
90         }
91         catch (Exception JavaDoc e)
92         {
93             fail(e.getMessage());
94         }
95     }
96 }
97
Popular Tags