diff --git a/plugins/TestingList.java b/plugins/TestingList.java index c9be13b..c587a19 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -2,6 +2,7 @@ * Copyright (c) 2015 Paul Scherrer Institute. All rights reserved. */ // + import ch.psi.pshell.core.Controller; import ch.psi.utils.swing.MonitoredPanel; import ch.psi.pshell.ui.Panel; @@ -41,6 +42,7 @@ import org.apache.commons.io.FilenameUtils; import org.python.core.PyList; import static org.python.bouncycastle.util.Arrays.append; // + /** * * @author boccioli_m @@ -58,7 +60,7 @@ public class TestingList extends Panel { /** * - * @return + * @return jPanel */ @Override protected JPanel create() { @@ -80,26 +82,26 @@ public class TestingList extends Panel { boolean status = (boolean) eval("status"); Object deviceName = eval("DEVICE"); String sStatus = (status == true) ? TestStatus.SUCCESS.toString() : TestStatus.FAILURE.toString(); - System.out.println("onExecutedFile: received end of test for test "+fileName); + System.out.println("onExecutedFile: received end of test for test " + fileName); // if (ret != "") { - //start next test - if (testingList.isTestRunAllowed() && testingList.runningTestsCount()==0) { - // testingList.executeTests(iCurrentTestPos); - } -/* } else { // ret empty means that either the test script does not have variable ret, or that the script could not be started at all - ret = "Could not start test script or script doea not contain default variables"; - sStatus = TestStatus.FAILURE.toString(); - String[] dsDeviceName = testingList.getTestInProgress(); - //SwingUtils.showException(getComponent(), ex ); - if (dsDeviceName[0] != "") { - iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret.toString(), sStatus); - //start next test - if (testingList.isTestRunAllowed() && testingList.runningTestsCount()==0) { - testingList.executeTest(iCurrentTestPos); - } - } + //start next test + if (testingList.isTestRunAllowed() && testingList.runningTestsCount() == 0) { + // testingList.executeTests(iCurrentTestPos); } -*/ } catch (Exception ex) { + /* } else { // ret empty means that either the test script does not have variable ret, or that the script could not be started at all + ret = "Could not start test script or script doea not contain default variables"; + sStatus = TestStatus.FAILURE.toString(); + String[] dsDeviceName = testingList.getTestInProgress(); + //SwingUtils.showException(getComponent(), ex ); + if (dsDeviceName[0] != "") { + iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret.toString(), sStatus); + //start next test + if (testingList.isTestRunAllowed() && testingList.runningTestsCount()==0) { + testingList.executeTest(iCurrentTestPos); + } + } + } + */ } catch (Exception ex) { String ret = "Could not start test script"; String sStatus = TestStatus.FAILURE.toString(); String[] dsDeviceName = testingList.getTestInProgress(); @@ -109,7 +111,7 @@ public class TestingList extends Panel { iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret, sStatus); //start next test if (testingList.isTestRunAllowed()) { - // testingList.executeTests(iCurrentTestPos + 1); + // testingList.executeTests(iCurrentTestPos + 1); } } } @@ -142,7 +144,7 @@ public class TestingList extends Panel { /** * - * @return + * @return int index of the corresponding column */ public int index() { return (int) value; @@ -223,6 +225,9 @@ public class TestingList extends Panel { } }; + /** + * + */ public enum StartSequence { START_SEQ_AFTER, @@ -454,7 +459,6 @@ public class TestingList extends Panel { this.jTable1.setEnabled(false); } - private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed boolean bSelected = jCheckBox1.isSelected(); int iSelRows = jTable1.getSelectedRowCount(); @@ -476,7 +480,7 @@ public class TestingList extends Panel { }//GEN-LAST:event_jCheckBox1ActionPerformed private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked - if(this.jTable1.isEnabled()){ + if (this.jTable1.isEnabled()) { try { switch (evt.getClickCount()) { case 1: @@ -531,8 +535,10 @@ public class TestingList extends Panel { new Thread(() -> { try { - Object ret = eval("parallelize((run,('testLocalVar1',globals(),{'a':'21', 'b':34})), (run,('testLocalVar2',globals(),{'a':231, 'b':234})))"); - //Object ret = eval("parallelize((run,('testLocalVar1',locals= {'a':21, 'b':34})), (run,('testLocalVar2', locals={'a':231, 'b':234})))"); + //Object ret = eval("parallelize((run,('testLocalVar1',globals(),{'a':'21', 'b':34})), (run,('testLocalVar2',globals(),{'a':231, 'b':234})))"); + Object ret; + ret = eval("parallelize((run,('dummy',)))"); + ret = eval("parallelize((run,('testLocalVar1',{'a':21, 'b':34})), (run,('testLocalVar2', {'a':231, 'b':234})))"); Object ret1 = ((ArrayList) ret).get(0); Object ret2 = ((ArrayList) ret).get(1); System.out.println(String.valueOf(ret1)); @@ -566,15 +572,18 @@ public class TestingList extends Panel { // /** - * - * @return status of run button. True = tests launching sequence is - * running + *returns whether or not the tests can run + * (Run launched by the user) + * + * @return status of run button. True = tests launching sequence is running */ public boolean isTestRunAllowed() { - return (this.jButtonRun.getToolTipText().equals("Stop tests") && pendingTestsCount()>0); + return (this.jButtonRun.getToolTipText().equals("Stop tests") && pendingTestsCount() > 0); } - //move selection up in table + /** + * move selected rows up in table + */ private void moveUp() { DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); int[] rows = jTable1.getSelectedRows(); @@ -586,7 +595,9 @@ public class TestingList extends Panel { } } - //move selection down in table + /** + * move selected rows down in table + */ private void moveDown() { DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); int[] rows = jTable1.getSelectedRows(); @@ -598,7 +609,11 @@ public class TestingList extends Panel { } } - //open details of the selected test in a new panel + /** + * open details of the selected row in a new panel + * + * @throws exception + */ private void openDetails() throws Exception { //pick details from the clicked row int row = jTable1.getSelectedRow(); @@ -637,30 +652,30 @@ public class TestingList extends Panel { } /** - * show test result in table + * put the test result in table * - * @param deviceName - * @param testName - * @param res - * @param status - * @return + * @param deviceName name of the device to search in table + * @param testPath path of the test to search in table + * @param res String result returned by the test + * @param status String status returned by the test + * @return int index of the row of the device in table */ - public int showResult(String deviceName, String testName, String res, String status) { + public int showResult(String deviceName, String testPath, String res, String status) { int rowD = -1; - String sTestName = testName; - logger.log(Level.FINE, "Looking for: deviceName: " + deviceName + "; testPath: " + testName + " in table."); + String sTestName = testPath; + logger.log(Level.FINE, "Looking for: deviceName: " + deviceName + "; testPath: " + testPath + " in table."); String sStatus; - if(status == "true"){ + if (status == "true") { sStatus = TestStatus.SUCCESS.toString(); - } else if (status == "false"){ + } else if (status == "false") { sStatus = TestStatus.FAILURE.toString(); - } else{ + } else { sStatus = status; } //search for device name in table for (int row = 0; row <= jTable1.getRowCount() - 1; row++) { if (deviceName.equals(jTable1.getValueAt(row, COL.DEVICENAME.ordinal())) - && testName.equals(jTable1.getValueAt(row, COL.TESTPATH.ordinal()))) { + && testPath.equals(jTable1.getValueAt(row, COL.TESTPATH.ordinal()))) { rowD = row; sTestName = jTable1.getValueAt(rowD, COL.TESTNAME.ordinal()).toString(); break; @@ -687,53 +702,76 @@ public class TestingList extends Panel { jTable1.setValueAt(res, rowD, COL.RESULT.ordinal()); jTable1.setValueAt(sStatus, rowD, COL.STATUS.ordinal()); } else { - logger.log(Level.SEVERE, "Cant find Test: " + testName + " in table."); + logger.log(Level.SEVERE, "Cant find Test: " + testPath + " in table."); } //check if there are still pending tests. If not, set the status of the tool to Stopped. - if (pendingTestsCount()==0 && runningTestsCount()==0) { + if (pendingTestsCount() == 0 && runningTestsCount() == 0) { setToStopped(); - } + } return rowD; } - - //returns the amount of tests currently in Pending state - public int pendingTestsCount(){ - return testsStatusCount(TestStatus.PENDING); - } - - //returns the amount of tests currently in Pending state - public int runningTestsCount(){ - return testsStatusCount(TestStatus.RUNNING); - } - - //returns the amount of tests currently in Pending state - public int successTestsCount(){ - return testsStatusCount(TestStatus.SUCCESS); - } - //returns the amount of tests currently in "status" state - private int testsStatusCount(TestStatus status){ + + /** + *returns the amount of tests currently in Pending state + * + * @return int counter of pending tests + */ + public int pendingTestsCount() { + return testsStatusCount(TestStatus.PENDING); + } + + + /** + *returns the amount of tests currently in Running state + * + * @return int counter of running tests + */ + public int runningTestsCount() { + return testsStatusCount(TestStatus.RUNNING); + } + + + /** + *returns the amount of tests currently in Pending state + * + * @return int counter of successful tests + */ + public int successTestsCount() { + return testsStatusCount(TestStatus.SUCCESS); + } + + /** + * returns the amount of tests currently in "status" state + * + * @param status type of status to count + * @return int counter with occurrences of the status + */ + private int testsStatusCount(TestStatus status) { String sStatus; boolean bSelected; int iPendingTestsCount = 0; for (int row = 0; row < jTable1.getRowCount(); row++) { bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal()); sStatus = jTable1.getValueAt(row, COL.STATUS.ordinal()).toString(); - if(bSelected && sStatus == status.toString()){ + if (bSelected && sStatus == status.toString()) { iPendingTestsCount++; } } - return iPendingTestsCount; + return iPendingTestsCount; } - - private void setToStopped(){ - //No more tests to play. Stop - setButtonToStop(); - logger.log(Level.INFO, "End of tests."); - } - + /** - * find the test currently in progress + * set the tests to stopped + */ + private void setToStopped() { + //No more tests to play. Stop + setButtonToStop(); + logger.log(Level.INFO, "End of tests."); + } + + /** + * get the first test currently in progress * * @return properties of the test in progress */ @@ -756,8 +794,14 @@ public class TestingList extends Panel { } } - //returns the status of the specified test name for specified device name - public String getResult(String deviceName, String testName) { + /** + *returns the status of the specified test name for specified device name + * + * @param deviceName name of the device + * @param testPath path of the test file + * @return String containing the result returned by the test + */ + public String getResult(String deviceName, String testPath) { String sStatus = ""; int rowD = -1, colT = -1; //search for device name in table @@ -768,11 +812,12 @@ public class TestingList extends Panel { } } if (rowD >= 0) { - //search for test name in table - if (testName.equals(jTable1.getValueAt(rowD, COL.TESTPATH.ordinal()))) { + //search for test in table + if (testPath.equals(jTable1.getValueAt(rowD, COL.TESTPATH.ordinal()))) { colT = COL.TESTNAME.ordinal(); } } + //get the test result if (colT >= 0 && rowD >= 0) { sStatus = jTable1.getValueAt(rowD, COL.STATUS.ordinal()).toString(); } @@ -807,222 +852,230 @@ public class TestingList extends Panel { jTable1.setValueAt(sStart, row, COL.STARTSEQUENCE.ordinal()); } } - - public void executeTests(){ - RunTest runTest = new RunTest(); - Thread t = new Thread(runTest); - t.start(); + + /** + *launch the execution of the tests + */ + public void executeTests() { + RunTest runTest = new RunTest(); + Thread t = new Thread(runTest); + t.start(); } + /** + * + */ public class RunTest implements Runnable { private HashMap mParameters; //private HashMap args; - private HashMap hTests; - + private HashMap hTests; + + /** + * + */ public RunTest() { //System.out.println("A0"); } - + public void run() { // code in the other thread, can reference "var" variable executeTest(0); } - - //execute the selected tests in the list, starting from the position - private void executeTest(int position) { - boolean bSelected = false; - String sStartSequence, sStatus; - int[] selectedTestsRows = {}; - //scan through the table starting from 'position' and execute the first selected test found - int row = 0;// position; - if (row >= 0 && row < jTable1.getRowCount()) { - for (row = position; row < jTable1.getRowCount(); row++) { - bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal()); - sStartSequence = jTable1.getValueAt(row, COL.STARTSEQUENCE.ordinal()).toString(); - sStatus = jTable1.getValueAt(row, COL.STATUS.ordinal()).toString(); + + /** + *execute the selected tests in the list, starting from the position + * + *@param position row number from which to start executing tests + */ + private void executeTest(int position) { + boolean bSelected = false; + String sStartSequence, sStatus; + int[] selectedTestsRows = {}; + //scan through the table starting from 'position' and execute the first selected test found + int row = 0;// position; + if (row >= 0 && row < jTable1.getRowCount()) { + for (row = position; row < jTable1.getRowCount(); row++) { + bSelected = (boolean) jTable1.getValueAt(row, COL.CHECK.ordinal()); + sStartSequence = jTable1.getValueAt(row, COL.STARTSEQUENCE.ordinal()).toString(); + sStatus = jTable1.getValueAt(row, COL.STATUS.ordinal()).toString(); //collect tests to be launched in parallel - //the test must be: selected, set as start with previous, pending. - //alternatively, the test must be: selected, first of the list. + //the test must be: selected, set as start with previous, pending. + //alternatively, the test must be: selected, first of the list. - //System.out.println(String.valueOf(row) + "\t" + String.valueOf(bSelected) + "\t" + String.valueOf(selectedTestsRows.length) + "\t" + sStartSequence + "\t" + sStatus); + //System.out.println(String.valueOf(row) + "\t" + String.valueOf(bSelected) + "\t" + String.valueOf(selectedTestsRows.length) + "\t" + sStartSequence + "\t" + sStatus); + if (bSelected + && sStatus.equals(TestStatus.PENDING.toString()) + && (selectedTestsRows.length == 0 || //the test must be: selected, pending, first of the list. + sStartSequence.equals(StartSequence.START_SEQ_TOGETHER.toString()))) { //or the test must be: selected, pending, set as start with previous + selectedTestsRows = append(selectedTestsRows, row); + } else if (bSelected + && sStatus.equals(TestStatus.PENDING.toString()) &&//if this test must be executed... + selectedTestsRows.length > 0 && //but there are already tests to be executed in parallel.... + (sStartSequence.equals(StartSequence.START_SEQ_AFTER.toString()))) { //...and this test must be executed in series, then stop searching + break; + } + } + if (selectedTestsRows.length > 0) { //at least one test is selected: launch it (or them) + System.out.println("\n===================================================\n"); + executeParallelTestsGroup(selectedTestsRows); //last execution did not find a test file. Continue with next execution + executeTest(position + 1); - if (bSelected - && sStatus.equals(TestStatus.PENDING.toString()) - && (selectedTestsRows.length == 0 || //the test must be: selected, pending, first of the list. - sStartSequence.equals(StartSequence.START_SEQ_TOGETHER.toString()))) { //or the test must be: selected, pending, set as start with previous - selectedTestsRows = append(selectedTestsRows, row); - } else if (bSelected - && sStatus.equals(TestStatus.PENDING.toString()) &&//if this test must be executed... - selectedTestsRows.length > 0 && //but there are already tests to be executed in parallel.... - (sStartSequence.equals(StartSequence.START_SEQ_AFTER.toString()))) { //...and this test must be executed in series, then stop searching - break; } } - if (selectedTestsRows.length > 0) { //at least one test is selected: launch it (or them) - System.out.println("\n===================================================\n"); - executeParallelTestsGroup(selectedTestsRows) ; //last execution did not find a test file. Continue with next execution - executeTest(position + 1); - - } - } - } + } - private HashMap buildMapFromTableRow(int row){ + private HashMap buildMapFromTableRow(int row) { String sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString(); String sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString(); String sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString(); String sTestPath = jTable1.getValueAt(row, COL.TESTPATH.ordinal()).toString(); - HashMap mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal()))); + HashMap mParameters = buildParametersMap(String.valueOf(jTable1.getValueAt(row, COL.TESTPARAMS.ordinal()))); HashMap testArgs = new HashMap(); - //args.put("ret", ""); + //args.put("ret", ""); testArgs.put("parameters", mParameters); testArgs.put("test", sTestName); testArgs.put("device", sDeviceName); - testArgs.put("testPath", sTestPath); - testArgs.put("status", false); - + testArgs.put("testPath", sTestPath); + testArgs.put("status", false); + return testArgs; - } - - //start all the tests in the rowsToExecute - private int executeParallelTestsGroup(int[] rowsToExecute) { - int iRet = -1; - HashMap args2 = new HashMap(); //this is the global map that will contain one map per test. - HashMap testArgs; //this is the map for a test. - RunTest runTest; - String sTestName="", sDeviceName="", sTestPath=""; - for (int row : rowsToExecute) { - //System.out.println(String.valueOf(row) + "\t" + sDeviceName + "\t" + sTestName + "\t" + sTestCaseName + "\t" + String.valueOf(rowsToExecute.length)); - try { - testArgs = buildMapFromTableRow(row); - sTestName = (String) testArgs.get("test") ; - sTestPath = (String) testArgs.get("testPath") ; - sDeviceName = (String) testArgs.get("device") ; - mParameters = (HashMap) testArgs.get("parameters") ; - File f = new File(sTestPath); - if (!f.exists() || f.isDirectory()) { - logger.log(Level.SEVERE, "Cannot find test script: " + sTestPath); - showResult(sDeviceName, sTestPath, "Cannot find test script: " + sTestPath, TestStatus.FAILURE.toString()); - continue; - } - showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString()); - //launch the test - if (!mParameters.isEmpty()) { - logger.log(Level.INFO, "Running test '" + sTestName + "' with the following parameters: " + mParameters.toString()); - System.out.println("Running test '" + sTestName + "' with the following parameters: " + mParameters.toString()); - } else { - logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found."); - System.out.println("Running test '" + sTestName + "'. No parameters found."); - } - - args2.put(sTestPath,testArgs); - - hTests = args2; - iRet = 0; - } catch (Exception ex) { - SwingUtils.showMessage(TestingList.this.getComponent(), "executeTest()", ex.toString()); - logger.log(Level.SEVERE, ex.toString()); - showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString()); - setToStopped(); - } } - try{ - int iLastExecutedTestIndex = -1; - final String sParallelizeBegin = "(run,(str('"; - final String sParallelizeEnd = "'),))"; - String sParallelizeArguments; - try { - //System.out.println("A0.1"); - String sParallelizeCommand = "parallelize("; - int i = 0; - int iTotalEntries = hTests.entrySet().size(); - for(Map.Entry hTest : hTests.entrySet()){ - //setGlobalsVars(hTest.getValue()); //set global variables that can be read by all test scripts - sTestPath = hTest.getKey().toString(); - sTestPath = sTestPath.replace("\\","\\\\"); - //System.out.println(hTest.getValue().get("test")); - sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath; - //System.out.println("Parameters passed: " + String.valueOf(hTest.getValue().get("parameters"))); - //System.out.println("A"+i); - sParallelizeArguments = "globals(),{'parameters':'"+hTest.getValue().get("parameters")+ - "','test':'"+hTest.getValue().get("test")+ - "','device':'"+hTest.getValue().get("device")+ - "','status':'"+hTest.getValue().get("status")+"'}"; - //sParallelizeArguments = "locals()"; - sParallelizeCommand = sParallelizeCommand + - "'),"+sParallelizeArguments; - i++; - if (i hTest : hTests.entrySet()) { + //setGlobalsVars(hTest.getValue()); //set global variables that can be read by all test scripts + sTestPath = hTest.getKey().toString(); + sTestPath = sTestPath.replace("\\", "\\\\"); + //System.out.println(hTest.getValue().get("test")); + sParallelizeCommand = sParallelizeCommand + "(run,(str('" + sTestPath; + //System.out.println("A"+i); + sParallelizeArguments = "globals(),{'parameters':'" + hTest.getValue().get("parameters") + + // sParallelizeArguments = "{'parameters':'"+hTest.getValue().get("parameters")+ + "','test':'" + hTest.getValue().get("test") + + "','device':'" + hTest.getValue().get("device") + + "','status':'" + hTest.getValue().get("status") + "'}"; + sParallelizeCommand = sParallelizeCommand + "')," + sParallelizeArguments; + i++; + if (i < iTotalEntries) { + sParallelizeCommand = sParallelizeCommand + ")),"; //between each "run" command + } else { + sParallelizeCommand = sParallelizeCommand + ")))"; //very last part of command "parallelize" + } + } + System.out.println(sParallelizeCommand); + Object ret; + //ret = eval("str(locals())"); + //ret = eval("str(globals())"); + ret = eval(sParallelizeCommand); + System.out.println("c"); // Object ret = eval("parallelize((run,(str('"+sTestPath+"'),)), (run,('Motor Test 3 200ms',)))"); - //System.out.println("Ret = " + String.valueOf(ret)); - String sTestResult, sTestStatus; - //read the return mapping and put the result in the right table row - //System.out.println("ret type "+ret.getClass().toString() ); - //scan through all return mappings of all run tests - for(Object oTestRet : (ArrayList) ret){ - //check if the mapping of the selected test has all expected return values - if(((List) oTestRet).size()>=4){ - //extract return data of the current test - sTestPath = String.valueOf(((List) oTestRet).get(0)); - sDeviceName = String.valueOf(((List) oTestRet).get(1)); - sTestResult = String.valueOf(((List) oTestRet).get(2)); - sTestStatus = String.valueOf(((List) oTestRet).get(3)); - //from the map of executed tests, get the test name (key is test path) - HashMap hTest = hTests.get(sTestPath); - sTestName = String.valueOf(hTest.get("test")); - } else{ //problem, the test script does not return all the expected return values - String sErrorText = "Test "+ sTestPath+" did not return all required return values"; - Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, sErrorText); - SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", sErrorText); - System.out.println(String.valueOf(sErrorText)); - //try to fetch at least first element of returned map. If fails, it will go to catch - sTestPath = String.valueOf(((List) oTestRet).get(0)); - sTestStatus = sErrorText; - sTestResult = "false"; - HashMap hTest = hTests.get(sTestPath); - sDeviceName = String.valueOf(hTest.get("device")); - sTestName = String.valueOf(hTest.get("test")); - } - System.out.println("Result: " + sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus); - iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus) ; - } - } catch (ClassCastException ccex) { - Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ccex); - SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ccex.toString()); - //System.out.println(String.valueOf(ccex)); - if(!sDeviceName.isEmpty()) - showResult(sDeviceName, sTestPath, ccex.toString(), TestStatus.FAILURE.toString()); + //System.out.println("Ret = " + String.valueOf(ret)); + String sTestResult, sTestStatus; + //read the return mapping and put the result in the right table row + //System.out.println("ret type "+ret.getClass().toString() ); + //scan through all return mappings of all run tests + for (Object oTestRet : (ArrayList) ret) { + //check if the mapping of the selected test has all expected return values + if (((List) oTestRet).size() >= 4) { + //extract return data of the current test + sTestPath = String.valueOf(((List) oTestRet).get(0)); + sDeviceName = String.valueOf(((List) oTestRet).get(1)); + sTestResult = String.valueOf(((List) oTestRet).get(2)); + sTestStatus = String.valueOf(((List) oTestRet).get(3)); + //from the map of executed tests, get the test name (key is test path) + HashMap hTest = hTests.get(sTestPath); + sTestName = String.valueOf(hTest.get("test")); + } else { //problem, the test script does not return all the expected return values + String sErrorText = "Test " + sTestPath + " did not return all required return values"; + Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, sErrorText); + SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", sErrorText); + System.out.println(String.valueOf(sErrorText)); + //try to fetch at least first element of returned map. If fails, it will go to catch + sTestPath = String.valueOf(((List) oTestRet).get(0)); + sTestStatus = sErrorText; + sTestResult = "false"; + HashMap hTest = hTests.get(sTestPath); + sDeviceName = String.valueOf(hTest.get("device")); + sTestName = String.valueOf(hTest.get("test")); + } + System.out.println("Result: " + sDeviceName + "|" + sTestPath + "|" + sTestResult + "|" + sTestStatus); + iLastExecutedTestIndex = showResult(sDeviceName, sTestPath, sTestResult, sTestStatus); + } + } catch (ClassCastException ccex) { + Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ccex); + SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ccex.toString()); + //System.out.println(String.valueOf(ccex)); + if (!sDeviceName.isEmpty()) { + showResult(sDeviceName, sTestPath, ccex.toString(), TestStatus.FAILURE.toString()); + } + } catch (Exception ex) { + Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); + SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ex.toString()); + System.out.println(String.valueOf(ex)); + showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString()); + } + } catch (Exception ex) { - Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex); - SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup()", ex.toString()); - System.out.println(String.valueOf(ex)); - showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString()); - } - - - } catch (Exception ex) { SwingUtils.showMessage(TestingList.this.getComponent(), "executeParallelTestsGroup(), run thread", ex.toString()); logger.log(Level.SEVERE, ex.toString()); setToStopped(); - } - return iRet; - } + } + return iRet; + } } - /** * table management */ @@ -1080,7 +1133,8 @@ public class TestingList extends Panel { } /** - * + *get the current time in format like 2015/07/02 15:59:43 + * * @return formatted time */ public String getNow() { @@ -1090,7 +1144,8 @@ public class TestingList extends Panel { } /** - * + *get the current time in format like 20150702155943 + * * @return time with sortable format */ public String getnow() { @@ -1099,7 +1154,12 @@ public class TestingList extends Panel { return dateFormat.format(date); } - //scan tests directory, scan devices directory, search for their test cases and scan for tests. + /** + *scan tests directory, scan devices directory, search for their test cases and scan for tests. + * + * @throws FileNotFoundException + * @throws IOException + */ public void loadTests() throws FileNotFoundException, IOException { Properties propDevice = new Properties(); Properties propTest = new Properties(); @@ -1151,10 +1211,20 @@ public class TestingList extends Panel { /** * Build a map with optional parameters to be passed to the testing - * script. The map is like this: parameters | \_ name | | | \_ value | - * \_ description | \_ name | | | \_ value | \_ description ... the name - * 'name' is the mapping key. 'value' and 'description' are constant + * script. The map is like this: + * parameters + * \_ name + * | \_ value + * | \_ description + * \_ name + * | \_ value + * | \_ description + * ... + * the name 'name' is the mapping key. 'value' and 'description' are constant * mapping keys of a nested map. + * + * @param parametersString string containing the parameters. Syntax: + * name:value:description[;name:value:description;...] */ private HashMap buildParametersMap(String parametersString) { HashMap mParameters = new HashMap(); // contains name and attributes @@ -1175,7 +1245,7 @@ public class TestingList extends Panel { } /** - * + *Open file selector */ public void selectFile() { final JFileChooser fc = new JFileChooser(); @@ -1191,7 +1261,11 @@ public class TestingList extends Panel { } } - private void saveSettings() { + /** + * Save current setup in a file. + * The current position of table rows is also saved. + */ + public void saveSettings() { final JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(NetbeansPluginPanel.this); @@ -1201,7 +1275,13 @@ public class TestingList extends Panel { saveSettings(file); } } - + + /** + * Save current setup in a file. + * The current position of table rows is also saved. + * + * @param file file containing the settings + */ private void saveSettings(File file) { DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel(); try { @@ -1214,7 +1294,11 @@ public class TestingList extends Panel { } } - private void loadSettings() { + /** + * Save current setup in a file. + * The current position of table rows is also saved. + */ + public void loadSettings() { final JFileChooser fc = new JFileChooser(); int returnVal = fc.showOpenDialog(NetbeansPluginPanel.this); if (returnVal == JFileChooser.APPROVE_OPTION) { @@ -1223,6 +1307,12 @@ public class TestingList extends Panel { } } + /** + * Save current setup in a file. + * The current position of table rows is also saved. + * + * @param file file containing the settings + */ private void loadSettings(File file) { DefaultTableModel tableModel = (DefaultTableModel) jTable1.getModel(); try {