changeset 130:8612e27034af

adding new testcases and refactoring of the CliClientDBModifWebStorageTest testsuite
author Jana Fabrikova <jfabriko@redhat.com>
date Thu, 28 Nov 2013 17:29:33 +0100
parents 167a4f9adb46
children 86af136ea500
files ChangeLog scripts/list-vms_therm_shell3.txt src/org/thermostat/qa/testsuites/CliClientDBModifWebStorageTest.java
diffstat 3 files changed, 124 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Nov 28 16:15:14 2013 +0100
+++ b/ChangeLog	Thu Nov 28 17:29:33 2013 +0100
@@ -1,3 +1,18 @@
+2013-11-28  Jana Fabrikova <jfabriko@redhat.com>
+
+	* src/org/thermostat/qa/testuites/CliClientDBModifWebStorageTest.java:
+	adding annotation TillVersion 0.18.1 to (testAddVMAndSeeItInShellTest),
+	adding new version (testAddVMAndSeeItInShellTest2) with annotation
+	SinceVersion 1.1.0 - added behaviour is issuing login client-tester and
+	password for the thermostat shell when attempting to call list-vms,
+	adding new testcase (testBadLogin) with annotation SinceVersion 1.1.0
+	that issues empty strings as login+password, so the vms should not
+	be listed in the output,
+	refactoring of the three testcases, adding method (generalTest) to avoid
+	duplicity of the code
+	* scripts/list-vms_therm_shell3.txt
+	auxiliary script containing thermostat shell commands for the new test
+
 2013-11-28  Jana Fabrikova <jfabriko@redhat.com>
 
 	* src/org/thermostat/qa/testuites/CliClientDBModificationsSmokeTest.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/list-vms_therm_shell3.txt	Thu Nov 28 17:29:33 2013 +0100
@@ -0,0 +1,5 @@
+list-vms
+client-tester
+heslo2
+exit
+
--- a/src/org/thermostat/qa/testsuites/CliClientDBModifWebStorageTest.java	Thu Nov 28 16:15:14 2013 +0100
+++ b/src/org/thermostat/qa/testsuites/CliClientDBModifWebStorageTest.java	Thu Nov 28 17:29:33 2013 +0100
@@ -41,20 +41,14 @@
 
 
 
-
-
-
-
-
-
-
-
 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;
 
 
 /**
@@ -124,8 +118,97 @@
      * @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.1.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);
@@ -142,7 +225,7 @@
         }
                
         // run shell command list-vms
-        output1 = runCommandsInThermostatShell("list-vms_therm_shell.txt");
+        output1 = runCommandsInThermostatShell(commands);
         
         // test the output + some logging
         Assert.assertNotNull(output1, "error getting standard output");
@@ -151,19 +234,22 @@
             logInfo("run", "Thermostat shell: " +  s);
         }
         
-        String headerLine = output1.get(2);
-        for (String headerElem : new String[] { "HOST_ID", "HOST", "VM_ID", "STATUS", "VM_NAME" })
+        String headerLine = output1.get(lineNumberWhereCheck);
+        for (String headerElem : checkedHeaderStrings)
         {
-            Assert.assertTrue(headerLine.contains(headerElem), headerElem + " not in the header of thermostat shell output");
+            Assert.assertTrue(headerLine.contains(headerElem), headerElem + " not in the beginning of thermostat shell output");
         }
         
-        boolean addedVmPresent = false;
-        for(String vmsLine : output1)
+        if( null != findStringsAnywhere)
         {
-            addedVmPresent = addedVmPresent || checkPresenceOfPatterns(vmsLine, new String[] { "non-existing-agent-no1", "artif.added.host0.name", "12345", "RUNNING", "unknown" });
+            boolean wantedOutputPresent = false;
+            for(String line : output1)
+            {
+                wantedOutputPresent = wantedOutputPresent || checkPresenceOfPatterns(line, findStringsAnywhere);
+            }
+            Assert.assertTrue(wantedOutputPresent," wanted string not listed in the output");
         }
-        Assert.assertTrue(addedVmPresent," added vm not listed in the output");
-                
+        
         // remove the added vm from db
         List<String> output2 = runHelperBashScript("delete_added_vm.sh");
         for (String s : output2)
@@ -171,7 +257,7 @@
             logInfo("run", "Deleting vm from mongo: " +  s);
         }
 
-        stopWebStorage();
+        stopWebStorage();        
         
     }