view src/org/thermostat/qa/common/Configuration.java @ 167:7baba5d67a16

Fixes of gui tests and web storage tests, making tests more independent * Makefile: added possibility to change backend for making screenshots * Makefile: fixed problem with web storage (content of thermostat webapp direcory is copied in /webaps/thermostat instead of *.war) * Makefile: add coping configuration files to thermostat user directory, which fixed problem of some tests relying on leftower configuration and make it possible run them independently * README.md: new informations about screenshot backends included * src/org/thermostat/qa/framework/Patterns.java: new possible patterns for some tabs added (versions of tabs highlighted under cursor) * src/org/thermostat/qa/framework/ThermostatUtilities.java: thermostats jaas configruation file is now passed to tomcat * src/org/thermostat/qa/testsuites/GuiClientSmokeTest.java: adding 1 second delay fixed problem, when test sometimes failed * src/org/thermostat/qa/testsuites/GuiHostViewSmokeTest.java: window is now not resized more than necessary (caused problem where part of the window did not fit in lower resolution (1024x768) displays/vncs and test failed) * patterns/1.1.0/noAA/ClientPreferencesDialog/connection_info_label.png: added/updated pattern * patterns/1.1.0/noAA/HostView/memory_tab_chsen.png: same as previous * patterns/1.1.0/noAA/HostView/notes_tab.png: same as previous * patterns/1.1.0/noAA/HostView/notes_tab_chosen.png: same as previous * patterns/1.1.0/noAA/HostView/memory_tab_chosen2.png: same as previous * patterns/1.1.0/noAA/HostView/numa_tab_chosen2.png: same as previous * patterns/1.1.0/noAA/HostView/processor_tab_chosen2.png: same as previous
author Zdenek Zambersky <zzambers@redhat.com>
date Fri, 21 Nov 2014 10:50:09 +0100
parents e8ad3e5e4893
children
line wrap: on
line source

/*

    ThermostatQA - test framework for Thermostat Monitoring Tool

    Copyright 2013 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.qa.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class Configuration
{
    /**
     * Property file containing configuration of ThermostatQA.
     */
    private static final String PROPERTIES_FILE_NAME = "test.properties";

    private String thermostatExecutablePath = null;
    private String thermostatExecutableName = null;
    private String thermostatVersion = null;
    private String thermostatHome = null;
    private String thermostatUserHome = null;
    private boolean performCleaningAfterGuiTests = false;
    
    //the way how the screenshots will be provided
    private ScreenshotSourceType screenshotsSource = null; 

    public Configuration(String[] args)
    {
        readConfiguration();
    }

    private void readConfiguration()
    {
        FileInputStream fileInputStream = null;
        try
        {
            fileInputStream = new FileInputStream(PROPERTIES_FILE_NAME);
            readAllProperties(fileInputStream);
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            // try to close input stream containing property information
            if (fileInputStream != null)
            {
                try
                {
                    fileInputStream.close();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * Read test configuration from property file and set all attributes.
     * 
     * @param fileInputStream
     * @throws IOException 
     */
    private void readAllProperties(FileInputStream fileInputStream) throws IOException
    {
        //Properties properties = new Properties();
        //properties.load(fileInputStream);
        this.thermostatExecutablePath = getPathProperty("thermostat.executable.path"); // getPathProperty(properties, "thermostat_executable_path");
        this.thermostatExecutableName = System.getProperty("thermostat.executable.name"); // properties.getProperty("thermostat_executable_name");
        this.thermostatVersion = System.getProperty("thermostat.version"); // properties.getProperty("thermostat_version");
        this.thermostatHome = getPathProperty("thermostat.home"); // getPathProperty(properties, "thermostat_home");
        this.thermostatUserHome = getPathProperty("thermostat.user.home"); // getPathProperty(properties, "thermostat_user_home");
        
        String str = System.getProperty("screenshot.source"); // properties.getProperty("screenshot_source");
        if( str.equals("dummy") ){
            this.screenshotsSource = ScreenshotSourceType.DUMMY;
        }else if( str.equals("robot")){
            this.screenshotsSource = ScreenshotSourceType.NORMAL;
        }else if( str.equals("xvfb")){
            this.screenshotsSource = ScreenshotSourceType.XVFB;
        }
       
        this.performCleaningAfterGuiTests = System.getProperty("clean.after.gui.test").toLowerCase().equals("true") ;// properties.getProperty("clean_after_gui_test").equals("true");
    }
    
    /* eliminating need of tailing separator */
    private static String getPathProperty(String name) { // Properties properties, String name){
        String value = System.getProperty(name);// properties.getProperty(name);
        return value.endsWith(File.separator) ? value : value + File.separator;
    }

    public ScreenshotSourceType getScreenshotsSource() {
        return screenshotsSource;
    }
    
    public boolean useDummyScreenshots(){
       return (this.screenshotsSource == ScreenshotSourceType.DUMMY);
    }
    
    public boolean useRealScreenshots(){
        return (this.screenshotsSource != ScreenshotSourceType.DUMMY);
    }
    
    public String getThermostatVersion()
    {
        return this.thermostatVersion;
    }

    public void setThermostatVersion(String thermostatVersion)
    {
        this.thermostatVersion = thermostatVersion;
    }

    public String getThermostatExecutable()
    {
        return this.thermostatExecutablePath + this.thermostatExecutableName;
    }
    
    public String getThermostatHome()
    {
        return this.thermostatHome;
    }
    
    public String getThermostatUserHome()
    {
        return this.thermostatUserHome;
    }

    public boolean getPerformCleaningAfterGuiTests() {
        return performCleaningAfterGuiTests;
    }
}