view src/org/thermostat/qa/common/Configuration.java @ 150:3d06e2d323cb

refactoring of the framework+testsuites for gui tests so Xvfb+fluxbox may be used
author Jana Fabrikova <jfabriko@redhat.com>
date Tue, 01 Apr 2014 15:09:08 +0200
parents 86af136ea500
children 35c1e2abeb9d
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.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 String apacheTomcatHome = 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 = properties.getProperty("thermostat_executable_path");
        this.thermostatExecutableName = properties.getProperty("thermostat_executable_name");
        this.thermostatVersion = properties.getProperty("thermostat_version");
        this.thermostatHome = properties.getProperty("thermostat_home");
        this.thermostatUserHome = properties.getProperty("thermostat_user_home");
        this.apacheTomcatHome = properties.getProperty("apache_tomcat_home");
        
        String str = properties.getProperty("screenshot_source");
        if( str.equals("dummy") ){
            this.screenshotsSource = ScreenshotSourceType.DUMMY;
        }else if( str.equals("normal")){
            this.screenshotsSource = ScreenshotSourceType.NORMAL;
        }else if( str.equals("xvfb")){
            this.screenshotsSource = ScreenshotSourceType.XVFB;
        }
       
        this.performCleaningAfterGuiTests = properties.getProperty("clean_after_gui_test").equals("true");
    }

    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 String getApacheTomcatHome()
    {
        return this.apacheTomcatHome;
    }


    
    public boolean getPerformCleaningAfterGuiTests() {
        return performCleaningAfterGuiTests;
    }
}