KickJava   Java API By Example, From Geeks To Geeks.

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


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.FileInputStream JavaDoc;
20
21 import java.util.Properties JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import org.apache.velocity.app.Velocity;
27
28 import junit.framework.TestSuite;
29
30 /**
31  * Test suite for Templates.
32  *
33  * @author <a HREF="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
34  * @author <a HREF="mailto:jvanzyl@apache.org">Jason van Zyl</a>
35  * @author <a HREF="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
36  * @author <a HREF="mailto:jon@latchkey.com">Jon S. Stevens</a>
37  * @version $Id: TemplateTestSuite.java,v 1.6.8.1 2004/03/03 23:23:04 geirm Exp $
38  */

39 public class TemplateTestSuite extends TestSuite implements TemplateTestBase
40 {
41     private Properties JavaDoc testProperties;
42
43     /**
44      * Creates an instace of the Apache Velocity test suite.
45      */

46     public TemplateTestSuite()
47     {
48         try
49         {
50             Velocity.setProperty(
51                 Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
52             
53             Velocity.setProperty(Velocity.RUNTIME_LOG_ERROR_STACKTRACE, "true");
54             Velocity.setProperty(Velocity.RUNTIME_LOG_WARN_STACKTRACE, "true");
55             Velocity.setProperty(Velocity.RUNTIME_LOG_INFO_STACKTRACE, "true");
56
57             Velocity.init();
58             
59             testProperties = new Properties JavaDoc();
60             testProperties.load(new FileInputStream JavaDoc(TEST_CASE_PROPERTIES));
61         }
62         catch (Exception JavaDoc e)
63         {
64             System.err.println("Cannot setup TemplateTestSuite!");
65             e.printStackTrace();
66             System.exit(1);
67         }
68
69         addTemplateTestCases();
70     }
71
72     /**
73      * Adds the template test cases to run to this test suite. Template test
74      * cases are listed in the <code>TEST_CASE_PROPERTIES</code> file.
75      */

76     private void addTemplateTestCases()
77     {
78         String JavaDoc template;
79         for (int i = 1 ;; i++)
80         {
81             template = testProperties.getProperty(getTemplateTestKey(i));
82
83             if (template != null)
84             {
85                 System.out.println("Adding TemplateTestCase : " + template);
86                 addTest(new TemplateTestCase(template));
87             }
88             else
89             {
90                 // Assume we're done adding template test cases.
91
break;
92             }
93         }
94     }
95
96     /**
97      * Macro which returns the properties file key for the specified template
98      * test number.
99      *
100      * @param nbr The template test number to return a property key for.
101      * @return The property key.
102      */

103     private static final String JavaDoc getTemplateTestKey(int nbr)
104     {
105         return ("test.template." + nbr);
106     }
107 }
108
Popular Tags