Closedown
This commit is contained in:
@@ -14,6 +14,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -39,7 +40,8 @@ import javax.naming.directory.SearchResult;
|
||||
import javax.naming.ldap.InitialLdapContext;
|
||||
import javax.naming.ldap.LdapContext;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
/**
|
||||
*
|
||||
* @author boccioli_m
|
||||
@@ -758,7 +760,7 @@ public class NewTest extends javax.swing.JPanel {
|
||||
* @param hmTestParams test parameters. For the details of the structure, see buildParametersMap
|
||||
* @return true if success, false if else
|
||||
*/
|
||||
public boolean generateTestConfig(Path templateDir,
|
||||
public boolean generateTestConfigOld(Path templateDir,
|
||||
Path testDir,
|
||||
String sTestName,
|
||||
String sTestDescription,
|
||||
@@ -818,6 +820,100 @@ public class NewTest extends javax.swing.JPanel {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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,
|
||||
String sTestDescription,
|
||||
String sTestSuite,
|
||||
HashMap hmTestParams){
|
||||
//generate test config file from template
|
||||
boolean success = false;
|
||||
try {
|
||||
Path path = Paths.get(testDir.toString(),TESTS_CONFIG_FILENAME);
|
||||
if(Files.exists(path)){
|
||||
Files.delete(path);
|
||||
}
|
||||
Files.copy(templateDir, path);
|
||||
File configFile = path.toFile();
|
||||
|
||||
//Loop among the test parameters and generate variable assignement syntax for python
|
||||
String sTestParameters = "";
|
||||
String name="", value="", description="";
|
||||
for(Object entry : hmTestParams.keySet()){
|
||||
Object param = entry;
|
||||
if(param instanceof String){
|
||||
name = (String) param;
|
||||
HashMap attributes = (HashMap) hmTestParams.get(param);
|
||||
value = (String) attributes.get("value");
|
||||
description = (String) attributes.get("description");
|
||||
//build the python code for getting the test parameter
|
||||
sTestParameters = sTestParameters + name + ":" + value + ":" + description + ";" ;
|
||||
}
|
||||
}
|
||||
FileInputStream in = new FileInputStream(configFile);
|
||||
Properties props = new Properties();
|
||||
props.load(in);
|
||||
in.close();
|
||||
FileOutputStream out = new FileOutputStream(configFile);
|
||||
if(sType == TypeOfNewFile.Device){
|
||||
//creation of device config
|
||||
props.setProperty("name", sTestName);
|
||||
props.setProperty("description", sTestDescription);
|
||||
props.setProperty("tests", sTestSuite);
|
||||
}else{
|
||||
//creation of test config
|
||||
props.setProperty("name", sTestName);
|
||||
props.setProperty("description", sTestDescription);
|
||||
props.setProperty("parameters", sTestParameters);
|
||||
|
||||
}
|
||||
props.store(out, null);
|
||||
out.close();
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("Name", "crunchify.com");
|
||||
obj.put("Author", "App Shah");
|
||||
|
||||
JSONArray company = new JSONArray();
|
||||
company.add("Compnay: eBay");
|
||||
company.add("Compnay: Paypal");
|
||||
company.add("Compnay: Google");
|
||||
obj.put("Company List", company);
|
||||
|
||||
String jsonConfig = obj.toJSONString();
|
||||
|
||||
FileWriter jout = new FileWriter(configFile);
|
||||
|
||||
jout.write(jsonConfig);
|
||||
jout.flush();
|
||||
jout.close();
|
||||
|
||||
success = true;
|
||||
} catch (FileNotFoundException ex) {
|
||||
SwingUtils.showMessage(this, "generateTestConfig()", "Cannot find file: " + ex.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
SwingUtils.showMessage(this, "generateTestConfig()", "Problem with file aaccess: " + ex.toString());
|
||||
Logger.getLogger(NewTest.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* generate the html help file of the test
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user