Mercurial > hg > ThermostatQA
changeset 73:e5fc1bf81ded
adding 2 testcases to AgentTest
author | Jana Fabrikova <jfabriko@redhat.com> |
---|---|
date | Thu, 13 Jun 2013 17:02:56 +0200 |
parents | 5a3bad83880f |
children | 768acb232957 |
files | ChangeLog Makefile scripts/list_all_therm_agents.sh scripts/stop_all_therm_agents.sh src/org/thermostat/qa/framework/ThermostatTest.java src/org/thermostat/qa/testsuites/AgentTest.java |
diffstat | 6 files changed, 131 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Jun 13 11:20:28 2013 +0200 +++ b/ChangeLog Thu Jun 13 17:02:56 2013 +0200 @@ -1,3 +1,16 @@ +2013-06-13 Jana Fabrikova <jfabriko@redhat.com> + + * src/org/thermostat/qa/framework/ThermostatTest.java: + adding AgentThread simillar to existing GuiThread, only the exit value + is not checked + * src/org/thermostat/qa/testsuites/AgentTest.java: + adding 2 testcases (testStartWithoutStorage) and (testStartAgent) + * scripts/list_all_therm_agents.sh: + * scripts/stop_all_therm_agents.sh: + auxiliary shell scripts + * Makefile: + adding the AgentTest to runtests goal + 2013-06-13 Jana Fabrikova <jfabriko@redhat.com> * src/org/thermostat/qa/testsuites/StorageSmokeTest.java:
--- a/Makefile Thu Jun 13 11:20:28 2013 +0200 +++ b/Makefile Thu Jun 13 17:02:56 2013 +0200 @@ -33,6 +33,7 @@ TESTS = \ SmokeTests \ + AgentTest \ StorageSmokeTest \ GuiClientSmokeTest \ CliClientSmokeTest \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/list_all_therm_agents.sh Thu Jun 13 17:02:56 2013 +0200 @@ -0,0 +1,2 @@ +jps | grep Thermostat +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/stop_all_therm_agents.sh Thu Jun 13 17:02:56 2013 +0200 @@ -0,0 +1,2 @@ +kill $(jps | grep Thermostat | cut -d' ' -f1) +
--- a/src/org/thermostat/qa/framework/ThermostatTest.java Thu Jun 13 11:20:28 2013 +0200 +++ b/src/org/thermostat/qa/framework/ThermostatTest.java Thu Jun 13 17:02:56 2013 +0200 @@ -87,12 +87,12 @@ protected Configuration configuration = null; /** - * Set up the test suite. To be implemented by concrete test cases. + * Set up the test suite. To be implemented by specific test cases. */ protected abstract void setUp(); /** - * Tear down the test suite. To be implemented by concrete test cases. + * Tear down the test suite. To be implemented by specific test cases. */ protected abstract void tearDown(); @@ -167,6 +167,32 @@ } } } + + public class AgentThread extends Thread + { + @Override + public void run() + { + Process process; + try + { + process = runThermostatInNewProcess("agent"); + List<String> processOutput = readProcessOutput(process); + sleep(ONE_SEC); + Assert.assertNotNull(processOutput, "no output from process"); +// int exitValue = process.exitValue(); +// Assert.assertEquals(exitValue, EXPECTED_EXIT_VALUE, "Bad thermostat exit value " + exitValue); + } + catch (IOException e) + { + e.printStackTrace(); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + } /** * Run all tests found in the current test suite. @@ -432,7 +458,7 @@ bufferedReader.close(); return out; } - + /** * * @param line1
--- a/src/org/thermostat/qa/testsuites/AgentTest.java Thu Jun 13 11:20:28 2013 +0200 +++ b/src/org/thermostat/qa/testsuites/AgentTest.java Thu Jun 13 17:02:56 2013 +0200 @@ -32,11 +32,28 @@ package org.thermostat.qa.testsuites; +import java.io.IOException; +import java.util.List; + + + +import org.thermostat.qa.framework.Assert; import org.thermostat.qa.framework.ThermostatTest; +import org.thermostat.qa.framework.ThermostatTest.GuiThread; +/** + * Class AgentTest + * contains basic smoke tests for starting the Thermostat agent. Starting the agent without + * storage (which should not work) and with storage is checked. + * + */ public class AgentTest extends ThermostatTest { - + private static final String[] THERMOSTAT_AGENT_WITHOUT_STORAGE_MESSAGE = new String[] { + "list of commands:", + "" + }; + @Override protected void tearDown() { @@ -51,9 +68,73 @@ } - public void testX() + /** + * Method testStartWithoutStorage + * tries to start thermostat agent in new thread without previously + * starting the storage. There should be no thermostat agents running. + * + * This test uses the following scripts: + * <ul> + * <li><a href="../../../../../../scripts/list_all_therm_agents.sh">list_all_therm_agents.sh</a>, + * <li><a href="../../../../../../scripts/stop_all_therm_agents.sh">stop_all_therm_agents.sh</a>. + * <ul> + * + * @throws IOException + */ + public void testStartWithoutStorage() throws IOException { - System.out.println("XXX"); + //start only agent + new AgentThread().start(); + logInfo("runAgentThread", "Thermostat Agent started"); + + //wait till agent stops + sleep(FIVE_SEC); + + //there should not be any agent running (check the jps) + List<String> output = runHelperBashScript("list_all_therm_agents.sh"); + Assert.assertNotNull(output, "error running script 'list_all_therm_agents.sh'"); + for (String message : output) + { + logInfo("Agent list:", message); + } + Assert.assertTrue(output.size()==0, "there should not be any running thermostat agents"); + } + + /** + * Method testStartAgent + * starts the storage and then tries to start thermostat agent in a new + * thread. There should be one thermostat agent running. + * + * This test uses the following scripts: + * <ul> + * <li><a href="../../../../../../scripts/list_all_therm_agents.sh">list_all_therm_agents.sh</a>, + * <li><a href="../../../../../../scripts/stop_all_therm_agents.sh">stop_all_therm_agents.sh</a>. + * <ul> + * + * @throws IOException + */ + public void testStartAgent() throws IOException + { + startStorage(); + + //start agent + new AgentThread().start(); + logInfo("runAgentThread", "Thermostat Agent started"); + + //check if the agent is running (jps) + List<String> output = runHelperBashScript("list_all_therm_agents.sh"); + Assert.assertNotNull(output, "error running script 'list_all_therm_agents.sh'"); + Assert.assertTrue(output.size()>0, "there should be >0 running thermostat agents"); + + //stop the agent + output = runHelperBashScript("stop_all_therm_agents.sh"); + Assert.assertNotNull(output, "error running script 'stop_all_therm_agents.sh'"); + + stopStorage(); + } + + public static void main(String[] args) { + new AgentTest().doTests(args); } }