Closedown

This commit is contained in:
boccioli_m
2015-06-25 09:42:08 +02:00
parent 35b48ab212
commit 67b193126d
2 changed files with 79 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableCellRenderer;
import org.apache.commons.io.FilenameUtils;
import static org.python.bouncycastle.util.Arrays.append;
/**
*
@@ -235,7 +236,7 @@ public class TestingList extends Panel {
public enum StartSequence {
START_SEQ_AFTER,
START_SEQ_BEFORE;
START_SEQ_TOGETHER;
@Override
public final String toString() {
@@ -244,7 +245,7 @@ public class TestingList extends Panel {
case START_SEQ_AFTER:
status = "After previous";
break;
case START_SEQ_BEFORE:
case START_SEQ_TOGETHER:
status = "Together with previous";
break;
}
@@ -739,7 +740,7 @@ public class TestingList extends Panel {
}
//execute the selected tests in the list, starting from the position
public void executeTest(int position){
public void executeTest_Old(int position){
boolean bSelected = false;
String sDeviceName;
String sTestName;
@@ -794,6 +795,79 @@ public class TestingList extends Panel {
logger.log(Level.INFO, "End of tests.");
}
}
//execute the selected tests in the list, starting from the position
public 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 = position;
if (row >=0 && row <= jTable1.getRowCount()-1 ) {
for(row = position ; row <= jTable1.getRowCount()-1 ; 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.
if( bSelected &&
(selectedTestsRows.length == 0 || //the test must be: selected, first of the list.
(sStartSequence.equals(StartSequence.START_SEQ_TOGETHER.toString()) && //or the test must be: selected, set as start with previous, pending.
sStatus.equals(TestStatus.PENDING.toString()) ))){
selectedTestsRows = append(selectedTestsRows, row);
} else if (bSelected && //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 (bSelected) { //at least one test is selected: launch it (or them)
executeParallelTestsGroup(selectedTestsRows);
}
}
if(!bSelected){ //No test to play. Stop
setButtonToStop();
logger.log(Level.INFO, "End of tests.");
}
}
private void executeParallelTestsGroup(int[] rowsToExecute){
HashMap args = new HashMap();
for(int row: rowsToExecute){
//build the .py test file path
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())));
try{
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
args.put("DEVICE", sDeviceName);
args.put("ret", "");
args.put("status", false);
if(!mParameters.isEmpty()){
args.put("parameters", mParameters);
logger.log(Level.INFO, "Running test '"+sTestName+"' with the following parameters: " + mParameters.toString());
} else {
logger.log(Level.INFO, "Running Test '" + sTestName + "'. No parameters found.");
}
runAsync(sTestPath, args);
} catch (Exception ex) {
SwingUtils.showMessage(this, "executeTest()", ex.toString());
logger.log(Level.SEVERE, ex.toString());
showResult(sDeviceName, sTestPath, ex.toString(), TestStatus.FAILURE.toString());
setButtonToStop();
}
}
}
/**
*table management
@@ -806,7 +880,7 @@ public class TestingList extends Panel {
//Set up the combo box editor for the Start Sequence cells.
JComboBox comboBox = new JComboBox();
comboBox.addItem(StartSequence.START_SEQ_AFTER.toString());
comboBox.addItem(StartSequence.START_SEQ_BEFORE.toString());
comboBox.addItem(StartSequence.START_SEQ_TOGETHER.toString());
jTable1.getColumnModel().getColumn(COL.STARTSEQUENCE.ordinal()).setCellEditor(new DefaultCellEditor(comboBox));
//Set up tool tips for the sequence cells.
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();