view src/org/thermostat/qa2/framework/ThermostatQAConfig.java @ 184:40990362e151

Improved reporter - for compatibility report thermostat versions are now diplayed in heading and title of pages. - fixed bug in replacePatterns method in CommonUtilities class, when there is more then one pattern on single line.
author Zdenek Zambersky <zzambers@redhat.com>
date Fri, 15 May 2015 19:09:02 +0200
parents e37e710e45df
children 7bc828291ea4
line wrap: on
line source

/*
 ThermostatQA - test framework for Thermostat Monitoring Tool

 Copyright 2015 Red Hat, Inc.

 This file is part of ThermostatQA

 ThermostatQA is distributed under the GNU General Public License,
 version 2 or any later version (with a special exception described
 below, commonly known as the "Classpath Exception").

 A copy of GNU General Public License (GPL) is included in this
 distribution, in the file COPYING.

 Linking ThermostatQA code with other modules is making a combined work
 based on ThermostatQA.  Thus, the terms and conditions of the GPL
 cover the whole combination.

 As a special exception, the copyright holders of ThermostatQA give you
 permission to link this code with independent modules to produce an
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on ThermostatQA code.  If you modify ThermostatQA, you may
 extend this exception to your version of the software, but you are
 not obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version.
 */
package org.thermostat.qa2.framework;

import java.io.File;
import java.io.PrintStream;

/**
 *
 * @author Zdeněk Žamberský
 */
public class ThermostatQAConfig {

    public static PrintStream logStream = System.out;
    public static String tomcatHome;
    public static int mongoPort = 27518;
    public static int agentPort = 12000;
    public static int webStoragePort = 8080;
    public static String gnomeKeyringConfigDir;
    public static String backupDir;
    public static String logsDir;
    public static String reportDir;

    public static Login mongoLogin = new Login("mongodevuser", "mongodevpassword");
    public static Login agentLogin = new Login("agent-tester", "heslo1");
    public static Login clientLogin = new Login("client-tester", "heslo2");

    public static Login agentBadLogin = new Login("doctor-evil", "mini-me");
    public static Login clientBadLogin = new Login("time-for-tea", "aaargh");

    ///////////////////////
    // tested thermostat //
    ///////////////////////
    public static String thermostatHome;
    public static String thermostatUserHome;
    public static String thermostatVersion;
    public static String thermostatWebAppDir;

    //////////////////////
    // other thermostat //
    //////////////////////
    public static String thermostatOtherHome;
    //static String ThermostatOtherUserHome;
    public static String thermostatOtherVersion;
    public static String thermostatOtherWebAppDir;

    static {
        tomcatHome = System.getProperty("tomcat.home");

        thermostatHome = System.getProperty("thermostat.home");
        thermostatUserHome = System.getProperty("thermostat.user.home");
        thermostatVersion = System.getProperty("thermostat.version");
        thermostatWebAppDir = System.getProperty("thermostat.webapp.path");

        thermostatOtherHome = System.getProperty("thermostat.other.home");
        thermostatOtherVersion = System.getProperty("thermostat.other.version");
        thermostatOtherWebAppDir = System.getProperty("thermostat.other.webapp.path");

        gnomeKeyringConfigDir = System.getProperty("gnome-keyring.config.path");
        backupDir = System.getProperty("backup.path");

        logsDir = System.getProperty("logs.path");
        reportDir = System.getProperty("reports.path");
    }

    static String getPatternsDir() {
        return "." + File.separator + "patterns" + File.separator + "1.1.0" + File.separator + "noAA";
    }

    // true -> tested, false -> other
    static boolean getTargetAsBoolean(String target) {
        if (target.equals("tested")) {
            return true;
        } else if (target.equals("other")) {
            return false;
        } else {
            throw new IllegalArgumentException("Invalid target thermostat: " + target);
        }
    }

    // true -> web, false -> mongo
    static boolean getStorageTypeAsBoolean(String storageType) {
        if (storageType.equals("web")) {
            return true;
        } else if (storageType.equals("mongo")) {
            return false;
        } else {
            throw new IllegalArgumentException("Invalid storage type: " + storageType);
        }
    }

    public static String getTomcatHome() {
        return tomcatHome;
    }

    public static String getWebAppPath(String target) {
        String dir = getTargetAsBoolean(target) ? thermostatWebAppDir : thermostatOtherWebAppDir;
        File dirFile = new File(dir);
        File[] files = dirFile.listFiles();
        for (File f : files) {
            String name = f.getName();
            if (name.toLowerCase().endsWith(".war")) {
                return dir + File.separator + name.substring(0, name.length() - 4);
            }
        }
        throw new IllegalArgumentException("web app not found");
    }

    public static String getThermostatHome(String target) {
        return getTargetAsBoolean(target) ? thermostatHome : thermostatOtherHome;
    }

    public static String getThermostatUserHome() {
        return getThermostatUserHome("tested");
    }

    public static String getThermostatUserHome(String target) {
        return thermostatUserHome;
    }

    public static String getThermostatVersion(String target) {
        return getTargetAsBoolean(target) ? thermostatVersion : thermostatOtherVersion;
    }

    public static String getThermostatExecutablePath() {
        return getThermostatExecutablePath("tested");
    }

    public static String getThermostatExecutablePath(String target) {
        return getThermostatHome(target) + File.separator + "bin" + File.separator + "thermostat";
    }

    public static String getThermostatOutputTextsDir() {
        return "." + File.separator + "outputtexts" + File.separator + thermostatVersion;
    }

    public static boolean isCompatibilityTesting() {
        return thermostatOtherVersion != null;
    }

    public static Login getMongoLogin() {
        return mongoLogin;
    }

    public static Login getAgentLogin() {
        return agentLogin;
    }

    public static Login getClientLogin() {
        return clientLogin;
    }

    public static Login getCommandChannelLogin() {
        return clientLogin;
    }

    public static Login getAgentBadLogin() {
        return agentBadLogin;
    }

    public static Login getClientBadLogin() {
        return clientBadLogin;
    }

    public static String getStroageUrl(boolean web) {
        return web ? "http://127.0.0.1:" + webStoragePort + "/thermostat/storage" : "mongodb://127.0.0.1:" + mongoPort;
    }

    public static class Login {

        String username;
        String password;

        public Login(String username, String password) {
            this.username = username;
            this.password = password;
        }

        public String getUsername() {
            return username;
        }

        public String getPassword() {
            return password;
        }

    }

}