001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creation date: 29/09/2004 - 18:16:46
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum;
044:
045: import java.io.File;
046: import java.io.IOException;
047:
048: import net.jforum.dao.DataAccessDriver;
049: import net.jforum.util.I18n;
050: import net.jforum.util.preferences.ConfigKeys;
051: import net.jforum.util.preferences.SystemGlobals;
052: import freemarker.template.Configuration;
053:
054: /**
055: * General utilities for the test cases.
056: *
057: * @author Rafael Steil
058: * @version $Id: TestCaseUtils.java,v 1.23 2007/09/19 05:43:23 rafaelsteil Exp $
059: */
060: public class TestCaseUtils {
061: private static TestCaseUtils utils = new TestCaseUtils();
062: private String rootDir;
063:
064: private TestCaseUtils() {
065: }
066:
067: public static void loadEnvironment() throws Exception {
068: utils.init();
069: }
070:
071: /**
072: * Inits the database stuff.
073: * Must be called <b>after</b> #loadEnvironment
074: *
075: * @throws Exception
076: */
077: public static void initDatabaseImplementation() throws Exception {
078: SystemGlobals.loadAdditionalDefaults(SystemGlobals
079: .getValue(ConfigKeys.DATABASE_DRIVER_CONFIG));
080:
081: SystemGlobals.loadQueries(SystemGlobals
082: .getValue(ConfigKeys.SQL_QUERIES_GENERIC));
083: SystemGlobals.loadQueries(SystemGlobals
084: .getValue(ConfigKeys.SQL_QUERIES_DRIVER));
085:
086: // Start the dao.driver implementation
087: String driver = SystemGlobals.getValue(ConfigKeys.DAO_DRIVER);
088: Class c = Class.forName(driver);
089: DataAccessDriver d = (DataAccessDriver) c.newInstance();
090: DataAccessDriver.init(d);
091:
092: DBConnection.createInstance();
093: DBConnection.getImplementation().init();
094: }
095:
096: public static String getRootDir() {
097: if (utils.rootDir == null) {
098: utils.rootDir = utils.getClass().getResource("/").getPath();
099: utils.rootDir = utils.rootDir.substring(0, utils.rootDir
100: .length()
101: - "/tests/bin".length());
102: }
103:
104: return utils.rootDir;
105: }
106:
107: private void init() throws IOException {
108: getRootDir();
109: SystemGlobals.initGlobals(this .rootDir, this .rootDir
110: + "/WEB-INF/config/SystemGlobals.properties");
111:
112: if (new File(SystemGlobals
113: .getValue(ConfigKeys.INSTALLATION_CONFIG)).exists()) {
114: SystemGlobals.loadAdditionalDefaults(SystemGlobals
115: .getValue(ConfigKeys.INSTALLATION_CONFIG));
116: }
117:
118: // Configure the template engine
119: Configuration templateCfg = new Configuration();
120: templateCfg.setDirectoryForTemplateLoading(new File(
121: SystemGlobals.getApplicationPath() + "/templates"));
122: templateCfg.setTemplateUpdateDelay(0);
123: JForumExecutionContext.setTemplateConfig(templateCfg);
124:
125: I18n.load();
126: }
127: }
|