vmassol     01/10/20 12:24:27

  Modified:    src/framework/share/org/apache/cactus AbstractTestCase.java
               src/framework/share/org/apache/cactus/client
                        AbstractHttpClient.java
                        ClientConfigurationChecker.java
               src/test/share/org/apache/cactus
                        TestAbstractTestCase_InterceptorTestCase.java
  Log:
  improved client configuration checking (to detect early configuration errors and 
display nice messages)
  
  Revision  Changes    Path
  1.13      +13 -3     
jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java
  
  Index: AbstractTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractTestCase.java     2001/10/19 23:06:34     1.12
  +++ AbstractTestCase.java     2001/10/20 19:24:27     1.13
  @@ -72,7 +72,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    *
  - * @version $Id: AbstractTestCase.java,v 1.12 2001/10/19 23:06:34 vmassol Exp $
  + * @version $Id: AbstractTestCase.java,v 1.13 2001/10/20 19:24:27 vmassol Exp $
    */
   public abstract class AbstractTestCase extends TestCase
   {
  @@ -92,6 +92,11 @@
       protected final static String END_METHOD_PREFIX = "end";
   
       /**
  +     * Name of properties file to initialize logging subsystem
  +     */
  +    public final static String LOG_CLIENT_CONFIG = "log_client.properties";
  +
  +    /**
        * The name of the current test method being executed. This name is valid
        * both on the client side and on the server side, meaning you can call it
        * from a <code>testXXX()</code>, <code>setUp()</code> or
  @@ -353,16 +358,21 @@
        */
       public void runBare() throws Throwable
       {
  +        // Run some configuration checks
  +        ClientConfigurationChecker.getInstance().checkCactusProperties();
  +        ClientConfigurationChecker.getInstance().checkHttpClient();
  +        ClientConfigurationChecker.getInstance().checkLog4j();
  +
           // Initialize the logging system. As this class is instanciated both
           // on the server side and on the client side, we need to differentiate
           // the logging initialisation. This method is only called on the client
           // side, so we instanciate the log for client side here.
           if (!LogService.getInstance().isInitialized()) {
  -            LogService.getInstance().init("/log_client.properties");
  +            LogService.getInstance().init("/" + AbstractTestCase.LOG_CLIENT_CONFIG);
           }
   
           // We make sure we reinitialize the logger with the name of the
  -        // current class (that's why the logge instance is not static).
  +        // current class (that's why the logged instance is not static).
           this.logger =
               LogService.getInstance().getLog(this.getClass().getName());
   
  
  
  
  1.10      +1 -8      
jakarta-cactus/src/framework/share/org/apache/cactus/client/AbstractHttpClient.java
  
  Index: AbstractHttpClient.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/client/AbstractHttpClient.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AbstractHttpClient.java   2001/10/19 21:11:34     1.9
  +++ AbstractHttpClient.java   2001/10/20 19:24:27     1.10
  @@ -67,7 +67,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    *
  - * @version $Id: AbstractHttpClient.java,v 1.9 2001/10/19 21:11:34 vmassol Exp $
  + * @version $Id: AbstractHttpClient.java,v 1.10 2001/10/20 19:24:27 vmassol Exp $
    */
   public abstract class AbstractHttpClient
   {
  @@ -87,13 +87,6 @@
        */
       public final static ResourceBundle CONFIG =
           PropertyResourceBundle.getBundle(CONFIG_NAME);
  -
  -    /**
  -     * Check client configuration parameters (verify client classpath)
  -     */
  -    static {
  -        ClientConfigurationChecker.checkConfigProperties();
  -    }
   
       /**
        * @return the URL to call the redirector
  
  
  
  1.5       +113 -6    
jakarta-cactus/src/framework/share/org/apache/cactus/client/ClientConfigurationChecker.java
  
  Index: ClientConfigurationChecker.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/client/ClientConfigurationChecker.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ClientConfigurationChecker.java   2001/09/14 20:15:14     1.4
  +++ ClientConfigurationChecker.java   2001/10/20 19:24:27     1.5
  @@ -57,35 +57,142 @@
   import java.io.*;
   
   import org.apache.cactus.*;
  +import org.apache.cactus.util.*;
  +import org.apache.cactus.util.log.*;
   
   /**
    * Helper class that checks configuration parameters (for the client side)
    * like if the CLASSPATH contains the jar for the Servlet API, if the
    * <code>cactus.properties</code> file is in the CLASSPATH, ...
    *
  + * Note: there cannot be any logging in the checking process as the
  + * logging system has not been initialized yet when the methods of this class
  + * are called.
  + *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    *
  - * @version $Id: ClientConfigurationChecker.java,v 1.4 2001/09/14 20:15:14 pier Exp 
$
  + * @version $Id: ClientConfigurationChecker.java,v 1.5 2001/10/20 19:24:27 vmassol 
Exp $
    */
   public class ClientConfigurationChecker
   {
       /**
  +     * Singleton instance
  +     */
  +    private static ClientConfigurationChecker instance;
  +
  +    /**
  +     * Has the presence of httpclient jar been checked ?
  +     */
  +    private boolean isHttpClientChecked;
  +
  +    /**
  +     * Has the presence of cactus.properties been checked ?
  +     */
  +    private boolean isCactusPropertiesChecked;
  +
  +    /**
  +     * Has the log4j subsystem been checked ?
  +     */
  +    private boolean isLog4jChecked;
  +
  +    /**
  +     * Private constructor (singleton)
  +     */
  +    private ClientConfigurationChecker()
  +    {
  +    }
  +
  +    /**
  +     * @return the singleton instance
  +     */
  +    public static synchronized ClientConfigurationChecker getInstance()
  +    {
  +        if (instance == null) {
  +            instance = new ClientConfigurationChecker();
  +        }
  +
  +        return instance;
  +    }
  +
  +    /**
        * Checks if the <code>cactus.properties</code> file is in the CLASSPATH.
        *
  -     * @exception RuntimeException if the properties file is not in the
  +     * @exception ChainedRuntimeException if the properties file is not in the
        *            CLASSPATH.
        */
  -    public static void checkConfigProperties()
  +    public synchronized void checkCactusProperties()
       {
  -        InputStream is = ClientConfigurationChecker.class.getResourceAsStream( 
  +        if (this.isCactusPropertiesChecked) {
  +            return;
  +        }
  +
  +        InputStream is = ClientConfigurationChecker.class.getResourceAsStream(
               "/" + AbstractHttpClient.CONFIG_NAME + ".properties");
           
           if (is == null) {
               String msg = "The Cactus '" + AbstractHttpClient.CONFIG_NAME +
                   ".properties' configuration file need to be present in the " +
                   "java CLASSPATH (i.e. the directory that contains it need " +
  -                "to be added to the CLASSPATH).";
  -            throw new RuntimeException(msg);
  +                "to be added to the client side CLASSPATH - This is the " +
  +                "CLASSPATH that you used to start the JUnit test runner).";
  +            throw new ChainedRuntimeException(msg);
  +        }
  +
  +        this.isCactusPropertiesChecked = true;
  +    }
  +
  +    /**
  +     * Check if the httpclient jar is in the CLASSPATH
  +     */
  +    public void checkHttpClient()
  +    {
  +        if (this.isHttpClientChecked) {
  +            return;
  +        }
  +
  +        try {
  +            Class httpclientClass =
  +                Class.forName("org.apache.commons.httpclient.HttpClient");
  +        } catch (ClassNotFoundException e) {
  +            String msg = "The Commons HttpClient jar file need to be " +
  +                "present in the client side CLASSPATH (This is the " +
  +                "CLASSPATH that you used to start the JUnit test runner).";
  +            throw new ChainedRuntimeException(msg, e);
  +        }
  +
  +        this.isHttpClientChecked = true;
  +    }
  +
  +    /**
  +     * Verify that log_client.properties is in the CLASSPATH if the log4j jar
  +     * is in the classpath
  +     */
  +    public void checkLog4j()
  +    {
  +        if (this.isLog4jChecked) {
  +            return;
  +        }
  +
  +        try {
  +            Class log4jClass =
  +                Class.forName("org.apache.log4j.Category");
  +        } catch (ClassNotFoundException e) {
  +            // Log4j is not in the classpath, so it is fine if
  +            // log_client.properties is not in the classpath as the logging
  +            // system will be initialized with no op log class.
  +            this.isLog4jChecked = true;
  +            return;
  +        }
  +
  +        InputStream is = ClientConfigurationChecker.class.getResourceAsStream(
  +            "/" + AbstractTestCase.LOG_CLIENT_CONFIG);
  +
  +        if (is == null) {
  +            String msg = "The '" + AbstractTestCase.LOG_CLIENT_CONFIG +
  +                "' logging configuration file need to be present in the " +
  +                "java CLASSPATH. If you do not wish to enable logging, " +
  +                "please remove the log4j jar from the CLASSPATH.";
  +            throw new ChainedRuntimeException(msg);
           }
   
       }
  
  
  
  1.7       +10 -1     
jakarta-cactus/src/test/share/org/apache/cactus/TestAbstractTestCase_InterceptorTestCase.java
  
  Index: TestAbstractTestCase_InterceptorTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/src/test/share/org/apache/cactus/TestAbstractTestCase_InterceptorTestCase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestAbstractTestCase_InterceptorTestCase.java     2001/10/19 21:11:34     1.6
  +++ TestAbstractTestCase_InterceptorTestCase.java     2001/10/20 19:24:27     1.7
  @@ -68,7 +68,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Vincent Massol</a>
    *
  - * @version $Id: TestAbstractTestCase_InterceptorTestCase.java,v 1.6 2001/10/19 
21:11:34 vmassol Exp $
  + * @version $Id: TestAbstractTestCase_InterceptorTestCase.java,v 1.7 2001/10/20 
19:24:27 vmassol Exp $
    */
   public class TestAbstractTestCase_InterceptorTestCase
       extends AbstractTestCase
  @@ -81,6 +81,15 @@
       public TestAbstractTestCase_InterceptorTestCase(String theName)
       {
           super(theName);
  +    }
  +
  +    /**
  +     * Override default method so that configuration checks are not run during
  +     * these unit tests.
  +     */
  +    public void runBare() throws Throwable
  +    {
  +        runTest();
       }
   
       /**
  
  
  

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

Reply via email to