This commit is contained in:
boccioli_m
2015-06-30 15:30:40 +02:00
parent df5b42a266
commit 86d98e0c2f
2 changed files with 570 additions and 8 deletions

View File

@@ -0,0 +1,441 @@
/**
* @author boccioli_m
* @version 1.0
* @created 30-Jun-2015 10:18:25
*/
public class NetbeansPluginPanel extends MonitoredPanel {
/**
* @author boccioli_m
* @version 1.0
* @created 30-Jun-2015 10:18:25
*/
public class RunTest implements Runnable {
private HashMap<String,Object> args;
private HashMap<String,HashMap> hTests;
private HashMap mParameters;
private String sDeviceName;
private String sTestPath;
public RunTest(){
}
public void finalize() throws Throwable {
}
/**
*
* @param sTestPath
* @param args
*/
public RunTest(String sTestPath, HashMap<String,Object> args){
}
/**
*
* @param sTestPath
*/
public RunTest(String sTestPath){
}
/**
*
* @param args
*/
public RunTest(HashMap<String,HashMap> args){
}
public void run(){
}
}
/**
* <editor-fold defaultstate="collapsed" desc="Witget Variables declaration">
* Variables declaration - do not modify//GEN-BEGIN:variables
*/
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButtonMoveDown;
private javax.swing.JButton jButtonMoveUp;
private javax.swing.JButton jButtonOpenLog;
private javax.swing.JButton jButtonRun;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
Logger logger = Logger.getLogger("TestsLog");
/**
* these paths are converted to unix or win path according to host OS
*/
private final String TESTS_DEVICES_DEFAULT_DIR = new java.io.File(".").getCanonicalPath()
+ FilenameUtils.separatorsToSystem("/home/script/tests/devices/");
private final String TESTS_LOG_DEFAULT_DIR = new java.io.File(".").getCanonicalPath()
+ FilenameUtils.separatorsToSystem("/home/script/tests/log/TestsLog" + getnow() + ".txt");
private final String TESTS_TESTS_DEFAULT_DIR = new java.io.File(".").getCanonicalPath()
+ FilenameUtils.separatorsToSystem("/home/script/tests/tests/");
public void finalize() throws Throwable {
super.finalize();
}
/**
*
* @exception IOException IOException
*/
public NetbeansPluginPanel()
throws IOException{
}
/**
* append test info to table
*
* @param deviceName
* @param deviceDescription
* @param testSuite
* @param testName
* @param testParams
* @param testDescription
* @param testHelp
*/
private void addToTable(String deviceName, String deviceDescription, String testSuite, String testName, String testParams, String testDescription, String testHelp){
}
/**
* 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 mapping keys of a nested map.
*
* @param parametersString
*/
private HashMap buildParametersMap(String parametersString){
return null;
}
/**
* table management
*/
private void buildTable(){
}
/**
* start all the tests in the rowsToExecute
*
* @param rowsToExecute
*/
private int executeParallelTestsGroup(int[] rowsToExecute){
return 0;
}
/**
* execute the selected tests in the list, starting from the position
*
* @param position
*/
public void executeTest(int position){
}
/**
* execute the selected tests in the list, starting from the position
*
* @param position
*/
public void executeTest_Old(int position){
}
/**
* @return formatted time
*/
public String getNow(){
return "";
}
/**
* @return time with sortable format
*/
public String getnow(){
return "";
}
/**
* returns the status of the specified test name for specified device name
*
* @param deviceName
* @param testName
*/
public String getResult(String deviceName, String testName){
return "";
}
/**
* find the test currently in progress
* @return properties of the test in progress
*/
public String[] getTestInProgress(){
return "";
}
/**
*
* @param column
*/
private void hideColumn(COL column){
}
@SuppressWarnings("unchecked")
private void initComponents(){
}
private void initLogger(){
}
/**
* @return status of run button. True = tests launching sequence is running
*/
public boolean isTestRunAllowed(){
return false;
}
/**
* GEN-LAST:event_jButtonMoveUpActionPerformed
*
* @param evt
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
}
/**
* GEN-LAST:event_jButton1ActionPerformed
*
* @param evt
*/
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt){
}
/**
* GEN-LAST:event_jTable1KeyReleased
*
* @param evt
*/
private void jButtonMoveDownActionPerformed(java.awt.event.ActionEvent evt){
}
/**
* GEN-LAST:event_jButtonMoveDownActionPerformed
*
* @param evt
*/
private void jButtonMoveUpActionPerformed(java.awt.event.ActionEvent evt){
}
/**
* oopen the log file using one of th default OS text reades
*
* @param evt
*/
private void jButtonOpenLogActionPerformed(java.awt.event.ActionEvent evt){
}
/**
* </editor-fold>//GEN-END:initComponents
*
* @param evt
*/
private void jButtonRunActionPerformed(java.awt.event.ActionEvent evt){
}
/**
*
* @param evt
*/
private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt){
}
/**
* GEN-LAST:event_jButtonOpenLogActionPerformed
*
* @param evt
*/
private void jTable1KeyReleased(java.awt.event.KeyEvent evt){
}
/**
* GEN-LAST:event_jCheckBox1ActionPerformed
*
* @param evt
*/
private void jTable1MouseClicked(java.awt.event.MouseEvent evt){
}
public int jump(){
return 0;
}
private void loadSettings(){
}
/**
*
* @param file
*/
private void loadSettings(File file){
}
/**
* scan tests directory, scan devices directory, search for their test cases and
* scan for tests.
* @exception FileNotFoundException,IOException
*/
public void loadTests()
throws FileNotFoundException,IOException{
}
/**
* move selection down in table
*/
private void moveDown(){
}
/**
* move selection up in table
*/
private void moveUp(){
}
/**
* open details of the selected test in a new panel
* @exception Exception
*/
private void openDetails()
throws Exception{
}
/**
* returns the amount of tests currently in Pending state
*/
public int pendingTestsCount(){
return 0;
}
/**
* returns the amount of tests currently in Pending state
*/
public int runningTestsCount(){
return 0;
}
/**
* delete this
*
* @param sDeviceName
* @param sTestPath
* @param mParameters
*/
private void runTest(String sDeviceName, String sTestPath, HashMap mParameters){
}
private void saveSettings(){
}
/**
*
* @param file
*/
private void saveSettings(File file){
}
public void selectFile(){
}
private void setButtonToStart(){
}
/**
* GEN-LAST:event_jButtonRunActionPerformed
*/
private void setButtonToStop(){
}
private void setToStopped(){
}
/**
* show test result in table
* @return
*
* @param deviceName
* @param testName
* @param res
* @param status
*/
public int showResult(String deviceName, String testName, String res, String status){
return 0;
}
/**
* returns the amount of tests currently in Pending state
*/
public int successTestsCount(){
return 0;
}
/**
* returns the amount of tests currently in "status" state
*
* @param status
*/
private int testsStatusCount(TestStatus status){
return 0;
}
/**
* visualise test status (columns status and icon)
*/
public void updateStatus(){
}
}

View File

@@ -86,11 +86,11 @@ 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("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.executeTest(iCurrentTestPos);
// 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";
@@ -115,7 +115,7 @@ public class TestingList extends Panel {
iCurrentTestPos = testingList.showResult(dsDeviceName[0], fileName, ret, sStatus);
//start next test
if (testingList.isTestRunAllowed()) {
testingList.executeTest(iCurrentTestPos + 1);
// testingList.executeTests(iCurrentTestPos + 1);
}
}
}
@@ -440,7 +440,7 @@ public class TestingList extends Panel {
if (this.jButtonRun.getToolTipText().equals("Run selected tests")) {
setButtonToStart();
updateStatus();
executeTest(0);
executeTests();
} else {
setButtonToStop();
}
@@ -812,7 +812,16 @@ public class TestingList extends Panel {
jTable1.setValueAt(sStart, row, COL.STARTSEQUENCE.ordinal());
}
}
public void executeTests(){
RunTest runTest = new RunTest();
System.out.println("C");
Thread t = new Thread(runTest);
System.out.println("D");
t.start();
System.out.println("E");
}
/*
//execute the selected tests in the list, starting from the position
public void executeTest_Old(int position) {
boolean bSelected = false;
@@ -973,7 +982,7 @@ public class TestingList extends Panel {
return iRet;
}
*/
//delete this
/*
public class RunTest_old implements Runnable {
@@ -1083,12 +1092,112 @@ public class TestingList extends Panel {
this.mParameters.put("a", 1);
}
public RunTest(HashMap<String,HashMap> args) {
System.out.println("A0");
System.out.println("A0");
this.hTests = (HashMap) args;
}
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();
//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.
//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)
if (executeParallelTestsGroup(selectedTestsRows) < 0) { //last execution did not find a test file. Continue with next execution
executeTest(position + 1);
}
}
}
}
//start all the tests in the rowsToExecute
private int executeParallelTestsGroup(int[] rowsToExecute) {
int iRet = -1;
HashMap args = 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;
for (int row : rowsToExecute) {
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())));
System.out.println(String.valueOf(row) + "\t" + sDeviceName + "\t" + sTestName + "\t" + sTestCaseName + "\t" + String.valueOf(rowsToExecute.length));
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());
iRet = -1;
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.");
}
testArgs = new HashMap();
//args.put("ret", "");
testArgs.put("parameters", mParameters);
testArgs.put("test", sTestName);
testArgs.put("device", sDeviceName);
testArgs.put("status", false);
args.put(sTestPath,testArgs);
System.out.println("A");
hTests = args;
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());
setButtonToStop();
}
}
try{
// runTest = new RunTest(args);
// System.out.println("C");
// Thread t = new Thread(runTest);
// System.out.println("D");
// t.start();
// System.out.println("E");
int iLastExecutedTestIndex = -1;
final String sParallelizeBegin = "(run,(str('";
final String sParallelizeEnd = "'),))";
@@ -1131,8 +1240,20 @@ public class TestingList extends Panel {
Logger.getLogger(TestingList.class.getName()).log(Level.SEVERE, null, ex);
SwingUtils.showMessage(TestingList.this.getComponent(), "runTest()", ex.toString());
System.out.println(String.valueOf(ex));
}
setButtonToStop();
}
} catch (Exception ex) {
SwingUtils.showMessage(TestingList.this.getComponent(), "executeTest(), run thread", ex.toString());
logger.log(Level.SEVERE, ex.toString());
setButtonToStop();
}
return iRet;
}
}