This commit is contained in:
boccioli_m
2015-08-28 09:10:50 +02:00
parent fc64356e5e
commit 2fc122c293
2 changed files with 88 additions and 9 deletions

View File

@@ -30,12 +30,6 @@ import javax.swing.event.HyperlinkListener;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.io.FilenameUtils;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author boccioli_m
@@ -110,6 +104,9 @@ public class NewTest extends javax.swing.JPanel {
txtTestName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jComboBoxTestSuites.setMinimumSize(new java.awt.Dimension(31, 23));
jComboBoxTestSuites.setPreferredSize(new java.awt.Dimension(31, 23));
jScrollPane3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
txtTestDescription.setColumns(20);
@@ -232,6 +229,7 @@ public class NewTest extends javax.swing.JPanel {
}
}//GEN-LAST:event_jMenuItemReleteRowActionPerformed
//constant declarations
public static Path TESTS_DEVICES_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "devices");
public static Path TESTS_TESTS_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "tests");
public static Path TESTS_CONFIG_DEFAULT_DIR = Paths.get(".", "home", "script", "tests", "config");
@@ -280,9 +278,11 @@ public class NewTest extends javax.swing.JPanel {
testParams = "";
}
ist.close();
//separate items in string by building a HashMap
HashMap hParams = (HashMap) buildParametersMap(testParams);
String name="", value="", description="";
DefaultTableModel model = (DefaultTableModel) jTableParams.getModel();
//put items in table
for(Object entry : hParams.keySet()){
Object param = entry;
if(param instanceof String){
@@ -338,6 +338,11 @@ public class NewTest extends javax.swing.JPanel {
return mParameters;
}
/**
* Pick the items one by one from the table and build a HashMap.
* For details on the HashMap structure, see buildParametersMap()
* @return contains the test parameters.
*/
private HashMap getParametersFromTable(){
HashMap mParameters = new HashMap(); // contains name and attributes
HashMap mParameterAttributes = new HashMap(); //contians value and description
@@ -354,6 +359,11 @@ public class NewTest extends javax.swing.JPanel {
return mParameters;
}
/**
* verifies that the data introduced in the fields is correct
* i.e. fields filled, and only allowed characters
* @return true if the data is correct, false if else
*/
public boolean checkDataFields(){
//check compulsory data fields
if(this.txtTestName.getText().isEmpty() ||
@@ -392,7 +402,10 @@ public class NewTest extends javax.swing.JPanel {
return true;
}
/**
* pick the data introduced by the user
* and create folders and files for the new test to generate
*/
public void generateTestFiles(){
HashMap hmTestParams = (HashMap) getParametersFromTable();
if(sType.equals("Device")){
@@ -408,6 +421,14 @@ public class NewTest extends javax.swing.JPanel {
}
}
/**
* create folders and files for the new test to generate
*
* @param sTestName name of the test
* @param sTestDescription description of the test
* @param sTestSuite test cases/test suite name
* @param hmTestParams test parameters. For the details of the structure, see buildParametersMap
*/
public void generateTestFiles(String sTestName,
String sTestDescription,
String sTestSuite,
@@ -464,6 +485,14 @@ public class NewTest extends javax.swing.JPanel {
}
}
/**
* create folders and files for the new device to generate
*
* @param sTestName name of the test
* @param sTestDescription description of the test
* @param sTestSuite test cases/test suite name
* @param hmTestParams test parameters. For the details of the structure, see buildParametersMap
*/
public void generateDeviceFiles(String sTestName,
String sTestDescription,
String sTestSuite,
@@ -500,7 +529,16 @@ public class NewTest extends javax.swing.JPanel {
}
/**
* generate the python script that runs the test
*
* @param testDir path where the test is located (including the test name dir)
* @param sTestName name of the test
* @param sTestDescription description of the test
* @param sTestSuite test cases/test suite name
* @param hmTestParams test parameters. For the details of the structure, see buildParametersMap
* @return true if success, false if else
*/
public boolean generateTestScript(Path testDir,
String sTestName,
String sTestDescription,
@@ -539,6 +577,18 @@ public class NewTest extends javax.swing.JPanel {
return success;
}
/**
* generate the python script that runs the test
*
* @param templateDir the path of the template to be used for the generation of theconfig.
* it can be: TEMPLATES_TESTCONFIG_FILEPATH, TEMPLATES_DEVICECONFIG_FILEPATH
* @param testDir path where the test is located (including the test name dir)
* @param sTestName name of the test
* @param sTestDescription description of the test
* @param sTestSuite test cases/test suite name
* @param hmTestParams test parameters. For the details of the structure, see buildParametersMap
* @return true if success, false if else
*/
public boolean generateTestConfig(Path templateDir,
Path testDir,
String sTestName,
@@ -574,10 +624,12 @@ public class NewTest extends javax.swing.JPanel {
in.close();
FileOutputStream out = new FileOutputStream(configFile);
if(sType.equals("Devices")){
//creation of device config
props.setProperty("name", sTestName);
props.setProperty("description", sTestDescription);
props.setProperty("parameters", sTestParameters);
}else{
//creation of test config
props.setProperty("name", sTestName);
props.setProperty("description", sTestDescription);
props.setProperty("tests", sTestSuite);
@@ -595,6 +647,17 @@ public class NewTest extends javax.swing.JPanel {
return success;
}
/**
* generate the html help file of the test
*
* @param testDir path where the test is located (including the test name dir)
* @param sTestName name of the test
* @param sTestDescription description of the test
* @param sTestSuite test cases/test suite name
* @param hmTestParams test parameters. For the details of the structure, see buildParametersMap
* @return true if success, false if else
*/
public boolean generateTestHelp(Path testDir,
String sTestName,
String sTestDescription,
@@ -633,7 +696,17 @@ public class NewTest extends javax.swing.JPanel {
return success;
}
/**
* replace thetemplateparameters(usually starting with $) with real values
*
* @param path path of the file whose parameters must be replaced
* @param parameterNames array of template parameters names that must be searched in the file.
* the size must be equal to the size of parameterValues
* @param parameterValues array of template parameters values
* that must replace the template parameter names in the file.
* the size must be equal to the size of parameterNames
* @return
*/
public boolean replaceParameters(Path path,
String parameterNames[],
String parameterValues[]){