01: package org.apache.turbine;
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.File;
23:
24: import javax.servlet.ServletConfig;
25: import javax.servlet.ServletContext;
26:
27: import junit.framework.Test;
28: import junit.framework.TestSuite;
29:
30: import org.apache.turbine.Turbine;
31: import org.apache.turbine.test.BaseTestCase;
32: import org.apache.turbine.util.TurbineConfig;
33: import org.apache.turbine.util.TurbineXmlConfig;
34:
35: /**
36: * This testcase verifies that TurbineConfig can be used to startup Turbine in a non
37: * servlet environment properly.
38: *
39: * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
40: * @version $Id: TurbineConfigTest.java 534527 2007-05-02 16:10:59Z tv $
41: */
42: public class TurbineConfigTest extends BaseTestCase {
43: private static TurbineConfig tc = null;
44: private static TurbineXmlConfig txc = null;
45:
46: public TurbineConfigTest(String name) throws Exception {
47: super (name);
48: }
49:
50: public static Test suite() {
51: return new TestSuite(TurbineConfigTest.class);
52: }
53:
54: public void testTurbineConfigWithPropertiesFile() throws Exception {
55: String value = new File("/conf/test/TemplateService.properties")
56: .getPath();
57: tc = new TurbineConfig(".", value);
58:
59: ServletConfig config = (ServletConfig) tc;
60: ServletContext context = config.getServletContext();
61:
62: String confFile = Turbine.findInitParameter(context, config,
63: TurbineConfig.PROPERTIES_PATH_KEY, null);
64: assertEquals(value, confFile);
65: }
66:
67: public void testTurbineXmlConfigWithConfigurationFile()
68: throws Exception {
69: String value = new File("/conf/test/TurbineConfiguration.xml")
70: .getPath();
71: txc = new TurbineXmlConfig(".", value);
72:
73: ServletConfig config = (ServletConfig) txc;
74: ServletContext context = config.getServletContext();
75:
76: String confFile = Turbine.findInitParameter(context, config,
77: TurbineConfig.CONFIGURATION_PATH_KEY, null);
78: assertEquals(value, confFile);
79: }
80: }
|