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