dlr         01/08/20 16:17:58

  Modified:    src/test/org/apache/torque BaseTestCase.java
  Log:
  Handle Torque initialization activities in one place.
  
  Revision  Changes    Path
  1.2       +57 -1     
jakarta-turbine-torque/src/test/org/apache/torque/BaseTestCase.java
  
  Index: BaseTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-torque/src/test/org/apache/torque/BaseTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- BaseTestCase.java 2001/08/20 16:42:02     1.1
  +++ BaseTestCase.java 2001/08/20 23:17:58     1.2
  @@ -54,22 +54,78 @@
    * <http://www.apache.org/>.
    */
   
  +import java.io.FileInputStream;
  +import java.util.Properties;
  +
  +import org.apache.commons.collections.ExtendedProperties;
  +
  +import org.apache.log4j.Category;
  +import org.apache.log4j.PropertyConfigurator;
  +
   import junit.framework.TestCase;
   
   /**
    * Base functionality to be extended by all Torque test cases.  Test
    * case implementations are used to automate unit testing via JUnit.
    *
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Daniel Rall</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Christopher Elkins</a>
  - * @version $Id: BaseTestCase.java,v 1.1 2001/08/20 16:42:02 dlr Exp $
  + * @version $Id: BaseTestCase.java,v 1.2 2001/08/20 23:17:58 dlr Exp $
    */
   public abstract class BaseTestCase extends TestCase
   {
       /**
  +     * The path to the configuration file.
  +     */
  +    private static final String CONFIG_FILE = "TurbineResources.properties";
  +
  +    /**
  +     * Whether torque has been initialized.
  +     */
  +    private static boolean hasInitialized = false;
  +
  +    /**
        * Creates a new instance.
        */
       public BaseTestCase(String name)
       {
           super(name);
  +        if (!hasInitialized)
  +        {
  +            synchronized (BaseTestCase.class)
  +            {
  +                if (!hasInitialized)
  +                {
  +                    initTorque();
  +                }
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Performs Torque initialization activities.
  +     */
  +    private final void initTorque()
  +    {
  +        try
  +        {
  +            ExtendedProperties config = new ExtendedProperties(CONFIG_FILE);
  +            // HELP: What about the database.* properties?
  +            config = config.subset("services.DatabaseService");
  +            System.out.println("Using configuration file: " +
  +                               config.getString(Torque.DATABASE_DEFAULT));
  +
  +            Properties p = new Properties();
  +            p.load(new FileInputStream(CONFIG_FILE));
  +            PropertyConfigurator.configure(p);
  +
  +            Torque.setConfiguration(config);
  +            Torque.setCategory(Category.getInstance("ALL"));
  +            Torque.init();
  +        }
  +        catch (Exception e)
  +        {
  +            fail("Couldn't initialize Torque: " + e.getMessage());
  +        }
       }
   }
  
  
  

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

Reply via email to