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