Mercurial > hg > ThermostatQA
view src/org/thermostat/qa2/tests/CommandChannelSmokeTest.java @ 171:1d7ab9111fd2
- added tests ported to the new framework (package org.thermostat.qa2.tests)
- added/updated required targets in Makefile
- new info about dependecies added to README.md
- authorization and error checking code added to mongo js scripts
- done necessary changes to reporter, so it can be used with new framework
- updated keyrings
- added required pattern (for gui tests)
author | Zdenek Zambersky <zzambers@redhat.com> |
---|---|
date | Tue, 10 Mar 2015 13:48:12 +0100 |
parents | |
children | a74aa91ab44c |
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.util.List; import org.thermostat.qa2.framework.Assert; import static 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.services.ThermostatAgent; import org.thermostat.qa2.framework.utils.ProcessUtilities; import org.thermostat.qa2.framework.utils.ThermostatUtilities; /** * Test class ported from old framework * @author Zdeněk Žamberský */ public class CommandChannelSmokeTest { static final String[] patternRunningAgent = new String[]{ "Please enter username for storage at mongodb://127.0.0.1:", "Please enter password for storage at mongodb://127.0.0.1:", "Queuing ping request. Destination: /127.0.0.1:12000", "Response received from: /127.0.0.1:12000" }; static final String[] patternStoppedAgent = new String[]{ "Please enter username for storage at mongodb://127.0.0.1:", "Please enter password for storage at mongodb://127.0.0.1:", "Invalid host ID or agent no longer running." // new //"Queuing ping request. Destination: /127.0.0.1:12000", //"Error received from: /127.0.0.1:12000" }; public static List<String> pingHost(String hostId, String username, String password) throws Exception { String[] pingCmds = {ThermostatQAConfig.getThermostatExecutablePath(), "ping", hostId}; Shell ping = new Shell(pingCmds); ping.setEnvironmentVariable("USER_THERMOSTAT_HOME", ThermostatQAConfig.getThermostatUserHome()); ping.setStdOutMode(NativeProcess.MODE_LOG_AND_BUFFER); ping.start(); ping.writeln(username); ping.writeln(password); ping.waitFor(); return ping.getStdoutLines(); } public static void pingAgentImpl(String username, String password, String[] patternsRunning, String[] patternsStopped) throws Exception { ThermostatAgent agent = new ThermostatAgent(); agent.start(); Assert.assertRuns(agent, "Agent should be running"); List<String> pidLines = ProcessUtilities.shellRunGetOutput("jps | grep Thermostat | cut -d' ' -f1"); List<String> vmsLines = ThermostatUtilities.getListVmsOutput(); String hostId = null; for (String vmsLine : vmsLines) { if (vmsLine.contains("RUNNING")) { for (String pid : pidLines) { if (vmsLine.contains(pid)) { hostId = vmsLine.split(" ")[0]; } } } } assertTrue(hostId != null, "hostId of agent was not found"); List<String> ping1Lines = pingHost(hostId, username, password); agent.stop(); List<String> ping2Lines = pingHost(hostId, username, password); assertContainsPatterns(ping1Lines, patternsRunning); assertContainsPatterns(ping2Lines, patternsStopped); } @Test @SetupStorage(type = "mongo") @RunStorage @RunGnomeKeyring public void pingAgent() throws Exception { ThermostatQAConfig.Login login = ThermostatQAConfig.getClientLogin(); pingAgentImpl(login.getUsername(), login.getPassword(), patternRunningAgent, patternStoppedAgent); } }