view src/org/thermostat/qa2/tests/CliClientAgentInfoTest.java @ 180:aee16d21b7ad

adding a new testsuite for list-agents, agent-info in thermostat shell
author Jana Fabrikova <jfabriko@redhat.com>
date Wed, 06 May 2015 09:50:46 +0200
parents
children 5d335809cd51
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.tests;

import java.io.File;
import java.util.List;

import org.thermostat.qa2.framework.Assert;
import org.thermostat.qa2.framework.NativeProcess;
import org.thermostat.qa2.framework.Shell;
import org.thermostat.qa2.framework.ThermostatQAConfig;
import org.thermostat.qa2.framework.annotations.SetupStorage;
import org.thermostat.qa2.framework.annotations.RunGnomeKeyring;
import org.thermostat.qa2.framework.annotations.RunStorage;
import org.thermostat.qa2.framework.annotations.Test;
import org.thermostat.qa2.framework.annotations.RunAgent;
import org.thermostat.qa2.framework.utils.ProcessUtilities;

/**
 * Test class using thermostat shell - testing commands list-agents
 * and agents-info.
 * 
 * @author jfabriko
 */
@SetupStorage(type = "mongo")
@RunGnomeKeyring
@RunStorage
public class CliClientAgentInfoTest {

    String[] patternListAgents = {
            "Thermostat version ",
            "Thermostat - > list-agents",
            "Please enter username for storage at ",
            "Please enter password for storage at ",
            "Agent ID",
            "Command Channel",
            "Address",
            "Start Time",
            "Stop Time",
            "Currently Active",
            "Thermostat + > exit"};
    String[] patternAgentInfo = {
            "Thermostat version ",
            "Thermostat - > agent-info -a ",
            "Please enter username for storage at ",
            "Please enter password for storage at ",
            "Agent ID ",
            "Command Channel Address ",
            "Start Time ",
            "Stop Time               Currently Active",                                    
            "Backend                    Status Description",
            "System Backend             Active Gathers basic information from the system",
            "Host CPU Backend           Active Gathers CPU statistics about a host",
            "VM CPU Backend             Active Gathers CPU statistics about a JVM",
            "Host Memory Backend        Active Gathers memory statistics about a host",
            "VM GC Backend              Active Gathers garbage collection statistics about a JVM",
            "VM Classes Backend         Active Gathers class loading statistics about a JVM",
            "VM Memory Backend          Active Gathers memory statistics about a JVM",
            "NUMA Backend               Active Gathers NUMA statistics about a host",
            "VM IO Backend              Active Gathers IO statistics about a JVM",
            "VM Thread Counting Backend Active Gathers thread counts for a JVM",
            "VM Thread Backend          Active Gathers thread information about a JVM",
            "VM JMX Backend             Active gathers JMX information using JMX",
            "Thermostat + > exit"};

   
    public String getAgentIdFromListAgents() throws Exception{

        ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin();
        String name = login.getUsername();
        String passwd = login.getPassword();
        
        //shell list agents
        Shell thermostat = ProcessUtilities.createThermostatShell();
        thermostat.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome());
        thermostat.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
        thermostat.start();
        thermostat.writeln("list-agents");
        thermostat.writeln(name);
        thermostat.writeln(passwd);
        thermostat.writeln("exit");
        thermostat.waitFor();

        List<String> output = thermostat.getStdoutLines();
        
        //check output
        Assert.assertContainsPatterns(output, patternListAgents);
        
        //preparate agent id
        return output.get(5).split(" ")[0];
    }
    
    public void checkAgentInfo(String agentId) throws Exception {
        ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin();
        
        Shell thermostat = ProcessUtilities.createThermostatShell();
        thermostat.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome());
        thermostat.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER);
        thermostat.start();
        thermostat.writeln("agent-info -a "+agentId);
        thermostat.writeln(login.getUsername());
        thermostat.writeln(login.getPassword());
        thermostat.writeln("exit");
        thermostat.waitFor();
        
        List<String> output = thermostat.getStdoutLines();
           
        //check agent info in output
        Assert.assertContainsPatterns(output, patternAgentInfo);
        
    }
    
    @Test
    @RunAgent
    public void agentInfo() throws Exception {
        //get the login data
        String agentId = getAgentIdFromListAgents(); 
              
        //run shell again + agent info
        checkAgentInfo(agentId);
    }
}