void createJMeterSuitePerformed() { Project pProject = DataModel.getCurrentProject(); TestList pTestList = null; Family pFamily = null; Test pTest = null; DefaultMutableTreeNode pNode = SalomeTMFPanels.getTestDynamicTree().getSelectedNode(); if (pNode == null) { return; } else { SimpleData pData = (SimpleData) pNode.getUserObject(); if (pData instanceof Family) { pFamily = (Family) pData; } else if (pData instanceof TestList) { pTestList = (TestList) pData; } else if (pData instanceof Test) { pTest = (Test) pData; } } if (pTestList != null) { Util.log("Test List selected = " + pTestList.getNameFromModel()); JMeterTester pMeterTester = new JMeterTester(null, true, pProject, true, "", "", "", ""); if (pMeterTester.execute()) { Util.log("[JMeterIntegrationPlugin:editTest] ok pressed"); Attachment pNewattach = pMeterTester.getNewAttachment(); Attachment pSelectedattach = pMeterTester.getSelectedAttachment(); String toWrite = "attachment_id = "; if (pSelectedattach != null) { if (pSelectedattach.equals(pNewattach)) { if (!addAttachmentToProject(pNewattach, DataModel.getCurrentProject())) return; } toWrite += pSelectedattach.getIdBdd() + "\n"; toWrite += "attachment_name = " + pSelectedattach.getNameFromModel() + "\n"; } else { toWrite += "\nattachment_name = \n"; } toWrite += "junit_class = " + pMeterTester.getJunitClass() + "\n"; try { if (!pTestList.isInBase()) { pTestList.updateInModel(pMeterTester.getJunitClass(), "JMETER TEST SUITE"); pFamily.addTestListInDB(pTestList); } // currentJunitAnalyser.createJunitTest(pSelectedattach, // pJunitTester.getJunitClass(), pTestList, toWrite); } catch (Exception e1) { Tools.ihmExceptionView(e1); } } } }
void addTest(String name, String description, String[] idReqs, TestList pSuite, String toWrite) { name = getTestName(name, pSuite, 0); AutomaticTest pTest = new AutomaticTest(name, description, id_plugin); pTest.setConceptorLoginInModel(DataModel.getCurrentUser().getLoginFromModel()); if (Api.isConnected()) { try { pSuite.addTestInDBAndModel(pTest); } catch (Exception e1) { Tools.ihmExceptionView(e1); return; } } File file = null; try { Util.log("[JMeterIntegrationPlugin:AddTest] Create test Script file"); file = writeJunitFile(null, pTest, toWrite); } catch (Exception e2) { Tools.ihmExceptionView(e2); e2.printStackTrace(); return; } Script pScript = new Script(file.getName(), "Junit test script"); pScript.setLocalisation(file.getAbsolutePath()); pScript.setTypeInModel(ApiConstants.TEST_SCRIPT); pScript.setScriptExtensionInModel(pTest.getExtensionFromModel()); // pScript.setPlugArg(""); if (Api.isConnected()) { try { pTest.addScriptInDBAndModel(pScript, file); Util.log( "[JMeterIntegrationPlugin:AddTest] Add Script : " + pScript.getNameFromModel() + " to DB & Model"); } catch (Exception e3) { Tools.ihmExceptionView(e3); return; } } // add associated requirements Vector<ReqManager> reqManagers = pIPlugObject.getReqManagers(); for (ReqManager reqManager : reqManagers) { for (String idReqString : idReqs) { int idReq = new Integer(idReqString).intValue(); reqManager.addReqLinkWithTest(pTest, idReq); } } }
public String updateTestScript( String testScript, org.objectweb.salome_tmf.data.AutomaticTest pTest) { String strNewId = ""; try { File pFile = new File(testScript); FileInputStream pFileInputStream = new FileInputStream(pFile); Properties test_prop = new Properties(); test_prop.load(pFileInputStream); // Utile.getPropertiesFile(testScript); String strID = test_prop.getProperty("attachment_id"); String strAttachment = test_prop.getProperty("attachment_name"); String strClass = test_prop.getProperty("junit_class"); String meth = test_prop.getProperty("test_meth"); String version = test_prop.getProperty("junit_version"); pFileInputStream.close(); Hashtable tabAttach = new Hashtable(DataModel.getCurrentProject().getAttachmentMapFromModel()); Enumeration e = tabAttach.elements(); boolean trouve = false; while (e.hasMoreElements() && !trouve) { Attachment pAttach = (Attachment) e.nextElement(); if (pAttach.getDescriptionFromModel().equals(JMeterTester.jMeterDescAttach) && pAttach.getNameFromModel().equals(strAttachment)) { strNewId = "" + pAttach.getIdBdd(); trouve = true; } } // ADD PROJECT PATH String toWrite = "attachment_id = " + strNewId + "\n"; toWrite += "attachment_name = " + strAttachment + "\n"; toWrite += "junit_class = " + strClass + "\n"; toWrite += "test_meth = " + meth + "\n"; toWrite += "junit_version = " + version + "\n"; File newFile = writeJunitFile(pFile, pTest, toWrite); Script pScript = pTest.getScriptFromModel(); pScript.updateInDB(newFile); } catch (Exception e) { } return strNewId; }
java.io.File ChoiceOrEdit( AutomaticTest pTest, boolean choice, File pFile, String strID, String strAttachment, String strClass, String meth, String version) { JMeterTester pJMeterTester = new JMeterTester(null, true, pTest, choice, strID, strAttachment, strClass, meth, version); if (pJMeterTester.execute()) { Util.log("[JMeterIntegrationPlugin:editTest] ok pressed"); Attachment pNewattach = pJMeterTester.getNewAttachment(); Attachment pSelectedattach = pJMeterTester.getSelectedAttachment(); String toWrite = "attachment_id = "; if (pSelectedattach != null) { if (pSelectedattach.equals(pNewattach)) { if (!addAttachmentToProject(pNewattach, DataModel.getCurrentProject())) return null; } toWrite += pSelectedattach.getIdBdd() + "\n"; toWrite += "attachment_name = " + pSelectedattach.getNameFromModel() + "\n"; } else { toWrite += "\nattachment_name = \n"; } toWrite += "junit_class = " + pJMeterTester.getJunitClass() + "\n"; toWrite += "test_meth = " + pJMeterTester.getJunitMeth() + "\n"; if (version != null) { toWrite += "junit_version = " + version + "\n"; version = version.trim(); } try { File f = writeJunitFile(pFile, pTest, toWrite); return f; } catch (Exception e) { Tools.ihmExceptionView(e); e.printStackTrace(); return null; } } else { Util.log("[JMeterIntegrationPlugin:editTest] cancel pressed"); return null; } }