This commit is contained in:
boccioli_m
2018-03-20 13:48:39 +01:00
parent f952dba362
commit 23f6671e41
12 changed files with 507 additions and 3410 deletions

View File

@@ -14,7 +14,6 @@ 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;
@@ -40,8 +39,7 @@ 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
@@ -60,11 +58,9 @@ public class NewTest extends javax.swing.JPanel {
public static Path TEMPLATES_DEVICECONFIG_FILEPATH = Paths.get(TESTS_ROOT_DIR, "templates","deviceTemplate.config");
public static String TESTS_CONFIG_FILENAME = ".config";
public static String TESTS_HELP_FILENAME = "help.html";
public static String ALLOWED_CHARSET1 = "[a-z A-Z 0-9 . _ \\- \\[\\] () : < > = \\$]*"; //les restricted set of chars
public static String ALLOWED_CHARSET2 = "[a-z A-Z 0-9 . _ \\- \\[\\] () : \\$]*"; //more restricted set of chars
public static String ALLOWED_CHARSET3 = "[a-zA-Z0-9._ \\- \\$ , :]*"; //even more restricted set of chars
public static String VALUE_SEPARATOR = "&";
public static String PARAM_SEPARATOR = ";";
public static String ALLOWED_CHARSET1 = "[a-z A-Z 0-9 . _ \\- \\[\\] () : , < > =]*"; //les restricted set of chars
public static String ALLOWED_CHARSET2 = "[a-z A-Z 0-9 . _ \\- \\[\\] ()]*"; //more restricted set of chars
public static String ALLOWED_CHARSET3 = "[a-zA-Z0-9._\\-]*"; //even more restricted set of chars
/**
* enumeration of table column indexes
@@ -155,13 +151,8 @@ public class NewTest extends javax.swing.JPanel {
txtTestName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
txtTestName.setToolTipText("");
txtTestName.setMinimumSize(new java.awt.Dimension(30, 26));
txtTestName.setPreferredSize(new java.awt.Dimension(60, 26));
txtTestName.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtTestNameActionPerformed(evt);
}
});
txtTestName.setMinimumSize(new java.awt.Dimension(30, 23));
txtTestName.setPreferredSize(new java.awt.Dimension(60, 23));
jComboBoxTestSuites.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jComboBoxTestSuites.setToolTipText("Select a Test Suite or add a new one");
@@ -175,13 +166,10 @@ public class NewTest extends javax.swing.JPanel {
txtTestDescription.setLineWrap(true);
txtTestDescription.setRows(5);
txtTestDescription.setToolTipText("Add here a detailed description");
txtTestDescription.setWrapStyleWord(true);
jScrollPane3.setViewportView(txtTestDescription);
txtContactName.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
txtContactName.setToolTipText("Write here the user name of the person who can be contacted for any question concerning this test");
txtContactName.setMinimumSize(new java.awt.Dimension(6, 26));
txtContactName.setPreferredSize(new java.awt.Dimension(6, 26));
jTableParams.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
jTableParams.setModel(new javax.swing.table.DefaultTableModel(
@@ -207,8 +195,8 @@ public class NewTest extends javax.swing.JPanel {
jTableParams.getColumnModel().getColumn(0).setMinWidth(150);
jTableParams.getColumnModel().getColumn(0).setPreferredWidth(150);
jTableParams.getColumnModel().getColumn(0).setMaxWidth(150);
jTableParams.getColumnModel().getColumn(1).setPreferredWidth(100);
jTableParams.getColumnModel().getColumn(1).setMaxWidth(200);
jTableParams.getColumnModel().getColumn(1).setPreferredWidth(80);
jTableParams.getColumnModel().getColumn(1).setMaxWidth(100);
}
jButtonGenerate.setText("Generate");
@@ -250,7 +238,7 @@ public class NewTest extends javax.swing.JPanel {
.addGroup(layout.createSequentialGroup()
.addComponent(lblParams)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblName)
@@ -263,44 +251,36 @@ public class NewTest extends javax.swing.JPanel {
.addComponent(lblContact))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtTestName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jComboBoxTestSuites, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING))
.addGap(12, 12, 12))
.addGroup(layout.createSequentialGroup()
.addComponent(txtContactName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())))))
.addComponent(txtTestName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jComboBoxTestSuites, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtContactName))
.addGap(12, 12, 12))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblName)
.addComponent(txtTestName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblSuite)
.addComponent(jComboBoxTestSuites, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblName))
.addComponent(txtTestName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
.addComponent(lblDescr))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblSuite)
.addComponent(jComboBoxTestSuites, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
.addComponent(lblDescr))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(lblContact)
.addGap(29, 29, 29))
.addGroup(layout.createSequentialGroup()
.addComponent(txtContactName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
.addComponent(txtContactName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblContact))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblParams)
.addGap(0, 171, Short.MAX_VALUE))
.addGap(0, 132, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
@@ -341,17 +321,11 @@ public class NewTest extends javax.swing.JPanel {
}
}//GEN-LAST:event_jMenuItemDeleteRowActionPerformed
private void txtTestNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTestNameActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtTestNameActionPerformed
/**
* fill table with example parameters
* @param newType of type TypeOfNewFile, can be device or test.
*/
private void fillComponents(TypeOfNewFile newType) {
txtContactName.setText(System.getProperty("user.name"));
// listener for mouse-click also on table header
jTableParams.getTableHeader().addMouseListener(new MouseAdapter() {
@@ -369,9 +343,9 @@ public class NewTest extends javax.swing.JPanel {
this.lblName.setText( newType + " "+ this.lblName.getText());
this.lblName.setToolTipText(newType + " name. Can be a PV name.");
this.txtTestName.setToolTipText(newType + " name. Can be a PV name.");
//lblParams.setVisible(false);
//jTableParams.setVisible(false);
//jScrollPane1.setVisible(false);
lblParams.setVisible(false);
jTableParams.setVisible(false);
jScrollPane1.setVisible(false);
lblContact.setVisible(false);
txtContactName.setVisible(false);
}
@@ -449,7 +423,7 @@ public class NewTest extends javax.swing.JPanel {
String[] dsParameterAttributes = null;
String[] dsParameters = parametersString.split(";");
for (String sParameter : dsParameters) {
dsParameterAttributes = sParameter.split("&");
dsParameterAttributes = sParameter.split(":");
if (dsParameterAttributes.length > 2) {
mParameterAttributes = new HashMap();
mParameterAttributes.put("value", (Object) dsParameterAttributes[1]);
@@ -784,7 +758,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 generateTestConfigOld(Path templateDir,
public boolean generateTestConfig(Path templateDir,
Path testDir,
String sTestName,
String sTestDescription,
@@ -810,7 +784,7 @@ public class NewTest extends javax.swing.JPanel {
value = (String) attributes.get("value");
description = (String) attributes.get("description");
//build the python code for getting the test parameter
sTestParameters = sTestParameters + name + VALUE_SEPARATOR + value + VALUE_SEPARATOR + description + PARAM_SEPARATOR ;
sTestParameters = sTestParameters + name + ":" + value + ":" + description + ";" ;
}
}
FileInputStream in = new FileInputStream(configFile);
@@ -844,101 +818,6 @@ 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_SEPARATOR + "\"" + value + "\"" + VALUE_SEPARATOR + "\"" + description + "\"" + PARAM_SEPARATOR ;
}
}
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);
props.setProperty("parameters", sTestParameters);
}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
*