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.FileInputStream;
23: import java.util.Properties;
24:
25: import junit.framework.TestSuite;
26:
27: import org.apache.velocity.app.Velocity;
28: import org.apache.velocity.runtime.log.NullLogChute;
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 477002 2006-11-20 01:07:43Z henning $
38: */
39: public class TemplateTestSuite extends TestSuite implements
40: TemplateTestBase {
41: private Properties testProperties;
42:
43: /**
44: * Creates an instace of the Apache Velocity test suite.
45: */
46: public TemplateTestSuite() {
47: try {
48: Velocity.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,
49: FILE_RESOURCE_LOADER_PATH);
50:
51: Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS,
52: NullLogChute.class.getName());
53:
54: Velocity.init();
55:
56: testProperties = new Properties();
57: testProperties.load(new FileInputStream(
58: TEST_CASE_PROPERTIES));
59: } catch (Exception e) {
60: System.err.println("Cannot setup TemplateTestSuite!");
61: e.printStackTrace();
62: System.exit(1);
63: }
64:
65: addTemplateTestCases();
66: }
67:
68: /**
69: * Adds the template test cases to run to this test suite. Template test
70: * cases are listed in the <code>TEST_CASE_PROPERTIES</code> file.
71: */
72: private void addTemplateTestCases() {
73: String template;
74: for (int i = 1;; i++) {
75: template = testProperties
76: .getProperty(getTemplateTestKey(i));
77:
78: if (template != null) {
79: System.out.println("Adding TemplateTestCase : "
80: + template);
81: addTest(new TemplateTestCase(template));
82: } else {
83: // Assume we're done adding template test cases.
84: break;
85: }
86: }
87: }
88:
89: /**
90: * Macro which returns the properties file key for the specified template
91: * test number.
92: *
93: * @param nbr The template test number to return a property key for.
94: * @return The property key.
95: */
96: private static final String getTemplateTestKey(int nbr) {
97: return ("test.template." + nbr);
98: }
99: }
|