view src/org/thermostat/qa2/framework/ThermostatQAConfig.java @ 170:0d34a379de82

- Added new framework (package org.thermosta.qa2.framework) - Removed hardcoded display in org.thermostat.qa.framework.GuiRobot class
author Zdenek Zambersky <zzambers@redhat.com>
date Tue, 10 Mar 2015 13:38:36 +0100
parents
children 6b6ac47a811f
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;
import java.util.ArrayList;

/**
 *
 * @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 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 commandChannelLogin = new Login("cmdc-tester", "heslo3");

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

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

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

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

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

        gnomeKeyringConfigDir = System.getProperty("gnome-keyring.config.path");
        backupDir = System.getProperty("backup.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 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[] getThermostatUserConfigFiles(String target, boolean web, boolean agentBadlogin, boolean clientBadLogin) {
        return getThermostatUserConfigFilesForVersion(getThermostatVersion(target), web, agentBadlogin, clientBadLogin);
    }

    public static String[] getThermostatUserConfigFilesNames() {
        return new String[]{"agent.auth", "agent.properties", "client.properties"};
    }

    public static String[] getThermostatConfigFiles(String target, boolean web) {
        return getThermostatConfigFilesForVersion(getThermostatVersion(target), web);
    }

    static String[] getThermostatUserConfigFilesForVersion(String thermostatVersion, boolean web, boolean agentBadlogin, boolean clientBadLogin) {
        String prefix = "storageconfig" + File.separator + thermostatVersion;
        if (web) {
            prefix += File.separator + "web-tomcat";
        } else {
            prefix += File.separator + "db-mongodb";
        }
        ArrayList<String> configFiles = new ArrayList();
        configFiles.add(prefix + File.separator + (agentBadlogin ? "agent.badauth" : "agent.auth"));
        configFiles.add(prefix + File.separator + "agent.properties");
        configFiles.add(prefix + File.separator + (clientBadLogin ? "client.badauth" : "client.properties"));
        return configFiles.toArray(new String[configFiles.size()]);
    }

    static String[] getThermostatConfigFilesForVersion(String thermostatVersion, boolean web) {
        String prefix = "storageconfig" + File.separator + thermostatVersion;
        if (web) {
            prefix += File.separator + "web-tomcat";
        } else {
            prefix += File.separator + "db-mongodb";
        }
        ArrayList<String> configFiles = new ArrayList();
        if (web) {
            configFiles.add(prefix + File.separator + "thermostat-users.properties");
            configFiles.add(prefix + File.separator + "thermostat-roles.properties");
        }
        return configFiles.toArray(new String[configFiles.size()]);
    }

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

    public static Login getMongoLogin() {
        return mongoLogin;
    }

    public static Login getAgentLogin() {
        return agentLogin;
    }

    public static Login getClientLogin() {
        return clientLogin;
    }

    public static Login getCommandChannelLogin() {
        return commandChannelLogin;
    }

    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;
        }

    }

}