You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2003/10/13 22:28:40 UTC

cvs commit: jakarta-cactus/framework/src/test/share/org/apache/cactus TestAll.java

vmassol     2003/10/13 13:28:40

  Modified:    framework build.xml
               .        build.properties.sample
               samples/servlet/src/scripts/j2ee12 build.properties
               samples/servlet/src/scripts/j2ee13 build.properties
               framework/src/java/share/org/apache/cactus/configuration
                        BaseConfiguration.java
               framework/src/test/share/org/apache/cactus TestAll.java
  Added:       framework logging.properties
  Log:
  Added support for a cactus logging configuration file.
  
  Revision  Changes    Path
  1.69      +15 -11    jakarta-cactus/framework/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/build.xml,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- build.xml	12 Oct 2003 19:59:47 -0000	1.68
  +++ build.xml	13 Oct 2003 20:28:39 -0000	1.69
  @@ -394,22 +394,26 @@
         <path refid="project.classpath"/>
       </path>
   
  +	<pathconvert property="target.dir.normalized" dirsep="/">
  +	  <path>
  +	    <pathelement location="${target.dir}"/>
  +	  </path>
  +	</pathconvert>
  +	<copy todir="${target.dir}" filtering="on" 
  +		file="${base.dir}/logging.properties">
  +	  <filterset>
  +        <filter token="target.dir" value="${target.dir.normalized}"/>
  +      </filterset>
  +	</copy>
  +
     </target>
   
     <target name="test" depends="test.clover.prepare,test.main.prepare"
         description="Run the unit tests">
   
  -    <!-- Save all Ant properties to a file so that it can be read by the
  -         TestAll test suite. This is to allow passing system properties
  -         to the tests. This is useful for example to configure logging
  -         properties. For example, if you are using the JDK 1.4 and you 
  -         wish to pass your custom logging file, you can can:
  -           ant -Djava.util.logging.config.file=logging.properties test -->
  -    <echoproperties destfile="${target.dir}/test.properties"/>
  -
       <junit printsummary="yes" haltonfailure="yes" fork="yes">
  -      <sysproperty key="cactus.test.propertiesFile" 
  -          file="${target.dir}/test.properties"/>
  +      <sysproperty key="cactus.logging.config" 
  +          file="${target.dir}/logging.properties"/>
         <classpath>
           <path refid="test.class.path"/>
         </classpath>
  
  
  
  1.1                  jakarta-cactus/framework/logging.properties
  
  Index: logging.properties
  ===================================================================
  # -----------------------------------------------------------------------------
  # Logging properties
  # -----------------------------------------------------------------------------
  
  # Disable logging by default when running the tests. If you wish to use a 
  # logging subsystem, uncomment the line below. That will let Commons logging
  # decide automatically of a suitable logging system for you. For more info, see
  # http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/package-summary.html#package_description
  #org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
  
  # ---- JDK 1.4 logging properties
  
  # Following properties are useful if you're using the JDK 1.4 logging subsystem
  # and wish to output logs to the console. Comment the NoOpLog line above and
  # uncommment the following lines as needed.
  java.util.logging.config.file = @target.dir@/logging.properties
  handlers = java.util.logging.FileHandler,java.util.logging.ConsoleHandler
  java.util.logging.ConsoleHandler.level = FINEST
  java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  java.util.logging.FileHandler.pattern = test%u.log
  java.util.logging.FileHandler.limit = 50000
  java.util.logging.FileHandler.count = 1
  java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
  
  # If you want to provide finer grained logging, restrict the level for the 
  # specific package name. 
  # For example: org.apache.cactus.server.level = FINEST
  org.apache.cactus.level = FINEST
  
  
  
  1.85      +1 -30     jakarta-cactus/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/build.properties.sample,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- build.properties.sample	12 Oct 2003 19:59:47 -0000	1.84
  +++ build.properties.sample	13 Oct 2003 20:28:40 -0000	1.85
  @@ -177,32 +177,3 @@
   #jakarta.username = vmassol
   #scp = pscp
   #ssh = tortoisePlink
  -
  -# -----------------------------------------------------------------------------
  -# Logging properties
  -# -----------------------------------------------------------------------------
  -
  -# Disable logging by default when running the tests. If you wish to use a 
  -# logging subsystem, uncomment the line below. That will let Commons logging
  -# decide automatically of a suitable logging system for you. For more info, see
  -# http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/package-summary.html#package_description
  -org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
  -
  -# ---- JDK 1.4 logging properties
  -
  -# Following properties are useful if you're using the JDK 1.4 logging subsystem
  -# and wish to output logs to the console. Comment the NoOpLog line above and
  -# uncommment the following lines as needed.
  -java.util.logging.config.file=${basedir}/build.properties
  -handlers= java.util.logging.FileHandler,java.util.logging.ConsoleHandler
  -java.util.logging.ConsoleHandler.level = FINEST
  -java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  -java.util.logging.FileHandler.pattern = test%u.log
  -java.util.logging.FileHandler.limit = 50000
  -java.util.logging.FileHandler.count = 1
  -java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
  -
  -# If you want to provide finer grained logging, restrict the level for the 
  -# specific package name. 
  -# For example: org.apache.cactus.server.level = FINEST
  -org.apache.cactus.level = FINEST
  
  
  
  1.13      +1 -30     jakarta-cactus/samples/servlet/src/scripts/j2ee12/build.properties
  
  Index: build.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/samples/servlet/src/scripts/j2ee12/build.properties,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- build.properties	13 Oct 2003 05:43:41 -0000	1.12
  +++ build.properties	13 Oct 2003 20:28:40 -0000	1.13
  @@ -40,32 +40,3 @@
   #cactus.home.orion1x = c:/Apps/orion-1.6.0
   #cactus.home.orion2x = c:/Apps/orion-2.0.2
   #cactus.home.weblogic7x = c:/bea/weblogic700
  -
  -# -----------------------------------------------------------------------------
  -# Logging properties
  -# -----------------------------------------------------------------------------
  -
  -# Disable logging by default when running the tests. If you wish to use a 
  -# logging subsystem, uncomment the line below. That will let Commons logging
  -# decide automatically of a suitable logging system for you. For more info, see
  -# http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/package-summary.html#package_description
  -org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
  -
  -# ---- JDK 1.4 logging properties
  -
  -# Following properties are useful if you're using the JDK 1.4 logging subsystem
  -# and wish to output logs to the console. Comment the NoOpLog line above and
  -# uncommment the following lines as needed.
  -java.util.logging.config.file=${basedir}/build.properties
  -handlers= java.util.logging.FileHandler,java.util.logging.ConsoleHandler
  -java.util.logging.ConsoleHandler.level = FINEST
  -java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  -java.util.logging.FileHandler.pattern = test%u.log
  -java.util.logging.FileHandler.limit = 50000
  -java.util.logging.FileHandler.count = 1
  -java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
  -
  -# If you want to provide finer grained logging, restrict the level for the 
  -# specific package name. 
  -# For example: org.apache.cactus.server.level = FINEST
  -org.apache.cactus.level = FINEST
  
  
  
  1.12      +1 -29     jakarta-cactus/samples/servlet/src/scripts/j2ee13/build.properties
  
  Index: build.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/samples/servlet/src/scripts/j2ee13/build.properties,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.properties	13 Oct 2003 05:43:41 -0000	1.11
  +++ build.properties	13 Oct 2003 20:28:40 -0000	1.12
  @@ -47,31 +47,3 @@
   #cactus.home.jboss3x = c:/Apps/jboss-3.2.1
   #cactus.home.weblogic7x = c:/bea/weblogic700
   
  -# -----------------------------------------------------------------------------
  -# Logging properties
  -# -----------------------------------------------------------------------------
  -
  -# Disable logging by default when running the tests. If you wish to use a 
  -# logging subsystem, uncomment the line below. That will let Commons logging
  -# decide automatically of a suitable logging system for you. For more info, see
  -# http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/package-summary.html#package_description
  -org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
  -
  -# ---- JDK 1.4 logging properties
  -
  -# Following properties are useful if you're using the JDK 1.4 logging subsystem
  -# and wish to output logs to the console. Comment the NoOpLog line above and
  -# uncommment the following lines as needed.
  -java.util.logging.config.file=${basedir}/build.properties
  -handlers= java.util.logging.FileHandler,java.util.logging.ConsoleHandler
  -java.util.logging.ConsoleHandler.level = FINEST
  -java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  -java.util.logging.FileHandler.pattern = test%u.log
  -java.util.logging.FileHandler.limit = 50000
  -java.util.logging.FileHandler.count = 1
  -java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
  -
  -# If you want to provide finer grained logging, restrict the level for the 
  -# specific package name. 
  -# For example: org.apache.cactus.server.level = FINEST
  -org.apache.cactus.level = FINEST
  
  
  
  1.5       +60 -8     jakarta-cactus/framework/src/java/share/org/apache/cactus/configuration/BaseConfiguration.java
  
  Index: BaseConfiguration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/configuration/BaseConfiguration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BaseConfiguration.java	26 May 2003 11:45:25 -0000	1.4
  +++ BaseConfiguration.java	13 Oct 2003 20:28:40 -0000	1.5
  @@ -124,6 +124,13 @@
           "cactus.initializer";
   
       /**
  +     * Name of the Cactus property that points to a properties file
  +     * containing logging configuration.
  +     */
  +    private static final String CACTUS_LOGGING_CONFIG_PROPERTY = 
  +        "cactus.logging.config";
  +
  +    /**
        * Initialize all Cactus configuration properties.
        */
       public BaseConfiguration()
  @@ -132,13 +139,23 @@
       }
   
       /**
  -     * Read the cactus configuration file from the java property defined
  -     * on the command line (named CACTUS_CONFIG_PROPERTY) and if none has been
  -     * defined tries to read the DEFAULT_CONFIG_NAME file from the classpath.
  -     * All properties found are exported as java system properties.
  +     * Initialize all configurations properties. 
        */
       private void initialize()
       {
  +        initializeConfig();
  +        initializeLoggingConfig();
  +    }
  +
  +    /**
  +     * Initialize general cactus configuration. Read the cactus configuration 
  +     * file from the java property defined on the command line 
  +     * (named CACTUS_CONFIG_PROPERTY) and if none has been defined tries to 
  +     * read the DEFAULT_CONFIG_NAME file from the classpath. All properties 
  +     * found are exported as java system properties.
  +     */
  +    public void initializeConfig()
  +    {
           ResourceBundle config;
   
           // Has the user passed the location of the cactus configuration
  @@ -176,7 +193,42 @@
               }
           }
   
  -        Enumeration keys = config.getKeys();
  +        addSystemProperties(config);
  +    }
  +
  +    /**
  +     * Initialize logging configuration.
  +     */
  +    public void initializeLoggingConfig()
  +    {
  +        String logConfig = System.getProperty(CACTUS_LOGGING_CONFIG_PROPERTY);
  +        if (logConfig != null)
  +        {
  +            ResourceBundle bundle;
  +            try
  +            {
  +                bundle = new PropertyResourceBundle(
  +                    new FileInputStream(logConfig));
  +            } 
  +            catch (IOException e)
  +            {
  +                throw new ChainedRuntimeException("Failed to load logging "
  +                    + "configuration file [" + logConfig + "]");
  +            }
  +            addSystemProperties(bundle);
  +        }
  +    }
  +
  +    /**
  +     * Add all properties found in the resource bundle as system
  +     * properties.
  +     *
  +     * @param theBundle the resource bundle containing the properties to
  +     *        set as system properties
  +     */
  +    private void addSystemProperties(ResourceBundle theBundle)
  +    {
  +        Enumeration keys = theBundle.getKeys();
   
           while (keys.hasMoreElements())
           {
  @@ -187,11 +239,11 @@
               // some values on the command line.
               if (System.getProperty(key) == null)
               {
  -                System.setProperty(key, config.getString(key));
  +                System.setProperty(key, theBundle.getString(key));
               }
           }
       }
  -
  +    
       /**
        * @return the context URL under which our application to test runs.
        */
  
  
  
  1.14      +7 -20     jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestAll.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TestAll.java	12 Oct 2003 19:59:47 -0000	1.13
  +++ TestAll.java	13 Oct 2003 20:28:40 -0000	1.14
  @@ -56,9 +56,7 @@
    */
   package org.apache.cactus;
   
  -import java.io.File;
  -import java.io.FileInputStream;
  -import java.util.Properties;
  +import org.apache.cactus.configuration.BaseConfiguration;
   
   import junit.framework.Test;
   import junit.framework.TestSuite;
  @@ -85,22 +83,11 @@
           TestSuite suite = new TestSuite(
               "Cactus unit tests not needing servlet engine");
   
  -        // Load a Cactus properties file so that we can pass system
  -        // properties to the tests. For example, this is useful to
  -        // set logging properties. If you are using the JDK 1.4 and
  -        // you wish to pass your custom logging file, you'll add the
  -        // following line to the Cactus properties file:
  -        //
  -        // java.util.logging.config.file=logging.properties
  -        
  -        String propsFile = System.getProperty("cactus.test.propertiesFile");
  -        if ((propsFile != null) && (new File(propsFile).exists()))
  -        {    
  -            Properties props = new Properties();
  -            props.load(new FileInputStream(propsFile));
  -            System.setProperties(props);
  -        }        
  -        
  +        // Make sure logging configuration properties are initialized so
  +        // that it is possible to control logging from the outside of the
  +        // tests.
  +        new BaseConfiguration();
  +
           suite.addTestSuite(TestAbstractTestCase.class);
           suite.addTestSuite(TestServletURL.class);
           suite.addTestSuite(TestServletUtil.class);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org