changeset 102:18a11b9d62ea

Refactoring, moved common methods into ThermostatTest so they could be used by the other tests too. Fixed some minor warnings.
author Pavel Tisnovsky <ptisnovs@redhat.com>
date Mon, 30 Sep 2013 10:22:07 +0200
parents f3437c7ad3da
children befe5e58f30f
files ChangeLog src/org/thermostat/qa/framework/ThermostatTest.java src/org/thermostat/qa/testsuites/CliClientSmokeTest.java src/org/thermostat/qa/testsuites/OutputMessagesTest.java
diffstat 4 files changed, 81 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 27 11:00:46 2013 +0200
+++ b/ChangeLog	Mon Sep 30 10:22:07 2013 +0200
@@ -1,3 +1,11 @@
+2013-09-30  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/org/thermostat/qa/framework/ThermostatTest.java:
+	* src/org/thermostat/qa/testsuites/CliClientSmokeTest.java:
+	* src/org/thermostat/qa/testsuites/OutputMessagesTest.java:
+	Refactoring, moved common methods into ThermostatTest so they could be
+	used by the other tests too. Fixed some minor warnings.
+
 2013-09-27  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/thermostat/qa/testsuites/AgentTest.java:
--- a/src/org/thermostat/qa/framework/ThermostatTest.java	Fri Sep 27 11:00:46 2013 +0200
+++ b/src/org/thermostat/qa/framework/ThermostatTest.java	Mon Sep 30 10:22:07 2013 +0200
@@ -261,7 +261,8 @@
     }
 
     /**
-     * 
+     * Comparison of two strings/lines.
+     *
      * @param line1
      * @param line2
      * @throws AssertionError
@@ -270,7 +271,23 @@
     {
         Assert.assertEquals(line1, line2, line1 + " != " + line2);
     }
-    
+  
+    /**
+     * Comparison of contents of list of strings against array of strings.
+     *
+     * @param list
+     * @param wantedArr
+     */
+    protected void compareListAndArrayOfStrings(List<String> list, String[] wantedArr)
+    {
+        int i = 0;
+        for(String wanted : wantedArr)
+        {
+            compareTwoLines(list.get(i), wanted);
+            i++;
+        }
+    }
+  
     /**
      * Method checkPresenceOfPatterns returns true iff all the patterns are
      * present in text.
--- a/src/org/thermostat/qa/testsuites/CliClientSmokeTest.java	Fri Sep 27 11:00:46 2013 +0200
+++ b/src/org/thermostat/qa/testsuites/CliClientSmokeTest.java	Mon Sep 30 10:22:07 2013 +0200
@@ -59,7 +59,7 @@
 {
     public static final String[] allscripts = new String[] {"exit_therm_shell.txt", "help_therm_shell.txt"};
     private String pathToOutputTexts;
-    private String[] THERMOSTAT_SHELL_HELP_MESSAGE, THERMOSTAT_SHELL_EXIT_MESSAGE;
+    private String[] thermostatShellHelpMessage, thermostatShellExitMessage;
 
     @Override
     protected void tearDown()
@@ -71,9 +71,9 @@
     @Override
     protected void setUp()
     {
-        pathToOutputTexts = "outputtexts/"+this.configuration.getThermostatOutputTextsVersion()+"/";
-        THERMOSTAT_SHELL_HELP_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(pathToOutputTexts+"output_of_help_therm_shell.txt");
-        THERMOSTAT_SHELL_EXIT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(pathToOutputTexts+"output_of_exit_therm_shell.txt");
+        this.pathToOutputTexts = "outputtexts/"+this.configuration.getThermostatOutputTextsVersion()+"/";
+        this.thermostatShellHelpMessage = FileUtils.getStringArrayFromOutputTextFile(this.pathToOutputTexts+"output_of_help_therm_shell.txt");
+        this.thermostatShellExitMessage = FileUtils.getStringArrayFromOutputTextFile(this.pathToOutputTexts+"output_of_exit_therm_shell.txt");
     }
     
     /**
@@ -100,9 +100,10 @@
             logInfo("run", "Thermostat shell: " +  s);
         }
         
-        Assert.assertTrue(output.size()>=THERMOSTAT_SHELL_EXIT_MESSAGE.length, "too few lines in the thermostat shell output");
+        Assert.assertTrue(output.size() >= this.thermostatShellExitMessage.length,
+                        "too few lines in the thermostat shell output");
                 
-        compareListAndArrayOfStrings(output, THERMOSTAT_SHELL_EXIT_MESSAGE);
+        compareListAndArrayOfStrings(output, this.thermostatShellExitMessage);
         
         stopStorage();
     }
@@ -131,23 +132,14 @@
             logInfo("run", "Thermostat shell: " +  s);
         }
         
-        Assert.assertTrue(output.size()>=THERMOSTAT_SHELL_HELP_MESSAGE.length, "too few lines in the thermostat shell output");
+        Assert.assertTrue(output.size() >= this.thermostatShellHelpMessage.length,
+                        "too few lines in the thermostat shell output");
         
-        compareListAndArrayOfStrings(output, THERMOSTAT_SHELL_HELP_MESSAGE);
+        compareListAndArrayOfStrings(output, this.thermostatShellHelpMessage);
         
         stopStorage();
     }
     
-    private void compareListAndArrayOfStrings(List<String> list, String[] wantedArr)
-    {
-        int i = 0;
-        for(String wanted : wantedArr)
-        {
-            compareTwoLines(list.get(i), wanted);
-            i++;
-        }
-    }
-  
     public static void main(String[] args) {
         new CliClientSmokeTest().doTests(args);
     }
--- a/src/org/thermostat/qa/testsuites/OutputMessagesTest.java	Fri Sep 27 11:00:46 2013 +0200
+++ b/src/org/thermostat/qa/testsuites/OutputMessagesTest.java	Mon Sep 30 10:22:07 2013 +0200
@@ -45,14 +45,13 @@
 import org.thermostat.qa.framework.ThermostatTest;
 import org.thermostat.qa.reporter.FileUtils;
 
+
+
 /**
  * Class OutputMessagesTest 
- * contains testcases for checking the output messages after issuing thermostat
- * help commands in a command line.  
- *
+ * contains testcases for checking the output messages written to the
+ * standard output after issuing thermostat help commands in a command line.
  */
-
-
 @TestType(TestTypes.CLI_TEST)
 public class OutputMessagesTest extends ThermostatTest
 {
@@ -81,9 +80,10 @@
         {"help", "vm-info"},
         {"help", "vm-stat"},
         {"help", "webservice"} };
-    
+
     private String outputsPath;
-    private String[] THERMOSTAT_STANDARD_MESSAGE, 
+
+    private static String[] THERMOSTAT_STANDARD_MESSAGE, 
     THERMOSTAT_HELP_MESSAGE, 
     THERMOSTAT_HELP_AGENT_MESSAGE, 
     THERMOSTAT_HELP_CONNECT_MESSAGE, 
@@ -108,28 +108,28 @@
     @Override
     protected void setUp()
     {
-        outputsPath = "outputtexts/"+this.configuration.getThermostatOutputTextsVersion()+"/";
-        THERMOSTAT_STANDARD_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat.txt");
-        THERMOSTAT_HELP_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help.txt");
-        THERMOSTAT_HELP_AGENT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_agent.txt");
-        THERMOSTAT_HELP_CONNECT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_connect.txt");
-        THERMOSTAT_HELP_DISCONNECT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_disconnect.txt"); 
-        THERMOSTAT_HELP_DUMP_HEAP_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_dump-heap.txt");
-        THERMOSTAT_HELP_FIND_OBJECTS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_find-objects.txt");
-        THERMOSTAT_HELP_FIND_ROOT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_find-root.txt");
-        THERMOSTAT_HELP_GUI_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_gui.txt");
-        THERMOSTAT_HELP_LIST_HEAP_DUMPS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_list-heap-dumps.txt");
-        THERMOSTAT_HELP_LIST_VMS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_list-vms.txt");
-        THERMOSTAT_HELP_OBJECT_INFO_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_object-info.txt");
-        THERMOSTAT_HELP_PING_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_ping.txt");
-        THERMOSTAT_HELP_SAVE_HEAP_DUMP_TO_FILE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_save-heap-dump-to-file.txt");
-        THERMOSTAT_HELP_SERVICE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_service.txt");
-        THERMOSTAT_HELP_SHELL_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_shell.txt");
-        THERMOSTAT_HELP_SHOW_HEAP_HISTOGRAM_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_show-heap-histogram.txt");
-        THERMOSTAT_HELP_STORAGE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_storage.txt");
-        THERMOSTAT_HELP_VM_INFO_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_vm-info.txt");
-        THERMOSTAT_HELP_VM_STAT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_vm-stat.txt");
-        THERMOSTAT_HELP_WEBSERVICE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(outputsPath+"thermostat_help_webservice.txt");
+        this.outputsPath = "outputtexts/"+this.configuration.getThermostatOutputTextsVersion()+"/";
+        THERMOSTAT_STANDARD_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat.txt");
+        THERMOSTAT_HELP_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help.txt");
+        THERMOSTAT_HELP_AGENT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_agent.txt");
+        THERMOSTAT_HELP_CONNECT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_connect.txt");
+        THERMOSTAT_HELP_DISCONNECT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_disconnect.txt"); 
+        THERMOSTAT_HELP_DUMP_HEAP_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_dump-heap.txt");
+        THERMOSTAT_HELP_FIND_OBJECTS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_find-objects.txt");
+        THERMOSTAT_HELP_FIND_ROOT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_find-root.txt");
+        THERMOSTAT_HELP_GUI_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_gui.txt");
+        THERMOSTAT_HELP_LIST_HEAP_DUMPS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_list-heap-dumps.txt");
+        THERMOSTAT_HELP_LIST_VMS_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_list-vms.txt");
+        THERMOSTAT_HELP_OBJECT_INFO_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_object-info.txt");
+        THERMOSTAT_HELP_PING_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_ping.txt");
+        THERMOSTAT_HELP_SAVE_HEAP_DUMP_TO_FILE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_save-heap-dump-to-file.txt");
+        THERMOSTAT_HELP_SERVICE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_service.txt");
+        THERMOSTAT_HELP_SHELL_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_shell.txt");
+        THERMOSTAT_HELP_SHOW_HEAP_HISTOGRAM_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_show-heap-histogram.txt");
+        THERMOSTAT_HELP_STORAGE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_storage.txt");
+        THERMOSTAT_HELP_VM_INFO_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_vm-info.txt");
+        THERMOSTAT_HELP_VM_STAT_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_vm-stat.txt");
+        THERMOSTAT_HELP_WEBSERVICE_MESSAGE = FileUtils.getStringArrayFromOutputTextFile(this.outputsPath+"thermostat_help_webservice.txt");
     }
 
     @Override
@@ -156,6 +156,15 @@
         }
     }
 
+    /**
+     * Read message written by the Thermostat CLI client to the standard output
+     * and compare those messages with the given template.
+     *
+     * @param template template containing expected messages
+     * @param flags flags passed to the Thermostat CLI client
+     * @throws IOException
+     * @throws AssertionError thrown when the given template is different from actual messages
+     */
     private void readAndCheckThermostatMessage(String[] template, String... flags) throws IOException, AssertionError
     {
         Process process = runThermostatInNewProcess(flags);
@@ -383,7 +392,7 @@
     {
         readAndCheckThermostatMessage(THERMOSTAT_HELP_VM_STAT_MESSAGE, allflags[19]);
     }
-    
+
     /**
      * Method testCheckHelpWebserviceMessage
      * checks output of command "thermostat help webservice".
@@ -395,6 +404,11 @@
         readAndCheckThermostatMessage(THERMOSTAT_HELP_WEBSERVICE_MESSAGE, allflags[20]);
     }
 
+    /**
+     * Entry point to this test.
+     *
+     * @param args
+     */
     public static void main(String[] args)
     {
         new OutputMessagesTest().doTests(args);