1 package org.apache.turbine;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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