view src/org/thermostat/qa/testsuites/OutputMessagesTest.java @ 162:e8ad3e5e4893

Making testing process automatic
author Zdenek Zambersky <zzambers@redhat.com>
date Wed, 22 Oct 2014 16:42:56 +0200
parents a31fddb9db68
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.testsuites;



import java.io.IOException;
import java.util.List;



import org.thermostat.qa.annotations.TestType;
import org.thermostat.qa.annotations.TestTypes;
import org.thermostat.qa.framework.Assert;
import org.thermostat.qa.framework.ThermostatTest;
import org.thermostat.qa.reporter.FileUtils;



/**
 * Class OutputMessagesTest 
 * contains testcases for checking the output messages written to the
 * standard output after issuing thermostat help commands in a command line.
 */
@TestType(TestTypes.CLI_TEST)
public class OutputMessagesTest extends ThermostatTest
{
    /**
     * The field allflags should be changed whenever the called flags change
     * because output text generator uses this commands for thermostat.
     */
    public static final String[][] allflags = new String[][]{ null,
        {"help"},
        {"help","agent"},
        {"help", "connect"},
        {"help", "disconnect"},
        {"help", "dump-heap"},
        {"help", "find-objects"},
        {"help", "find-root"},
        {"help", "gui"},
        {"help", "list-heap-dumps"},
        {"help", "list-vms"},
        {"help", "object-info"},
        {"help", "ping"},
        {"help", "save-heap-dump-to-file"},
        {"help", "show-heap-histogram"},
        {"help", "service"},
        {"help", "shell"},
        {"help", "storage"},
        {"help", "vm-info"},
        {"help", "vm-stat"}};

    private String outputsPath;

    private static String[] THERMOSTAT_STANDARD_MESSAGE, 
    THERMOSTAT_HELP_MESSAGE, 
    THERMOSTAT_HELP_AGENT_MESSAGE, 
    THERMOSTAT_HELP_CONNECT_MESSAGE, 
    THERMOSTAT_HELP_DISCONNECT_MESSAGE, 
    THERMOSTAT_HELP_DUMP_HEAP_MESSAGE,
    THERMOSTAT_HELP_FIND_OBJECTS_MESSAGE,
    THERMOSTAT_HELP_FIND_ROOT_MESSAGE,
    THERMOSTAT_HELP_GUI_MESSAGE,
    THERMOSTAT_HELP_LIST_HEAP_DUMPS_MESSAGE,
    THERMOSTAT_HELP_LIST_VMS_MESSAGE,
    THERMOSTAT_HELP_OBJECT_INFO_MESSAGE,
    THERMOSTAT_HELP_PING_MESSAGE,
    THERMOSTAT_HELP_SAVE_HEAP_DUMP_TO_FILE_MESSAGE,
    THERMOSTAT_HELP_SERVICE_MESSAGE,
    THERMOSTAT_HELP_SHELL_MESSAGE,
    THERMOSTAT_HELP_SHOW_HEAP_HISTOGRAM_MESSAGE,
    THERMOSTAT_HELP_STORAGE_MESSAGE,
    THERMOSTAT_HELP_VM_INFO_MESSAGE,
    THERMOSTAT_HELP_VM_STAT_MESSAGE;

    @Override
    protected void setUp()
    {
        this.outputsPath = "outputtexts/"+this.configuration.getThermostatVersion()+"/";
        THERMOSTAT_STANDARD_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat.txt");
        THERMOSTAT_HELP_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help.txt");
        THERMOSTAT_HELP_AGENT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_agent.txt");
        THERMOSTAT_HELP_CONNECT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_connect.txt");
        THERMOSTAT_HELP_DISCONNECT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_disconnect.txt"); 
        THERMOSTAT_HELP_DUMP_HEAP_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_dump-heap.txt");
        THERMOSTAT_HELP_FIND_OBJECTS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_find-objects.txt");
        THERMOSTAT_HELP_FIND_ROOT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_find-root.txt");
        THERMOSTAT_HELP_GUI_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_gui.txt");
        THERMOSTAT_HELP_LIST_HEAP_DUMPS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_list-heap-dumps.txt");
        THERMOSTAT_HELP_LIST_VMS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_list-vms.txt");
        THERMOSTAT_HELP_OBJECT_INFO_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_object-info.txt");
        THERMOSTAT_HELP_PING_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_ping.txt");
        THERMOSTAT_HELP_SAVE_HEAP_DUMP_TO_FILE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_save-heap-dump-to-file.txt");
        THERMOSTAT_HELP_SERVICE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_service.txt");
        THERMOSTAT_HELP_SHELL_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_shell.txt");
        THERMOSTAT_HELP_SHOW_HEAP_HISTOGRAM_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_show-heap-histogram.txt");
        THERMOSTAT_HELP_STORAGE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_storage.txt");
        THERMOSTAT_HELP_VM_INFO_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_vm-info.txt");
        THERMOSTAT_HELP_VM_STAT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_vm-stat.txt");
    }

    @Override
    protected void tearDown()
    {
        // TODO Auto-generated method stub
        
    }

    private void compareMessages(String[] template, List<String> processOutput)
            throws AssertionError
    {
        for (int i=0; i<template.length; i++)
        {
            String s1 = template[i];
            String s2 = processOutput.get(i);
            Assert.assertEquals(s1, s2, "'" + s1 + "' is not equal to '" + s2 + "'");
        }
        for (int i=0; i<processOutput.size(); i++)
        {
            String s1 = template[i];
            String s2 = processOutput.get(i);
            Assert.assertEquals(s1, s2, "'" + s1 + "' is not equal to '" + s2 + "'");
        }
    }

    /**
     * Read message written by the Thermostat CLI client to the standard output
     * and compare those messages with the given template.
     *
     * @param template template containing expected messages
     * @param flags flags passed to the Thermostat CLI client
     * @throws IOException
     * @throws AssertionError thrown when the given template is different from actual messages
     */
    private void readAndCheckThermostatMessage(String[] template, String... flags) throws IOException, AssertionError
    {
        Process process = runThermostatInNewProcess(flags);
        List<String> processOutput = readProcessOutput(process);
        Assert.assertNotNull(processOutput, "error getting standard output");
        compareMessages(template, processOutput);
    }

    /**
     * Method testCheckStandardMessage
     * checks output of command "thermostat".
     * 
     * @throws IOException
     */
    public void testCheckStandardMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_STANDARD_MESSAGE, allflags[0]);
    }

    /**
     * Method testCheckHelpMessage
     * checks output of command "thermostat help".
     * 
     * @throws IOException
     */
    public void testCheckHelpMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_MESSAGE, allflags[1]);
    }

    /**
     * Method testCheckHelpAgentMessage
     * checks output of command "thermostat help agent".
     * 
     * @throws IOException
     */
    public void testCheckHelpAgentMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_AGENT_MESSAGE, allflags[2]);
    }

    /**
     * Method testCheckHelpConnectMessage
     * checks output of command "thermostat help connect".
     * 
     * @throws IOException
     */
    public void testCheckHelpConnectMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_CONNECT_MESSAGE, allflags[3]);
    }

    /**
     * Method testCheckHelpDisconnectMessage
     * checks output of command "thermostat help disconnect".
     * 
     * @throws IOException
     */
    public void testCheckHelpDisconnectMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_DISCONNECT_MESSAGE, allflags[4]);
    }

    /**
     * Method testCheckHelpDumpHeapMessage
     * checks output of command "thermostat help dump-heap".
     * 
     * @throws IOException
     */
    public void testCheckHelpDumpHeapMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_DUMP_HEAP_MESSAGE, allflags[5]);
    }

    /**
     * Method testCheckHelpFindObjectsMessage
     * checks output of command "thermostat help find-objects".
     * 
     * @throws IOException
     */
    public void testCheckHelpFindObjectsMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_FIND_OBJECTS_MESSAGE, allflags[6]);
    }

    /**
     * Method testCheckHelpFindRootMessage
     * checks output of command "thermostat help find-root".
     * 
     * @throws IOException
     */
    public void testCheckHelpFindRootMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_FIND_ROOT_MESSAGE, allflags[7]);
    }

    /**
     * Method testCheckHelpGuiMessage
     * checks output of command "thermostat help gui".
     * 
     * @throws IOException
     */
    public void testCheckHelpGuiMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_GUI_MESSAGE, allflags[8]);
    }

    /**
     * Method testCheckHelpListHeapDumpsMessage
     * checks output of command "thermostat help list-heap-dumps".
     * 
     * @throws IOException
     */
    public void testCheckHelpListHeapDumpsMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_LIST_HEAP_DUMPS_MESSAGE, allflags[9]);
    }

    /**
     * Method testCheckHelpListVmsMessage
     * checks output of command "thermostat help list-vms".
     * 
     * @throws IOException
     */
    public void testCheckHelpListVmsMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_LIST_VMS_MESSAGE, allflags[10]);
    }

    /**
     * Method testCheckHelpObjectInfoMessage
     * checks output of command "thermostat help object-info".
     * 
     * @throws IOException
     */
    public void testCheckHelpObjectInfoMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_OBJECT_INFO_MESSAGE, allflags[11]);
    }

    /**
     * Method testCheckHelpPingMessage
     * checks output of command "thermostat help ping".
     * 
     * @throws IOException
     */
    public void testCheckHelpPingMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_PING_MESSAGE, allflags[12]);
    }

    /**
     * Method testCheckHelpSaveHeapDumpToFileMessage
     * checks output of command "thermostat help save-heap-dump-to-file".
     * 
     * @throws IOException
     */
    public void testCheckHelpSaveHeapDumpToFileMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_SAVE_HEAP_DUMP_TO_FILE_MESSAGE, allflags[13]);
    }

    /**
     * Method testCheckHelpShowHeapHistogramMessage
     * checks output of command "thermostat help show-heap-histogram".
     * 
     * @throws IOException
     */
    public void testCheckHelpShowHeapHistogramMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_SHOW_HEAP_HISTOGRAM_MESSAGE, allflags[14]);
    }

    /**
     * Method testCheckHelpServiceMessage
     * checks output of command "thermostat help service".
     * 
     * @throws IOException
     */
    public void testCheckHelpServiceMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_SERVICE_MESSAGE, allflags[15]);
    }

    /**
     * Method testCheckHelpShellMessage
     * checks output of command "thermostat help shell".
     * 
     * @throws IOException
     */
    public void testCheckHelpShellMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_SHELL_MESSAGE, allflags[16]);
    }

    /**
     * Method testCheckHelpStorageMessage
     * checks output of command "thermostat help storage".
     * 
     * @throws IOException
     */
    public void testCheckHelpStorageMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_STORAGE_MESSAGE, allflags[17]);
    }

    /**
     * Method testCheckHelpVmInfoMessage
     * checks output of command "thermostat help vm-info".
     * 
     * @throws IOException
     */
    public void testCheckHelpVmInfoMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_VM_INFO_MESSAGE, allflags[18]);
    }

    /**
     * Method testCheckHelpVmStatMessage
     * checks output of command "thermostat help vm-stat".
     * 
     * @throws IOException
     */
    public void testCheckHelpVmStatMessage() throws IOException
    {
        readAndCheckThermostatMessage(THERMOSTAT_HELP_VM_STAT_MESSAGE, allflags[19]);
    }

    /**
     * Entry point to this test.
     *
     * @param args
     */
    public static void main(String[] args)
    {
        new OutputMessagesTest().doTests(args);
    }
}