KickJava   Java API By Example, From Geeks To Geeks.

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


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 is intended to test the app.Velocity.java class.
39  *
40  * @author <a HREF="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
41  * @author <a HREF="mailto:jon@latchkey.com">Jon S. Stevens</a>
42  * @version $Id: VelocityAppTestCase.java,v 1.3.14.1 2004/03/03 23:23:04 geirm Exp $
43  */

44 public class VelocityAppTestCase extends BaseTestCase implements TemplateTestBase
45 {
46     private StringWriter JavaDoc compare1 = new StringWriter JavaDoc();
47     private String JavaDoc input1 = "My name is $name -> $Floog";
48     private String JavaDoc result1 = "My name is jason -> floogie woogie";
49
50     public VelocityAppTestCase()
51     {
52         super("VelocityAppTestCase");
53
54         try
55         {
56             Velocity.setProperty(
57                Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
58             
59             Velocity.init();
60         }
61         catch (Exception JavaDoc e)
62         {
63             System.err.println("Cannot setup VelocityAppTestCase!");
64             e.printStackTrace();
65             System.exit(1);
66         }
67     }
68
69     public static junit.framework.Test suite()
70     {
71         return new VelocityAppTestCase();
72     }
73
74     /**
75      * Runs the test.
76      */

77     public void runTest ()
78     {
79         VelocityContext context = new VelocityContext();
80         context.put("name", "jason");
81         context.put("Floog", "floogie woogie");
82
83         try
84         {
85             Velocity.evaluate(context, compare1, "evaltest", input1);
86
87 /*
88             FIXME: Not tested right now.
89             
90             StringWriter result2 = new StringWriter();
91             Velocity.mergeTemplate("mergethis.vm", context, result2);
92
93             StringWriter result3 = new StringWriter();
94             Velocity.invokeVelocimacro("floog", "test", new String[2],
95                                         context, result3);
96 */

97             if (!result1.equals(compare1.toString()))
98             {
99                 fail("Output incorrect.");
100             }
101         }
102         catch (Exception JavaDoc e)
103         {
104             fail(e.getMessage());
105         }
106     }
107 }
108
Popular Tags