diff --git a/plugins/TestingList.form b/plugins/TestingList.form index fbfcc1f..b4c0627 100644 --- a/plugins/TestingList.form +++ b/plugins/TestingList.form @@ -34,7 +34,7 @@ - + @@ -50,8 +50,6 @@ - - diff --git a/plugins/TestingList.java b/plugins/TestingList.java index 69c4ea0..43d8cc4 100644 --- a/plugins/TestingList.java +++ b/plugins/TestingList.java @@ -65,7 +65,12 @@ public class TestingList extends Panel { Object deviceName = eval("DEVICE"); String sStatus = (status == true) ? TestStatus.SUCCESS.toString() : TestStatus.FAILURE.toString(); - SwingUtils.showMessage(getComponent(), "onExecutedFile()", result.toString()); + if (exception!=null){ + SwingUtils.showMessage(getComponent(), "Error", String.valueOf(exception)); + } else { + SwingUtils.showMessage(getComponent(), "onExecutedFile()", String.valueOf(result)); + } + if (ret != "" ) { //SwingUtils.showMessage(getComponent(), "", ret.toString() + " - " + ret.getClass().getName()); iCurrentTestPos = testingList.showResult(deviceName.toString(), fileName, ret.toString(), sStatus); @@ -109,16 +114,17 @@ public class TestingList extends Panel { //table column indexes public enum COL { - CHECK (0), - TIME (1), - DEVICENAME (2), + CHECK (0), + TIME (1), + DEVICENAME (2), DEVICEDESCR (3), - TESTSUITE (4), - TESTNAME (5), - TESTPATH (6), - RESULT (7), - STATUS (8), - ICON (9); + TESTSUITE (4), + TESTNAME (5), + TESTPATH (6), + TESTPARAMS (7), + RESULT (8), + STATUS (9), + ICON (10); private int value; private COL(int value) { @@ -196,7 +202,6 @@ public class TestingList extends Panel { public class NetbeansPluginPanel extends MonitoredPanel { Logger logger = Logger.getLogger("TestsLog"); - HashMap mParameters = new HashMap(); //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/"); @@ -253,14 +258,14 @@ public class TestingList extends Panel { }, new String [] { - "Select", "Time", "Device Name", "Device Description", "Test Suite", "Test Name", "Test Peth", "Last Test Result", "Status", "" + "Select", "Time", "Device Name", "Device Description", "Test Suite", "Test Name", "Test Peth", "Test Parameters", "Last Test Result", "Status", "" } ) { Class[] types = new Class [] { - java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, javax.swing.Icon.class + java.lang.Boolean.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, javax.swing.Icon.class }; boolean[] canEdit = new boolean [] { - true, false, false, false, false, false, false, false, false, false + true, false, false, false, false, false, false, false, false, false, false }; public Class getColumnClass(int columnIndex) { @@ -280,14 +285,6 @@ public class TestingList extends Panel { jTable1MouseClicked(evt); } }); - jTable1.addInputMethodListener(new java.awt.event.InputMethodListener() { - public void caretPositionChanged(java.awt.event.InputMethodEvent evt) { - jTable1CaretPositionChanged(evt); - } - public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) { - jTable1InputMethodTextChanged(evt); - } - }); jTable1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { jTable1KeyReleased(evt); @@ -414,15 +411,19 @@ public class TestingList extends Panel { updateStatus(); }//GEN-LAST:event_jCheckBox1ActionPerformed - private void jTable1InputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTable1InputMethodTextChanged - }//GEN-LAST:event_jTable1InputMethodTextChanged - - private void jTable1CaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jTable1CaretPositionChanged - }//GEN-LAST:event_jTable1CaretPositionChanged - private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked - int colIndex = jTable1.getSelectedColumn(); - if (colIndex == COL.CHECK.ordinal()) updateStatus(); + switch (evt.getClickCount()){ + case 1: + int colIndex = jTable1.getSelectedColumn(); + if (colIndex == COL.CHECK.ordinal()) updateStatus(); + break; + case 2: + SwingUtils.showMessage(this, "jBu","bo"); + TestingListDetails detailsPanel = new TestingListDetails(); + //detailsPanel.setVisible(true); + //add(detailsPanel); + break; + } }//GEN-LAST:event_jTable1MouseClicked private void jTable1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyTyped @@ -602,6 +603,7 @@ public class TestingList extends Panel { String sTestCaseName; String sTestPath; HashMap args = new HashMap(); + HashMap mParameters = new HashMap(); //scan through the table starting from 'position' and execute the first selected test found int row = position; if (row >=0 && row <= jTable1.getRowCount()-1 ) { @@ -614,21 +616,26 @@ public class TestingList extends Panel { sDeviceName = jTable1.getValueAt(row, COL.DEVICENAME.ordinal()).toString(); sTestName = jTable1.getValueAt(row, COL.TESTNAME.ordinal()).toString(); sTestCaseName = jTable1.getValueAt(row, COL.TESTSUITE.ordinal()).toString(); - sTestPath = jTable1.getValueAt(row, COL.TESTPATH.ordinal()).toString();; - 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()); - executeTest(position+1); - return; - } - showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString()); - //launch the test - try{ + sTestPath = jTable1.getValueAt(row, COL.TESTPATH.ordinal()).toString(); + 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()); + executeTest(position+1); + return; + } + showResult(sDeviceName, sTestPath, "Test running", TestStatus.RUNNING.toString()); + //launch the test + args.put("DEVICE", sDeviceName); args.put("ret", ""); args.put("status", false); - args.put("parameters", buildParametersMap()); + if(!mParameters.isEmpty()){ + args.put("parameters", mParameters); + logger.log(Level.INFO,"Running tests with the following parameters: " + mParameters.toString()); + } runAsync(sTestPath, args); } catch (Exception ex) { SwingUtils.showMessage(this, "executeTest()", ex.toString()); @@ -660,7 +667,7 @@ public class TestingList extends Panel { } //append test info to table - public void addToTable(String deviceName, String deviceDescription, String testSuite, String testName) { + public void addToTable(String deviceName, String deviceDescription, String testSuite, String testName, String testParams) { String sDate = ""; if (testName.equals("") || deviceName.equals("")) { return; @@ -668,7 +675,7 @@ public class TestingList extends Panel { ImageIcon icon = null;// new ImageIcon(getClass().getResource("/icons/button_pause-16px.png")); DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); String testPath = FilenameUtils.separatorsToSystem(TESTS_TESTS_DEFAULT_DIR + testSuite + "/" + testName + "/" + testName + ".py"); - model.addRow(new Object[]{false, sDate, deviceName, deviceDescription, testSuite, testName, testPath, "", "Pending", icon}); + model.addRow(new Object[]{false, sDate, deviceName, deviceDescription, testSuite, testName, testPath, testParams, "", "Pending", icon}); jTable1.setModel(model); updateStatus(); } @@ -700,6 +707,7 @@ public class TestingList extends Panel { //Scan the list of devices File[] listOfFiles = folder.listFiles(); for (File listOfFile : listOfFiles) { + propDevice.clear(); if (listOfFile.isFile()) { } else if (listOfFile.isDirectory()) { File configFile = new File(listOfFile.getPath() + FilenameUtils.separatorsToSystem("/.config")); @@ -712,6 +720,7 @@ public class TestingList extends Panel { if (testsFolder.exists() && testsFolder.isDirectory()) { File[] listOfTests = testsFolder.listFiles(); for (File listOfTest : listOfTests) { + propTest.clear(); if (listOfTest.isDirectory()) { configFile = new File(listOfTest.getPath() + FilenameUtils.separatorsToSystem("/.config")); if (configFile.exists() && !configFile.isDirectory()) { @@ -720,7 +729,8 @@ public class TestingList extends Panel { addToTable(propDevice.getProperty("name"), propDevice.getProperty("description"), propDevice.getProperty("tests"), - propTest.getProperty("name")); + propTest.getProperty("name"), + propTest.getProperty("parameters")); iCounter++; } } @@ -732,13 +742,38 @@ public class TestingList extends Panel { logger.log(Level.INFO, iCounter + " tests loaded."); } - - private HashMap buildParametersMap(){ - HashMap mParameters = new HashMap(); - mParameters.put("repeatTimes", 2); - mParameters.put("midPoint", 40.0); - mParameters.put("spanFromMidPoint", 10.0); - + private HashMap buildParametersMap(String parametersString){ + /* + 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. + */ + HashMap mParameters = new HashMap(); // contains name and attributes + HashMap mParameterAttributes = new HashMap(); //contians value and description + String[] dsParameterAttributes = null; + String[] dsParameters = parametersString.split(";"); + for (String sParameter : dsParameters){ + dsParameterAttributes = sParameter.split(":"); + if(dsParameterAttributes.length > 2){ + mParameterAttributes = new HashMap(); + mParameterAttributes.put("value", (Object)dsParameterAttributes[1]); + mParameterAttributes.put("description", dsParameterAttributes[2]); + //add parameter name and attributes (value + description) + mParameters.put(dsParameterAttributes[0], mParameterAttributes); + } + } return mParameters; } diff --git a/script/tests/tests/Collimator Tests/Motor Test 2/.config b/script/tests/tests/Collimator Tests/Motor Test 2/.config index 8dbafbb..11d633c 100644 --- a/script/tests/tests/Collimator Tests/Motor Test 2/.config +++ b/script/tests/tests/Collimator Tests/Motor Test 2/.config @@ -1,3 +1,7 @@ name=Motor Test 2 description=Go to absolute position A, then move +B steps, then -2B steps, then +2Bsteps (ie oscillate round centre position, logging after each movement); repeat N times filename=Motor Test 3.xml + +#optional parameters. Description is compulsory. Syntax: +#parameters=::[;::] +parameters=repeatTimes:3:Repeat times;midPoint:41.0:Middle point;spanFromMidPoint:11.0:Span around middle point