Mercurial > hg > ThermostatQA
view src/org/thermostat/qa/testsuites/CliClientDBModifWebStorageTest.java @ 152:1191b3a92ad1
miscellaneous smaller modifications
author | Jana Fabrikova <jfabriko@redhat.com> |
---|---|
date | Tue, 01 Apr 2014 15:42:00 +0200 |
parents | 8612e27034af |
children | 19c8294a826f |
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.awt.AWTException; 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.ThermostatTest; import org.thermostat.qa.annotations.TillVersion; import org.thermostat.qa.annotations.SinceVersion; /** * Class CliClientDBModifWebStorageTest * tests if the changes made in the database are reflected in Thermostat * shell output, when the shell client uses web storage. * */ @StorageType(StorageTypes.WEBTOMCAT_STORAGE) public class CliClientDBModifWebStorageTest extends ThermostatTest { @Override protected void tearDown() { try { restoreNormalStorageConfigFiles(); runHelperBashScript("stop_all_therm_agents.sh"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override protected void setUp() { //setCheckedStrings(); try { eraseTomcatOutputFiles(); prepareWebStorageConfigFiles(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Method testAddVMAndSeeItInShellTest * tests if a virtual machine added to the thermostat database is visible * in the shell connected to web storage if the command list-vms is issued. * The method adds a vm and a host into the vm-info and host-info * collections of the thermostat database (mongodb) respectively and deletes * the new items after the tests. * * This method uses scripts and files * <ul> * <li><a href="scripts/find_mongo_port.sh">find_mongo_port.sh</a>, * <li><a href="scripts/add_vm.sh">add_vm2.sh</a>, * <li><a href="scripts/add_vm_db_commands.txt">add_vm_db_commands2.txt</a>, * <li><a href="scripts/list-vms_therm_shell.txt">list-vms_therm_shell.txt</a>, * <li><a href="scripts/delete_added_vm.sh">delete_added_vm.sh</a>, * <li><a href="scripts/remove_vm_db_commands.txt">remove_vm_db_commands.txt</a> * <ul> * and rewrites one text file * <a href="scripts/mongoPortNumber.txt">mongoPortNumber.txt</a>. * and one script file * <a href="scripts/run_thermostat_shell_with_commands.sh">run_thermostat_shell_with_commands.sh</a>. * * @throws IOException * @throws AWTException */ @TillVersion("0.18.1") @StorageType(StorageTypes.WEBTOMCAT_STORAGE) public void testAddVMAndSeeItInShellTest() throws IOException, AWTException { String commands = "list-vms_therm_shell.txt"; String[] header = new String[] { "HOST_ID", "HOST", "VM_ID", "STATUS", "VM_NAME" }; int headerLineNum = 2; String[] findStrings = new String[] { "non-existing-agent-no1", "artif.added.host0.name", "12345", "RUNNING", "unknown" }; genericTest(commands, header, headerLineNum, findStrings ); } /** * Method testAddVMAndSeeItInShellTest2 * tests if a virtual machine added to the thermostat database is visible * in the shell connected to web storage if the command list-vms is issued. * The method adds a vm and a host into the vm-info and host-info * collections of the thermostat database (mongodb) respectively and deletes * the new items after the tests. Difference between this method and * testAddVMAndSeeItInShellTest is that the test issues login+password * to the thermostat shell after the command list-vms. * * This method uses scripts and files * <ul> * <li><a href="scripts/find_mongo_port.sh">find_mongo_port.sh</a>, * <li><a href="scripts/add_vm.sh">add_vm2.sh</a>, * <li><a href="scripts/add_vm_db_commands.txt">add_vm_db_commands2.txt</a>, * <li><a href="scripts/list-vms_therm_shell3.txt">list-vms_therm_shell3.txt</a>, * <li><a href="scripts/delete_added_vm.sh">delete_added_vm.sh</a>, * <li><a href="scripts/remove_vm_db_commands.txt">remove_vm_db_commands.txt</a> * <ul> * and rewrites one text file * <a href="scripts/mongoPortNumber.txt">mongoPortNumber.txt</a>. * and one script file * <a href="scripts/run_thermostat_shell_with_commands.sh">run_thermostat_shell_with_commands.sh</a>. * * @throws IOException * @throws AWTException */ @SinceVersion("1.0.0") @StorageType(StorageTypes.WEBTOMCAT_STORAGE) public void testAddVMAndSeeItInShellTest2() throws IOException, AWTException { String commands = "list-vms_therm_shell3.txt"; String[] header = new String[] { "HOST_ID", "HOST", "VM_ID", "STATUS", "VM_NAME" }; int headerLineNum = 4; String[] findStrings = new String[] { "non-existing-agent-no1", "artif.added.host0.name", "12345", "RUNNING", "unknown" }; genericTest(commands, header, headerLineNum, findStrings ); } /** * Method testBadLogin * tests if the thermostat shell with web storage does not let user with * empty user name and password call list-vms and get a result. * User should use nonempty login + password from the configuration file * for web storage. * * This method uses scripts and files * <ul> * <li><a href="scripts/find_mongo_port.sh">find_mongo_port.sh</a>, * <li><a href="scripts/add_vm.sh">add_vm2.sh</a>, * <li><a href="scripts/add_vm_db_commands.txt">add_vm_db_commands2.txt</a>, * <li><a href="scripts/list-vms_therm_shell3.txt">list-vms_therm_shell3.txt</a>, * <li><a href="scripts/delete_added_vm.sh">delete_added_vm.sh</a>, * <li><a href="scripts/remove_vm_db_commands.txt">remove_vm_db_commands.txt</a> * <ul> * and rewrites one text file * <a href="scripts/mongoPortNumber.txt">mongoPortNumber.txt</a>. * and one script file * <a href="scripts/run_thermostat_shell_with_commands.sh">run_thermostat_shell_with_commands.sh</a>. * * @throws IOException * @throws AWTException */ @SinceVersion("1.1.0") @StorageType(StorageTypes.WEBTOMCAT_STORAGE) public void testBadLogin() throws IOException, AWTException { String commands = "list-vms_therm_shell2.txt"; String[] header = new String[] { "Thermostat >", "exit" }; int headerLineNum = 4; String[] findStrings = null; genericTest(commands, header, headerLineNum, findStrings ); } private void genericTest(String commands, String[] checkedHeaderStrings, int lineNumberWhereCheck, String[] findStringsAnywhere) throws IOException { // start web storage startWebStorage(); sleep(2000); // find out on which port to connect to db and add new vm to db List<String> output1 = runHelperBashScript("find_mongo_port.sh"); for (String s : output1) { logInfo("run", "Finding mongo port: " + s); } output1 = runHelperBashScript("add_vm2.sh"); for (String s : output1) { logInfo("run", "Adding vm to mongo: " + s); } sleep(2000); // run shell command list-vms output1 = runCommandsInThermostatShell(commands); // test the output + some logging Assert.assertNotNull(output1, "error getting standard output"); for (String s : output1) { logInfo("run", "Thermostat shell: " + s); } String headerLine = output1.get(lineNumberWhereCheck); for (String headerElem : checkedHeaderStrings) { Assert.assertTrue(headerLine.contains(headerElem), headerElem + " not in the beginning of thermostat shell output"); } if( null != findStringsAnywhere) { boolean wantedOutputPresent = false; for(String line : output1) { wantedOutputPresent = wantedOutputPresent || checkPresenceOfPatterns(line, findStringsAnywhere); } Assert.assertTrue(wantedOutputPresent," wanted string not listed in the output"); } // remove the added vm from db List<String> output2 = runHelperBashScript("delete_added_vm.sh"); for (String s : output2) { logInfo("run", "Deleting vm from mongo: " + s); } stopWebStorage(); } public static void main(String[] args) { new CliClientDBModifWebStorageTest().doTests(args); } }