001package org.apache.turbine; 002 003 004/* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023import static org.junit.Assert.assertEquals; 024 025import java.io.File; 026 027import javax.servlet.ServletConfig; 028import javax.servlet.ServletContext; 029 030import org.apache.turbine.test.BaseTestCase; 031import org.apache.turbine.util.TurbineConfig; 032import org.apache.turbine.util.TurbineXmlConfig; 033import org.junit.Test; 034 035/** 036 * This testcase verifies that TurbineConfig can be used to startup Turbine in a non 037 * servlet environment properly. 038 * 039 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a> 040 * @version $Id: TurbineConfigTest.java 1606111 2014-06-27 14:46:47Z gk $ 041 */ 042public class TurbineConfigTest 043 extends BaseTestCase 044{ 045 private static TurbineConfig tc = null; 046 private static TurbineXmlConfig txc = null; 047 048 @Test 049 public void testTurbineConfigWithPropertiesFile() throws Exception 050 { 051 String value = new File("/conf/test/TemplateService.properties").getPath(); 052 tc = new TurbineConfig(".", value); 053 Turbine turbine = new Turbine(); 054 055 ServletConfig config = tc; 056 ServletContext context = config.getServletContext(); 057 058 String confFile= turbine.findInitParameter(context, config, 059 TurbineConfig.PROPERTIES_PATH_KEY, 060 null); 061 assertEquals(value, confFile); 062 } 063 @Test 064 public void testTurbineXmlConfigWithConfigurationFile() throws Exception 065 { 066 String value = new File("/conf/test/TurbineConfiguration.xml").getPath(); 067 txc = new TurbineXmlConfig(".", value); 068 Turbine turbine = new Turbine(); 069 070 ServletConfig config = txc; 071 ServletContext context = config.getServletContext(); 072 073 String confFile= turbine.findInitParameter(context, config, 074 TurbineConfig.CONFIGURATION_PATH_KEY, 075 null); 076 assertEquals(value, confFile); 077 } 078}