lv.ctco.cukesrest.loadrunner.function.WebCustomRequest Maven / Gradle / Ivy
package lv.ctco.cukesrest.loadrunner.function;
import org.apache.commons.lang3.*;
import java.util.*;
public class WebCustomRequest implements LoadRunnerFunction {
private String name;
private String url;
private String method;
private String resource;
private String mode;
private String body;
private String snapshot;
private List beforeFunctions = new ArrayList();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getResource() {
return resource;
}
public void setResource(String resource) {
this.resource = resource;
}
public String getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getSnapshot() {
return snapshot;
}
public void setSnapshot(String snapshot) {
this.snapshot = snapshot;
}
public List getBeforeFunctions() {
return beforeFunctions;
}
public void setBeforeFunctions(List beforeFunctions) {
this.beforeFunctions = beforeFunctions;
}
public String format() {
StringBuilder result = new StringBuilder();
for (LoadRunnerFunction function : beforeFunctions) {
result.append(function.format());
}
if (beforeFunctions.size() > 0) result.append("\n");
result.append("web_custom_request(\"").append(name).append("\",\n");
appendOptionalParameter("URL", url, result);
appendOptionalParameter("Method", method, result);
appendOptionalParameter("Resource", resource, result);
appendOptionalParameter("Mode", mode, result);
appendOptionalParameter("Body", body, result);
appendOptionalParameter("Snapshot", snapshot, result);
return result.append("LAST);\n\n").toString();
}
private void appendOptionalParameter(String title, String value, StringBuilder stringBuilder) {
if (!StringUtils.isEmpty(value))
stringBuilder.append("\"")
.append(title)
.append("=")
.append(StringEscapeUtils.escapeJava(value))
.append("\",\n");
}
}