view src/org/thermostat/qa/testsuites/DBGuiHeapDumpTest.java @ 147:7fa8af3d3e7d

renaming DBHeapDumpTest testsuite to DBGuiHeapDumpTest, adding DBCommandsHeapDumpTest testsuite
author Jana Fabrikova <jfabriko@redhat.com>
date Mon, 24 Feb 2014 17:50:01 +0100
parents
children 3d06e2d323cb
line wrap: on
line source

/*

    ThermostatQA - test framework for Thermostat Monitoring Tool

    Copyright 2014 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.awt.AWTException;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.List;






import org.thermostat.qa.annotations.StorageType;
import org.thermostat.qa.annotations.StorageTypes;
import org.thermostat.qa.annotations.TestType;
import org.thermostat.qa.annotations.TestTypes;
import org.thermostat.qa.framework.Assert;
import org.thermostat.qa.framework.GuiRobot;
import org.thermostat.qa.framework.Patterns;
import org.thermostat.qa.framework.ThermostatGuiTest;

/**
 * Class DBGuiHeapDumpTest
 * contains tests for checking the db scheme for thermostat mongodb
 * storage after a heap dump performed via thermostat gui.
 * The test starts storage and one agent and gui, opens a vm view
 * and clicks on the "dump a heap" button. 
 * Then all the collections that should not be empty after these
 * steps are checked - there should be a non-null record in each
 * (findOne() in the js script for mongo shell), and
 * its elements should be of the right types.
 *
 */
@TestType(TestTypes.GUI_TEST)
@StorageType(StorageTypes.MONGODB_STORAGE)
public class DBGuiHeapDumpTest extends ThermostatGuiTest
{
    
    private List<String> scriptOutput;
    private GuiRobot robot;
    
    private GuiRobot clickOnVMView() throws IOException, AWTException{
        //start storage
        GuiRobot robot = startStorageOnly();
        //start agent
        new AgentThread().start();
        logInfo("runAgentThread", "Thermostat Agent started");
               
        if (this.configuration.useDummyGfxTests())
        {
            robot.loadScreenshot("GuiStarted1");
        }
        else
        {
            //start gui
            runThermostatGuiInANewThread();
            sleep(15000);
            robot.createScreenCapture();
            robot.saveScreenshot("GuiStarted1");
        }

        //if only host icon is visible, click the '>' icon to see all its vms
        Rectangle r = findPattern(robot, Patterns.MainWindow.HOST_ICON_WITH_ARROW, "host view icon with arrow");
        if(r != null)
        {
            r.width = 6;
            robot.clickToRectangle(r);
            sleep(ONE_SEC);
            robot.createScreenCapture();
            robot.saveScreenshot("GuiStarted2");
        }
        
        r = checkForPattern(robot, Patterns.MainWindow.VM_VIEW_ICON, "vm view icon");
        robot.clickToRectangle(r);
        
        if (this.configuration.useDummyGfxTests())
        {
            robot.loadScreenshot("VMViewActive1");
        }
        else
        {
            sleep(2000);
            robot.createScreenCapture();
            robot.saveScreenshot("VMViewActive1");
        }
        
        checkForPattern(robot, Patterns.MainWindow.VM_VIEW_ICON_ACTIVE, "vm view active icon");
        robot.saveScreenshot("VMViewActive2");
        
        return robot;
    }

    private GuiRobot dumpAHeap() throws IOException, AWTException {
        
        robot = clickOnVMView();
        
        //click on Heap Analyzer tab
        Rectangle r = checkForPattern(robot, Patterns.VMView.HEAP_ANALYZER_TAB, "heap analyzer tab");
        robot.clickToRectangle(r);
        
        if (this.configuration.useDummyGfxTests())
        {
            robot.loadScreenshot("VMViewHeapAnalyzer1");
        }
        else
        {
            sleep(2000);
            robot.createScreenCapture();
            robot.saveScreenshot("VMViewHeapAnalyzer1");
        }
        
        checkForPattern(robot, Patterns.VMView.HEAP_ANALYZER_TAB_CHOSEN, "heap analyzer tab chosen");
        robot.saveScreenshot("VMViewHeapAnalyzer2");
        
        //click on Heap Dump button
        r = checkForPattern(robot, Patterns.VMViewHeapAnalyzerTab.HEAP_DUMP_LABEL, "vm view icon");
        robot.clickToRectangle(r);
     
        return robot;
    }
    
    @Override
    protected void tearDown()
    {

    }

    @Override
    protected void setUp()
    {
        // TODO
        //start storage and agent
        try
        {
            this.robot = dumpAHeap();
        }
        catch (IOException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        catch (AWTException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        
        

        //run js test script, get output
        try
        {
            scriptOutput = runCommandsInMongoShell("check-collection-heap-dump.js");
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        
        //stop the agent and storage
        try
        {
            //ADD END OF THE SITUATION HERE
            stopGUI(robot);
            runHelperBashScript("stop_all_therm_agents.sh");
            stopStorage();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public void testAgentConfig(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for agent-config is OK");
    }
    public void testBackendInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for backend-info is OK");
    }
    public void testCpuStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for cpu-stats is OK");
    }
    /*public void testFs.chunks(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for fs.chunks is OK");
    }
    public void testFs.files(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for fs.files is OK");
    }*/
    public void testHostInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for host-info is OK");
    }
    public void testMemoryStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for memory-stats is OK");
    }
    public void testNetworkInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for network-info is OK");
    }
    public void testNumaHostInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for numa-host-info is OK");
    }
    public void testNumaStat(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for numa-stat is OK");
    }
    public void testVmClassStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-class-stats is OK");
    }
    public void testVmCpuStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-cpu-stats is OK");
    }
    public void testVmGcStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-gc-stats is OK");
    }
    public void testVmHeapInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-heap-info is OK");
    }
    public void testVmInfo(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-info is OK");
    }
    public void testVmMemoryStats(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-memory-stats is OK");
    }
    public void testVmThreadCapabilities(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-thread-capabilities is OK");
    }
    public void testVmThreadHarvesting(){
        Assert.assertNotNull(scriptOutput, "problems running auxiliary script");
        checkPresenceOfPatternInTexts(scriptOutput, "schema for vm-thread-harvesting is OK");
    }
    
    public static void main(String[] args) {
        new DBGuiHeapDumpTest().doTests(args);
    }

}