001: package org.apache.turbine;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: import org.apache.torque.Torque;
026: import org.apache.torque.avalon.TorqueComponent;
027: import org.apache.turbine.services.TurbineServices;
028: import org.apache.turbine.services.avaloncomponent.AvalonComponentService;
029: import org.apache.turbine.test.BaseTestCase;
030: import org.apache.turbine.util.TurbineConfig;
031:
032: /**
033: * Can we load and run Torque standalone, from Component and from
034: * AvalonComponent Service?
035: *
036: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
037: * @version $Id: TorqueLoadTest.java 534527 2007-05-02 16:10:59Z tv $
038: */
039: public class TorqueLoadTest extends BaseTestCase {
040: public TorqueLoadTest(String name) throws Exception {
041: super (name);
042: }
043:
044: public static Test suite() {
045: return new TestSuite(TorqueLoadTest.class);
046: }
047:
048: /**
049: * An uninitialized Torque must not be initialized.
050: */
051: public void testTorqueNonInit() throws Exception {
052: assertFalse("Torque should not be initialized!", Torque
053: .isInit());
054: }
055:
056: /**
057: * Load Torque from a given config file.
058: */
059: public void testTorqueManualInit() throws Exception {
060: assertFalse("Torque should not be initialized!", Torque
061: .isInit());
062: Torque.init("conf/test/TorqueTest.properties");
063: assertTrue("Torque must be initialized!", Torque.isInit());
064: Torque.shutdown();
065:
066: assertFalse("Torque did not shut down properly!", Torque
067: .isInit());
068: }
069:
070: private AvalonComponentService getService() {
071: return (AvalonComponentService) TurbineServices.getInstance()
072: .getService(AvalonComponentService.SERVICE_NAME);
073: }
074:
075: /**
076: * Load Torque with the AvalonComponentService
077: */
078: public void testTorqueAvalonServiceInit() throws Exception {
079: assertFalse("Torque should not be initialized!", Torque
080: .isInit());
081: TurbineConfig tc = new TurbineConfig(".",
082: "/conf/test/TurbineAvalonService.properties");
083:
084: try {
085: tc.initialize();
086: assertTrue("Torque must be initialized!", Torque.isInit());
087:
088: TorqueComponent toc = (TorqueComponent) getService()
089: .lookup("org.apache.torque.avalon.Torque");
090: assertTrue("TorqueComponent must be initialized!", toc
091: .isInit());
092:
093: getService().release(toc);
094: } catch (Exception e) {
095: throw e;
096: } finally {
097: tc.dispose();
098: }
099: assertFalse("Torque did not shut down properly!", Torque
100: .isInit());
101: }
102: }
|