1   package org.apache.turbine;
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.Test;
23  import junit.framework.TestSuite;
24  
25  import org.apache.torque.Torque;
26  import org.apache.torque.avalon.TorqueComponent;
27  import org.apache.turbine.services.TurbineServices;
28  import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
29  import org.apache.turbine.test.BaseTestCase;
30  import org.apache.turbine.util.TurbineConfig;
31  
32  /***
33   * Can we load and run Torque standalone, from Component and from
34   * AvalonComponent Service?
35   *
36   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
37   * @version $Id: TorqueLoadTest.java 534527 2007-05-02 16:10:59Z tv $
38   */
39  public class TorqueLoadTest
40          extends BaseTestCase
41  {
42      public TorqueLoadTest(String name)
43              throws Exception
44      {
45          super(name);
46      }
47  
48      public static Test suite()
49      {
50          return new TestSuite(TorqueLoadTest.class);
51      }
52  
53      /***
54       * An uninitialized Torque must not be initialized.
55       */
56      public void testTorqueNonInit()
57              throws Exception
58      {
59          assertFalse("Torque should not be initialized!", Torque.isInit());
60      }
61  
62      /***
63       * Load Torque from a given config file.
64       */
65      public void testTorqueManualInit()
66              throws Exception
67      {
68          assertFalse("Torque should not be initialized!", Torque.isInit());
69          Torque.init("conf/test/TorqueTest.properties");
70          assertTrue("Torque must be initialized!", Torque.isInit());
71          Torque.shutdown();
72  
73          assertFalse("Torque did not shut down properly!", Torque.isInit());
74      }
75  
76      private AvalonComponentService getService()
77      {
78          return (AvalonComponentService) TurbineServices.getInstance()
79                  .getService(AvalonComponentService.SERVICE_NAME);
80      }
81  
82      /***
83       * Load Torque with the AvalonComponentService
84       */
85      public void testTorqueAvalonServiceInit()
86              throws Exception
87      {
88           assertFalse("Torque should not be initialized!", Torque.isInit());
89           TurbineConfig tc = new TurbineConfig(".", "/conf/test/TurbineAvalonService.properties");
90  
91           try
92           {
93               tc.initialize();
94               assertTrue("Torque must be initialized!", Torque.isInit());
95  
96               TorqueComponent toc =
97                       (TorqueComponent) getService().lookup("org.apache.torque.avalon.Torque");
98               assertTrue("TorqueComponent must be initialized!", toc.isInit());
99  
100              getService().release(toc);
101          }
102          catch (Exception e)
103          {
104              throw e;
105          }
106          finally
107          {
108              tc.dispose();
109          }
110          assertFalse("Torque did not shut down properly!", Torque.isInit());
111     }
112 }
113