refactor
This commit is contained in:
parent
cf30603c7a
commit
1289751bc3
|
@ -3,7 +3,6 @@ package org.bench4q.master.scriptrecord.httpcapture;
|
|||
import java.util.Vector;
|
||||
|
||||
public class Action {
|
||||
private static String LINE_SEP = System.getProperty("line.separator");
|
||||
private String url;
|
||||
private String method;
|
||||
private String expected_result;
|
||||
|
@ -15,8 +14,7 @@ public class Action {
|
|||
private Vector<Param> bodyParams;
|
||||
private String multiPartData;
|
||||
|
||||
public Action()
|
||||
{
|
||||
public Action() {
|
||||
this.headers = new Vector<HeaderValue>();
|
||||
this.queryStringParams = new Vector<Param>();
|
||||
this.bodyParams = new Vector<Param>();
|
||||
|
@ -24,119 +22,97 @@ public class Action {
|
|||
this.multiPartData = "";
|
||||
}
|
||||
|
||||
public void setUrl(String url)
|
||||
{
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setMethod(String method)
|
||||
{
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getMethod()
|
||||
{
|
||||
public String getMethod() {
|
||||
return this.method;
|
||||
}
|
||||
|
||||
public void setExpectedResult(String str)
|
||||
{
|
||||
public void setExpectedResult(String str) {
|
||||
this.expected_result = str;
|
||||
}
|
||||
|
||||
public String getExpectedResult()
|
||||
{
|
||||
public String getExpectedResult() {
|
||||
return this.expected_result;
|
||||
}
|
||||
|
||||
public void setDelayTime(int seconds)
|
||||
{
|
||||
public void setDelayTime(int seconds) {
|
||||
this.delayTime = seconds;
|
||||
}
|
||||
|
||||
public int getDelayTime()
|
||||
{
|
||||
public int getDelayTime() {
|
||||
return this.delayTime;
|
||||
}
|
||||
|
||||
public void setExpectedSize(int bytes)
|
||||
{
|
||||
public void setExpectedSize(int bytes) {
|
||||
this.expected_size = bytes;
|
||||
}
|
||||
|
||||
public int getExpectedSize()
|
||||
{
|
||||
public int getExpectedSize() {
|
||||
return this.expected_size;
|
||||
}
|
||||
|
||||
public void setTimeout(int seconds)
|
||||
{
|
||||
public void setTimeout(int seconds) {
|
||||
this.timeout = seconds;
|
||||
}
|
||||
|
||||
public int getTimeout()
|
||||
{
|
||||
public int getTimeout() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
public int getHeaderCount()
|
||||
{
|
||||
public int getHeaderCount() {
|
||||
return this.headers.size();
|
||||
}
|
||||
|
||||
public HeaderValue[] getHeaders()
|
||||
{
|
||||
public HeaderValue[] getHeaders() {
|
||||
HeaderValue[] list = new HeaderValue[this.headers.size()];
|
||||
this.headers.copyInto(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public void addHeader(HeaderValue p)
|
||||
{
|
||||
public void addHeader(HeaderValue p) {
|
||||
this.headers.addElement(p);
|
||||
}
|
||||
|
||||
public void removeHeader(HeaderValue p)
|
||||
{
|
||||
public void removeHeader(HeaderValue p) {
|
||||
this.headers.removeElement(p);
|
||||
}
|
||||
|
||||
public int getParamsCount()
|
||||
{
|
||||
public int getParamsCount() {
|
||||
return getParams().length;
|
||||
}
|
||||
|
||||
public int getQueryStringParamCount()
|
||||
{
|
||||
public int getQueryStringParamCount() {
|
||||
return this.queryStringParams.size();
|
||||
}
|
||||
|
||||
public int getBodyParamCount()
|
||||
{
|
||||
public int getBodyParamCount() {
|
||||
return this.bodyParams.size();
|
||||
}
|
||||
|
||||
public Param[] getQueryStringParams()
|
||||
{
|
||||
public Param[] getQueryStringParams() {
|
||||
Param[] list = new Param[this.queryStringParams.size()];
|
||||
this.queryStringParams.copyInto(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public Param[] getBodyParams()
|
||||
{
|
||||
public Param[] getBodyParams() {
|
||||
Param[] list = new Param[this.bodyParams.size()];
|
||||
this.bodyParams.copyInto(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public Param[] getParams()
|
||||
{
|
||||
public Param[] getParams() {
|
||||
@SuppressWarnings("unchecked")
|
||||
Vector<Param> v = (Vector<Param>) this.queryStringParams.clone();
|
||||
v.addAll(this.bodyParams);
|
||||
|
@ -145,65 +121,27 @@ public class Action {
|
|||
return list;
|
||||
}
|
||||
|
||||
public void addQueryStringParam(Param p)
|
||||
{
|
||||
public void addQueryStringParam(Param p) {
|
||||
this.queryStringParams.addElement(p);
|
||||
}
|
||||
|
||||
public void addBodyParam(Param p)
|
||||
{
|
||||
public void addBodyParam(Param p) {
|
||||
this.bodyParams.addElement(p);
|
||||
}
|
||||
|
||||
public void removeQueryStringParam(Param p)
|
||||
{
|
||||
public void removeQueryStringParam(Param p) {
|
||||
this.queryStringParams.removeElement(p);
|
||||
}
|
||||
|
||||
public void removeBodyParam(Param p)
|
||||
{
|
||||
public void removeBodyParam(Param p) {
|
||||
this.bodyParams.removeElement(p);
|
||||
}
|
||||
|
||||
public String toXML()
|
||||
{
|
||||
StringBuffer str = new StringBuffer(1024);
|
||||
str.append(" ");
|
||||
str.append("<action url=\"").append(this.url).append("\" ");
|
||||
str.append(LINE_SEP).append(" ");
|
||||
str.append("method=\"").append(this.method).append("\" ");
|
||||
str.append(LINE_SEP).append(" ");
|
||||
str.append("delayTime=\"").append(this.delayTime).append("\" ");
|
||||
str.append(LINE_SEP).append(" ");
|
||||
str.append("expected-result=\"").append(this.expected_result).append("\"");
|
||||
str.append(LINE_SEP).append(" ");
|
||||
str.append("expected-result-size=\"").append(this.expected_size).append("\"");
|
||||
str.append(LINE_SEP).append(" ");
|
||||
str.append("timeout=\"").append(this.timeout).append("\">");
|
||||
Param[] params = getQueryStringParams();
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
str.append(LINE_SEP).append(" ");
|
||||
str.append("<param name=\"").append(params[i].name);
|
||||
str.append("\" value=\"").append(params[i].value).append("\"/>");
|
||||
}
|
||||
params = getBodyParams();
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
str.append(LINE_SEP).append(" ");
|
||||
str.append("<param name=\"").append(params[i].name);
|
||||
str.append("\" value=\"").append(params[i].value).append("\"/>");
|
||||
}
|
||||
str.append(LINE_SEP);
|
||||
str.append(" </action>");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
public void setMultiPartData(String multiPartData)
|
||||
{
|
||||
public void setMultiPartData(String multiPartData) {
|
||||
this.multiPartData = multiPartData;
|
||||
}
|
||||
|
||||
public String getMultiPartData()
|
||||
{
|
||||
public String getMultiPartData() {
|
||||
return this.multiPartData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,10 +205,9 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
doSetData(new String(requestBody, newCharset));
|
||||
else
|
||||
doSetData(new String(requestBody));
|
||||
|
||||
} else if (newCharset != null)
|
||||
} else if (newCharset != null) {
|
||||
setBodyParams(action, new String(requestBody, newCharset));
|
||||
else {
|
||||
} else {
|
||||
setBodyParams(action, new String(requestBody));
|
||||
}
|
||||
|
||||
|
@ -216,7 +215,6 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
|
||||
if (action.getParamsCount() > 0) {
|
||||
params = action.getParams();
|
||||
|
||||
for (i = 0; i < params.length; ++i) {
|
||||
name = params[i].name;
|
||||
value = params[i].value;
|
||||
|
@ -277,7 +275,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
}
|
||||
|
||||
this.requestCount++;
|
||||
doCallUrl(action.getUrl(), method, data_str, cont_len_str);
|
||||
doCallUrl(action, method, data_str, cont_len_str);
|
||||
}
|
||||
|
||||
private String doForCharset(String contentType) throws UserException {
|
||||
|
@ -385,7 +383,7 @@ public abstract class AbstractCodeGenerator implements IScriptGenerator,
|
|||
public abstract void doAssertResponse(String paramString)
|
||||
throws Utils.UserException;
|
||||
|
||||
public abstract void doCallUrl(String paramString1, String paramString2,
|
||||
public abstract void doCallUrl(Action action, String paramString2,
|
||||
String paramString3, String paramString4)
|
||||
throws Utils.UserException;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.scriptrecord.httpcapture.Action;
|
||||
import org.bench4q.master.scriptrecord.httpcapture.Config;
|
||||
import org.bench4q.master.scriptrecord.httpcapture.HeaderValue;
|
||||
import org.bench4q.master.scriptrecord.httpcapture.IScriptAdapter;
|
||||
|
@ -154,13 +155,12 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
|||
public void doSetData(String data) {
|
||||
}
|
||||
|
||||
public void doCallUrl(String url, String method, String data,
|
||||
public void doCallUrl(Action action, String method, String data,
|
||||
String contentLength) throws Utils.UserException {
|
||||
if ((!isFirstRequest())
|
||||
&& (!this.getScriptAdapter().isInChildrenUrl(url)))
|
||||
if (!isFirstRequest())
|
||||
doInsertDelay(getTimeElapsedSinceLastestRequest());
|
||||
UserBehaviorModel userBehavior = createHttpBehavior(
|
||||
this.getRequestCount(), url, method);
|
||||
this.getRequestCount(), action.getUrl(), method);
|
||||
insertBehavior(userBehavior);
|
||||
|
||||
this.queryStringParameters = "";
|
||||
|
@ -191,7 +191,6 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
|||
userBehavior.setName(method);
|
||||
userBehavior.setUse("http");
|
||||
userBehavior.setParameters(params);
|
||||
|
||||
return userBehavior;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public class TestCodeGenerator extends TestRecordBase {
|
|||
new RunScenarioModel());
|
||||
private Bench4qCodeGenerator codeGenerator = new Bench4qCodeGenerator(
|
||||
this.scriptAdapter);
|
||||
private static String dealWithSerie = "Script/gzip/gzipBaiduIR";
|
||||
private static String dealWithSerie = "RecordScriptTestCase/gzip/gzipBaiduIR";
|
||||
|
||||
@Test
|
||||
public void testProcessResponse() throws Exception {
|
||||
|
@ -53,7 +53,8 @@ public class TestCodeGenerator extends TestRecordBase {
|
|||
public void testGetContentBodyWithoutCompress() throws IOException {
|
||||
String contentString = new String(
|
||||
new ResponseParser().parseReponseBody(FileUtils
|
||||
.readFileToString(new File("Script/simpleResponse.txt"))));
|
||||
.readFileToString(new File(
|
||||
"RecordScriptTestCase/simpleResponse.txt"))));
|
||||
assertTrue(contentString.indexOf("<html") == 0);
|
||||
assertTrue(contentString.length() == 532);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue