001 package 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 023 024 import org.apache.commons.configuration.Configuration; 025 import org.apache.turbine.test.BaseTestCase; 026 import org.apache.turbine.util.TurbineConfig; 027 import org.apache.turbine.util.TurbineXmlConfig; 028 029 /** 030 * Tests that the ConfigurationFactory and regular old properties methods both work. 031 * Verify the overriding of properties. 032 * 033 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a> 034 * @version $Id: ConfigurationTest.java 615328 2008-01-25 20:25:05Z tv $ 035 */ 036 public class ConfigurationTest extends BaseTestCase 037 { 038 public static final String SERVICE_PREFIX = "services."; 039 040 /** 041 * A <code>Service</code> property determining its implementing 042 * class name . 043 */ 044 public static final String CLASSNAME_SUFFIX = ".classname"; 045 046 private static TurbineConfig tc = null; 047 private static TurbineXmlConfig txc = null; 048 049 public ConfigurationTest(String name) throws Exception 050 { 051 super(name); 052 } 053 054 public void testCreateTurbineWithConfigurationXML() throws Exception 055 { 056 txc = new TurbineXmlConfig(".", "/conf/test/TurbineConfiguration.xml"); 057 058 try 059 { 060 txc.initialize(); 061 062 Configuration configuration = Turbine.getConfiguration(); 063 assertNotNull("No Configuration Object found!", configuration); 064 assertFalse("Make sure we have values", configuration.isEmpty()); 065 066 // overridden value 067 String key = "module.cache"; 068 assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "true", configuration.getString(key)); 069 070 // non overridden value 071 key = "scheduledjob.cache.size"; 072 assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key)); 073 } 074 catch (Exception e) 075 { 076 throw e; 077 } 078 finally 079 { 080 txc.dispose(); 081 } 082 } 083 084 public void testCreateTurbineWithConfiguration() throws Exception 085 { 086 tc = new TurbineConfig(".", "/conf/test/TemplateService.properties"); 087 088 try 089 { 090 tc.initialize(); 091 092 Configuration configuration = Turbine.getConfiguration(); 093 assertNotNull("No Configuration Object found!", configuration); 094 assertFalse("Make sure we have values", configuration.isEmpty()); 095 096 String key = "scheduledjob.cache.size"; 097 assertEquals("Read a config value " + key + ", received:" + configuration.getString(key), "10", configuration.getString(key)); 098 } 099 catch (Exception e) 100 { 101 throw e; 102 } 103 finally 104 { 105 tc.dispose(); 106 } 107 } 108 109 }