001: package org.tigris.scarab.test;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048: import java.io.File;
049: import java.util.HashMap;
050: import java.util.Map;
051:
052: import junit.framework.TestCase;
053:
054: import org.apache.fulcrum.TurbineServices;
055: import org.apache.turbine.Turbine;
056: import org.apache.turbine.TurbineConfig;
057: import org.apache.turbine.TurbineConstants;
058: import org.apache.turbine.TurbineXmlConfig;
059:
060: /**
061: * Test case that just starts up Turbine. All Scarab specific
062: * logic needs to be implemented in your own test cases.
063: *
064: * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
065: */
066: public class BaseTurbineTestCase extends TestCase {
067: private static TurbineConfig tc = null;
068:
069: private static boolean initialized = false;
070:
071: public BaseTurbineTestCase() {
072: System.setProperty("applicationRoot", "./target/test-classes");
073: }
074:
075: public BaseTurbineTestCase(String name) throws Exception {
076: super (name);
077: }
078:
079: /*
080: * @see TestCase#setUp()
081: */
082: protected void setUp() throws Exception {
083:
084: if (!initialized) {
085: createLog4jDirectory();
086: initTurbine();
087: initialized = true;
088: }
089: }
090:
091: /*
092: * @see TestCase#tearDown()
093: */
094: protected void tearDown() throws Exception {
095: super .tearDown();
096: if (Turbine.getConfiguration() != null) {
097: // stopping turbine on each test iteration has a major performance impact
098: // checking for this parameter allows this to be skipped for a fast run of
099: // all tests in a single turbine instance.
100: boolean stop = Turbine.getConfiguration().getBoolean(
101: "unittest.teardown.shutdownServices", true);
102:
103: if (stop) {
104: TurbineServices.getInstance().shutdownServices();
105: initialized = false;
106: }
107: }
108: }
109:
110: private void createLog4jDirectory() {
111: File log4jDir = new File("." + File.separator + "target"
112: + File.separator + "scarab" + File.separator + "logs"
113: + File.separator);
114: if (!log4jDir.exists()) {
115: log4jDir.mkdirs();
116: }
117: }
118:
119: private void initTurbine() throws Exception {
120: File directoryFile = new File("src/test");
121: String directory = directoryFile.getAbsolutePath();
122:
123: Map params = new HashMap();
124: params.put(TurbineXmlConfig.CONFIGURATION_PATH_KEY,
125: "../../src/test/TestTurbineConfiguration.xml");
126: params.put(TurbineConstants.APPLICATION_ROOT, "target/scarab");
127: /*tc =
128: new TurbineXmlConfig(directory, "TestTurbineConfiguration.xml");*/
129: tc = new TurbineXmlConfig(directory, params);
130: tc.init();
131:
132: }
133:
134: }
|