-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f05dce
commit 4ca3fdd
Showing
11 changed files
with
508 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
backend/src/main/java/ca/etsmtl/taf/jmeter/model/FTPTestPlan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
package ca.etsmtl.taf.jmeter.model; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
public class FTPTestPlan { | ||
|
||
|
||
private String nbThreads ; | ||
private String rampTime ; | ||
private String duration ; | ||
private String domain ; | ||
private String port ; | ||
private String method; | ||
private String remotefile; | ||
private String localfile; | ||
private String username; | ||
private String password; | ||
private String loop; | ||
public FTPTestPlan() { | ||
|
||
} | ||
|
||
public FTPTestPlan(String nbThreads, String rampTime, | ||
String duration, String domain, String port, | ||
String remotefile, String localfile, String method, String username, String password) { | ||
this.nbThreads = nbThreads; | ||
this.rampTime = rampTime; | ||
this.duration = duration; | ||
this.domain = domain; | ||
this.port = port; | ||
this.method = method; | ||
this.remotefile = remotefile; | ||
this.localfile = localfile; | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
public String getLoop() { | ||
|
||
return loop; | ||
} | ||
|
||
public void setLoop(String loop) { | ||
this.loop = loop; | ||
} | ||
|
||
public String getNbThreads() { | ||
return nbThreads; | ||
} | ||
|
||
public void setNbThreads(String nbThreads) { | ||
this.nbThreads = nbThreads; | ||
} | ||
|
||
public String getRampTime() { | ||
return rampTime; | ||
} | ||
|
||
public void setRampTime(String rampTime) { | ||
this.rampTime = rampTime; | ||
} | ||
|
||
public String getDuration() { | ||
return duration; | ||
} | ||
|
||
public void setDuration(String duration) { | ||
this.duration = duration; | ||
} | ||
|
||
public String getDomain() { | ||
return domain; | ||
} | ||
|
||
public void setDomain(String domain) { | ||
this.domain = domain; | ||
} | ||
|
||
public String getPort() { | ||
return port; | ||
} | ||
|
||
public void setPort(String port) { | ||
this.port = port; | ||
} | ||
|
||
public String getRemotefile() { | ||
return remotefile; | ||
} | ||
|
||
public void setRemotefile(String remotefile) { | ||
this.remotefile = remotefile; | ||
} | ||
|
||
public String getLocalfile() { | ||
return localfile; | ||
} | ||
|
||
public void setLocalfile(String localfile) { | ||
this.localfile = localfile; | ||
} | ||
|
||
public String getMethod() { | ||
return method=="get"? "false" : "true"; | ||
|
||
} | ||
|
||
public void setMethod(String method) { | ||
this.method = method; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
|
||
public void generateTestPlan() { | ||
replaceAndSaveVariables(); | ||
} | ||
private void replaceAndSaveVariables() { | ||
try { | ||
// Read the XML content from the file | ||
String filePath = "backend/src/main/resources/jmeter/FTPSamplerTemplate.jmx"; | ||
String xmlContent = new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8); | ||
String target = "backend/src/main/resources/jmeter/FTPTestPlan.jmx"; | ||
|
||
// Replace variables with Java variables (using default values if not found) | ||
xmlContent = replaceVariables(xmlContent); | ||
|
||
// Save the modified content back to the file | ||
Files.write(Paths.get(target), xmlContent.getBytes(StandardCharsets.UTF_8)); | ||
|
||
System.out.println("Variables replaced successfully."); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private String replaceVariables(String xmlContent) { | ||
// Replace variables in the XML content using instance fields | ||
xmlContent = xmlContent.replace("$NB_THREADS$", nbThreads) | ||
.replace("$RAMP_TIME$", rampTime) | ||
.replace("$DURATION$", duration) | ||
.replace("$DOMAIN$", domain) | ||
.replace("$PORT$", port) | ||
.replace("$REMOTEFILE$", remotefile) | ||
.replace("$LOCALFILE$", localfile) | ||
.replace("$METHOD$", getMethod()) | ||
.replace("$USERNAME$", username) | ||
.replace("$PASSWORD$", password) | ||
.replace("$LOOP_COUNTER$", loop); | ||
|
||
|
||
return xmlContent; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JmeterFTPTestPlan{" + | ||
"nbThreads='" + nbThreads + '\'' + | ||
", rampTime='" + rampTime + '\'' + | ||
", duration='" + duration + '\'' + | ||
", domain='" + domain + '\'' + | ||
", port='" + port + '\'' + | ||
", remotefile='" + remotefile + '\'' + | ||
", localfile='" + localfile + "\'" + | ||
", method='" + method + '\'' + | ||
", username='" + username + '\'' + | ||
", password='" + password + '\''+ | ||
'}'; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.5"> | ||
<hashTree> | ||
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true"> | ||
<boolProp name="TestPlan.functional_mode">false</boolProp> | ||
<boolProp name="TestPlan.tearDown_on_shutdown">false</boolProp> | ||
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp> | ||
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" | ||
guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" | ||
enabled="true"> | ||
<collectionProp name="Arguments.arguments" /> | ||
</elementProp> | ||
</TestPlan> | ||
<hashTree> | ||
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" | ||
enabled="true"> | ||
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp> | ||
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" | ||
guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" | ||
enabled="true"> | ||
<boolProp name="LoopController.continue_forever">false</boolProp> | ||
<stringProp name="LoopController.loops">$LOOP_COUNTER$</stringProp> | ||
</elementProp> | ||
<stringProp name="ThreadGroup.num_threads">$NB_THREADS$</stringProp> | ||
<stringProp name="ThreadGroup.ramp_time">$RAMP_TIME$</stringProp> | ||
<boolProp name="ThreadGroup.scheduler">false</boolProp> | ||
<stringProp name="ThreadGroup.duration"></stringProp> | ||
<stringProp name="ThreadGroup.delay"></stringProp> | ||
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp> | ||
</ThreadGroup> | ||
<hashTree> | ||
<FTPSampler guiclass="FtpTestSamplerGui" testclass="FTPSampler" testname="FTP Request" | ||
enabled="true"> | ||
<stringProp name="FTPSampler.server">$DOMAIN$</stringProp> | ||
<stringProp name="FTPSampler.port">$PORT$</stringProp> | ||
<stringProp name="FTPSampler.filename">$REMOTEFILE$</stringProp> | ||
<stringProp name="FTPSampler.localfilename">$LOCALFILE$</stringProp> | ||
<stringProp name="FTPSampler.inputdata"></stringProp> | ||
<boolProp name="FTPSampler.binarymode">false</boolProp> | ||
<boolProp name="FTPSampler.saveresponse">false</boolProp> | ||
<boolProp name="FTPSampler.upload">$METHOD$</boolProp> | ||
<stringProp name="ConfigTestElement.username">$USERNAME$</stringProp> | ||
<stringProp name="ConfigTestElement.password">$PASSWORD$</stringProp> | ||
</FTPSampler> | ||
<hashTree /> | ||
</hashTree> | ||
</hashTree> | ||
</hashTree> | ||
</jmeterTestPlan> |
Oops, something went wrong.