epugh       2003/06/06 15:08:09

  Modified:    src/java/org/apache/turbine/util TurbineConfig.java
  Added:       conf/test TurbineConfiguration.xml TurbineResources.xml
               src/test/org/apache/turbine TurbineConfigTest.java
                        ConfigurationTest.java
  Log:
  Changed TurbineConfig to take in a .xml file that is assumed to be a
  ConfigurationFactory xml file.  Added testcases and support files
  for testcases.
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-2/conf/test/TurbineConfiguration.xml
  
  Index: TurbineConfiguration.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  
  <configuration>
    <dom4j className="org.apache.commons.configuration.DOM4JConfiguration" 
fileName="/conf/test/TurbineResources.xml"/>
    <properties className="org.apache.commons.configuration.PropertiesConfiguration" 
fileName="/conf/test/TemplateService.properties"/>
  </configuration>
  
    
    
  
  
  
  
  
  
  1.1                  jakarta-turbine-2/conf/test/TurbineResources.xml
  
  Index: TurbineResources.xml
  ===================================================================
  <XmlConfiguration>
        <module>
                <cache>true</cache>
        </module>
  </XmlConfiguration>
  
  
  
  1.1                  
jakarta-turbine-2/src/test/org/apache/turbine/TurbineConfigTest.java
  
  Index: TurbineConfigTest.java
  ===================================================================
  package org.apache.turbine;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import javax.servlet.*;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.turbine.Turbine;
  import org.apache.turbine.util.TurbineConfig;
  
  /**
   * This testcase verifies that TurbineConfig can be used to startup Turbine in a non
   * servlet environment properly.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
   *
   * @version $Id: TurbineConfigTest.java,v 1.1 2003/06/06 22:08:09 epugh Exp $
   */
  public class TurbineConfigTest
      extends TestCase
  {
      private static TurbineConfig tc = null;
  
      public TurbineConfigTest(String name)
      {
          super(name);
               
          
      }
  
      public static Test suite()
      {
          return new TestSuite(TurbineConfigTest.class);
      }
  
      public void testTurbineConfigWithPropertiesFile() throws Exception {
          String value = "/conf/test/TemplateService.properties";
          tc = new TurbineConfig(".", value);
          ServletContext context = tc.getServletContext();
          ServletConfig config = (ServletConfig)tc;
          String confFile= Turbine.findInitParameter(context, config, 
                  TurbineConfig.PROPERTIES_PATH_KEY, 
                  null);
          assertEquals(value,confFile);
          
      }
      
      public void testTurbineConfigWithconfigurationFile() throws Exception {
              String value = "/conf/test/TurbineConfiguration.xml";
              tc = new TurbineConfig(".", value);
              ServletContext context = tc.getServletContext();
              ServletConfig config = (ServletConfig)tc;
              String confFile= Turbine.findInitParameter(context, config, 
                      TurbineConfig.CONFIGURATION_PATH_KEY, 
                      null);
              assertEquals(value,confFile);
          
          }
  
      
  }
  
  
  
  1.1                  
jakarta-turbine-2/src/test/org/apache/turbine/ConfigurationTest.java
  
  Index: ConfigurationTest.java
  ===================================================================
  package org.apache.turbine;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import javax.servlet.*;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.turbine.Turbine;
  import org.apache.turbine.util.TurbineConfig;
  import org.apache.commons.configuration.Configuration;
  import org.apache.commons.configuration.ConfigurationFactory;
  import org.apache.commons.configuration.PropertiesConfiguration;
  
  /**
   * Tests that the ConfigurationFactory and regular old properties methods both work.
   * Verify the overriding of properties.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
   * 
   * @version $Id: ConfigurationTest.java,v 1.1 2003/06/06 22:08:09 epugh Exp $
   */
  public class ConfigurationTest
      extends TestCase
  {
      private static TurbineConfig tc = null;
  
      public ConfigurationTest(String name)
      {
          super(name);
       
          
          
      }
  
      public static Test suite()
      {
          return new TestSuite(ConfigurationTest.class);
      }
  
      
      
      public void testCreateTurbineWithConfigurationXML() throws Exception
         {
             tc = new TurbineConfig(".", "/conf/test/TurbineConfiguration.xml");
             tc.initialize();
           
             Configuration configuration = Turbine.getConfiguration();
             assertTrue("Make sure we have values", !configuration.isEmpty());
             
             // overridden value
             String key = "module.cache";
             assertEquals("Read a config value " + key + ", receieved:" + 
configuration.getString(key), "true", configuration.getString(key));
             
             // non overridden value
             key = "scheduledjob.cache.size";
             assertEquals("Read a config value " + key + ", receieved:" + 
configuration.getString(key), "10", configuration.getString(key));
  
  
         }
         
   
  }
  
  
  
  1.14      +18 -11    
jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineConfig.java
  
  Index: TurbineConfig.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/TurbineConfig.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TurbineConfig.java        2 Jun 2003 10:24:46 -0000       1.13
  +++ TurbineConfig.java        6 Jun 2003 22:08:09 -0000       1.14
  @@ -109,14 +109,13 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
    * @version $Id$
    */
  -public class TurbineConfig
  -        implements ServletConfig, ServletContext, Initializable, Disposable
  +public class TurbineConfig implements ServletConfig, ServletContext, Initializable, 
Disposable
   {
       /**
        * Servlet initialization parameter name for the path to
        * TurbineConfiguration.xml file used by Turbine
        */
  -    public static final String CONFIGURATION_PATH_KEY = "configuration";    
  +    public static final String CONFIGURATION_PATH_KEY = "configuration";
   
       /**
        * Servlet initialization parameter name for the path to
  @@ -128,8 +127,7 @@
        * Default value of TurbineResources.properties file path
        * (<code>/WEB-INF/conf/TurbineResources.properties</code>).
        */
  -    public static final String PROPERTIES_PATH_DEFAULT =
  -            "/WEB-INF/conf/TurbineResources.properties";
  +    public static final String PROPERTIES_PATH_DEFAULT = 
"/WEB-INF/conf/TurbineResources.properties";
   
       /** Filenames are looked up in this directory. */
       private File root;
  @@ -182,12 +180,22 @@
        * Turbine easiliy in the common setups.
        *
        * @param path The web application root (i.e. the path for file lookup).
  -     * @param properties the relative path to TurbineResources.properties file
  +     * @param properties the relative path to setup file.  Either 
  +     * TurbineResources.properties or TurbineConfiguration.xml.  If the file
  +     * ends in .xml, then we assume taht it is a ConfigurationFactory config
  +     * file.  Otherwise we assume it is a standard TurbineResources.propeties file.
        */
       public TurbineConfig(String path, String properties)
       {
           this(path, new HashMap(1));
  -        initParams.put(PROPERTIES_PATH_KEY, properties);
  +        if (properties.toLowerCase().endsWith(".xml"))
  +        {
  +            initParams.put(CONFIGURATION_PATH_KEY, properties);
  +        }
  +        else
  +        {
  +            initParams.put(PROPERTIES_PATH_KEY, properties);
  +        }
       }
   
       /**
  @@ -271,7 +279,7 @@
   
           if (f.exists())
           {
  -          result = f.getPath();
  +            result = f.getPath();
           }
           else
           {
  @@ -335,8 +343,7 @@
        * @return a URL pointing to the resource
        * @exception MalformedURLException
        */
  -    public URL getResource(String s)
  -            throws MalformedURLException
  +    public URL getResource(String s) throws MalformedURLException
       {
           return new URL("file://" + getRealPath(s));
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to