1   package org.apache.turbine;
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.Test;
20  import junit.framework.TestSuite;
21  
22  import org.apache.torque.Torque;
23  import org.apache.turbine.services.TurbineServices;
24  import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
25  import org.apache.turbine.test.BaseTestCase;
26  import org.apache.turbine.util.TurbineConfig;
27  
28  /***
29   * Can we load and run Torque standalone, from Component and from
30   * AvalonComponent Service?
31   *
32   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
33   * @version $Id: TorqueLoadTest.java 264148 2005-08-29 14:21:04Z henning $
34   */
35  public class TorqueLoadTest
36          extends BaseTestCase
37  {
38      public TorqueLoadTest(String name)
39              throws Exception
40      {
41          super(name);
42      }
43  
44      public static Test suite()
45      {
46          return new TestSuite(TorqueLoadTest.class);
47      }
48  
49      /***
50       * An uninitialized Torque must not be initialized.
51       */
52      public void testTorqueNonInit()
53              throws Exception
54      {
55          assertFalse("Torque should not be initialized!", Torque.isInit());
56      }
57  
58      /***
59       * Load Torque from a given config file.
60       */
61      public void testTorqueManualInit()
62              throws Exception
63      {
64          assertFalse("Torque should not be initialized!", Torque.isInit());
65          Torque.init("conf/test/TorqueTest.properties");
66          assertTrue("Torque must be initialized!", Torque.isInit());
67          Torque.shutdown();
68          // Uncomment once we get a torque 3.1 release post alpha-2
69          // Everything up to alpha-2 does not shut down Torque properly.
70          // assertFalse("Torque did not shut down properly!", Torque.isInit());
71      }
72  
73      /***
74       * Load Torque with the ComponentService
75       */
76      public void testTorqueComponentServiceInit()
77              throws Exception
78      {
79          assertFalse("Torque should not be initialized!", Torque.isInit());
80  
81          TurbineConfig tc = new TurbineConfig(".", "/conf/test/TurbineComponentService.properties");
82          try
83          {
84              tc.initialize();
85              assertTrue("Torque must be initialized!", Torque.isInit());
86          }
87          catch (Exception e)
88          {
89              throw e;
90          }
91          finally
92          {
93              tc.dispose();
94          }
95          // Uncomment once we get a torque 3.1 release post alpha-2
96          // Everything up to alpha-2 does not shut down Torque properly.
97          // assertFalse("Torque did not shut down properly!", Torque.isInit());
98      }
99  
100     private AvalonComponentService getService()
101     {
102         return (AvalonComponentService) TurbineServices.getInstance()
103                 .getService(AvalonComponentService.SERVICE_NAME);
104     }
105 
106     // Uncomment once we get a torque 3.1 release post alpha-2
107     // The current version of Torque doesn't run right with the AvalonComponentService
108     //
109     //    /***
110     //     * Load Torque with the AvalonComponentService
111     //     */
112     //     public void testTorqueAvalonServiceInit()
113     //             throws Exception
114     //     {
115     //         assertFalse("Torque should not be initialized!", Torque.isInit());
116 
117     //         TurbineConfig tc = new TurbineConfig(".", "/conf/test/TurbineAvalonService.properties");
118 
119     //         try
120     //         {
121     //             tc.initialize();
122     //             assertTrue("Torque must be initialized!", Torque.isInit());
123 
124     //             TorqueComponent toc =
125     //                     (TorqueComponent) getService().lookup("org.apache.torque.avalon.Torque");
126     //             assertTrue("TorqueComponent must be initialized!", toc.isInit());
127 
128     //             getService().release(toc);
129     //         }
130     //         catch (Exception e)
131     //         {
132     //             throw e;
133     //         }
134     //         finally
135     //         {
136     //             tc.dispose();
137     //         }
138     //         assertFalse("Torque did not shut down properly!", Torque.isInit());
139     //     }
140 }
141