1   package org.apache.torque;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License")
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import junit.framework.TestCase;
20  
21  /***
22   * Base functionality to be extended by all Torque test cases.  Test
23   * case implementations are used to automate unit testing via JUnit.
24   *
25   * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
26   * @author <a href="mailto:celkins@scardini.com">Christopher Elkins</a>
27   * @version $Id: BaseTestCase.java 239636 2005-08-24 12:38:09Z henning $
28   */
29  public abstract class BaseTestCase extends TestCase
30  {
31      /*** The path to the configuration file. */
32      private static final String CONFIG_FILE
33              = "src/test/TurbineResources.properties";
34  
35      /*** Whether torque has been initialized. */
36      private static boolean hasInitialized = false;
37  
38      /***
39       * Creates a new instance.
40       *
41       * @param name the name of the test case to run
42       */
43      public BaseTestCase(String name)
44      {
45          super(name);
46      }
47  
48      /***
49       * Initialize Torque on the first setUp().  Subclasses which
50       * override setUp() must call super.setUp() as their first action.
51       */
52      public void setUp()
53      {
54          synchronized (BaseTestCase.class)
55          {
56              if (!hasInitialized)
57              {
58                  try
59                  {
60                      Torque.init(CONFIG_FILE);
61                      hasInitialized = true;
62                  }
63                  catch (Exception e)
64                  {
65                      fail("Couldn't initialize Torque: " + e.getMessage());
66                  }
67              }
68          }
69      }
70  }