001: package org.apache.turbine;
002:
003: /*
004: * Copyright 2001-2005 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License")
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021:
022: import org.apache.torque.Torque;
023: import org.apache.turbine.services.TurbineServices;
024: import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
025: import org.apache.turbine.test.BaseTestCase;
026: import org.apache.turbine.util.TurbineConfig;
027:
028: /**
029: * Can we load and run Torque standalone, from Component and from
030: * AvalonComponent Service?
031: *
032: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
033: * @version $Id: TorqueLoadTest.java 264148 2005-08-29 14:21:04Z henning $
034: */
035: public class TorqueLoadTest extends BaseTestCase {
036: public TorqueLoadTest(String name) throws Exception {
037: super (name);
038: }
039:
040: public static Test suite() {
041: return new TestSuite(TorqueLoadTest.class);
042: }
043:
044: /**
045: * An uninitialized Torque must not be initialized.
046: */
047: public void testTorqueNonInit() throws Exception {
048: assertFalse("Torque should not be initialized!", Torque
049: .isInit());
050: }
051:
052: /**
053: * Load Torque from a given config file.
054: */
055: public void testTorqueManualInit() throws Exception {
056: assertFalse("Torque should not be initialized!", Torque
057: .isInit());
058: Torque.init("conf/test/TorqueTest.properties");
059: assertTrue("Torque must be initialized!", Torque.isInit());
060: Torque.shutdown();
061: // Uncomment once we get a torque 3.1 release post alpha-2
062: // Everything up to alpha-2 does not shut down Torque properly.
063: // assertFalse("Torque did not shut down properly!", Torque.isInit());
064: }
065:
066: /**
067: * Load Torque with the ComponentService
068: */
069: public void testTorqueComponentServiceInit() throws Exception {
070: assertFalse("Torque should not be initialized!", Torque
071: .isInit());
072:
073: TurbineConfig tc = new TurbineConfig(".",
074: "/conf/test/TurbineComponentService.properties");
075: try {
076: tc.initialize();
077: assertTrue("Torque must be initialized!", Torque.isInit());
078: } catch (Exception e) {
079: throw e;
080: } finally {
081: tc.dispose();
082: }
083: // Uncomment once we get a torque 3.1 release post alpha-2
084: // Everything up to alpha-2 does not shut down Torque properly.
085: // assertFalse("Torque did not shut down properly!", Torque.isInit());
086: }
087:
088: private AvalonComponentService getService() {
089: return (AvalonComponentService) TurbineServices.getInstance()
090: .getService(AvalonComponentService.SERVICE_NAME);
091: }
092:
093: // Uncomment once we get a torque 3.1 release post alpha-2
094: // The current version of Torque doesn't run right with the AvalonComponentService
095: //
096: // /**
097: // * Load Torque with the AvalonComponentService
098: // */
099: // public void testTorqueAvalonServiceInit()
100: // throws Exception
101: // {
102: // assertFalse("Torque should not be initialized!", Torque.isInit());
103:
104: // TurbineConfig tc = new TurbineConfig(".", "/conf/test/TurbineAvalonService.properties");
105:
106: // try
107: // {
108: // tc.initialize();
109: // assertTrue("Torque must be initialized!", Torque.isInit());
110:
111: // TorqueComponent toc =
112: // (TorqueComponent) getService().lookup("org.apache.torque.avalon.Torque");
113: // assertTrue("TorqueComponent must be initialized!", toc.isInit());
114:
115: // getService().release(toc);
116: // }
117: // catch (Exception e)
118: // {
119: // throw e;
120: // }
121: // finally
122: // {
123: // tc.dispose();
124: // }
125: // assertFalse("Torque did not shut down properly!", Torque.isInit());
126: // }
127: }
|