This commit is contained in:
coderfengyun 2013-12-18 15:35:48 +08:00
parent cf30603c7a
commit 1289751bc3
4 changed files with 123 additions and 187 deletions

View File

@ -3,207 +3,145 @@ 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;
private int delayTime;
private int expected_size;
private int timeout;
private Vector<HeaderValue> headers;
private Vector<Param> queryStringParams;
private Vector<Param> bodyParams;
private String multiPartData;
private String url;
private String method;
private String expected_result;
private int delayTime;
private int expected_size;
private int timeout;
private Vector<HeaderValue> headers;
private Vector<Param> queryStringParams;
private Vector<Param> bodyParams;
private String multiPartData;
public Action()
{
this.headers = new Vector<HeaderValue>();
this.queryStringParams = new Vector<Param>();
this.bodyParams = new Vector<Param>();
this.expected_result = "";
this.multiPartData = "";
}
public Action() {
this.headers = new Vector<HeaderValue>();
this.queryStringParams = new Vector<Param>();
this.bodyParams = new Vector<Param>();
this.expected_result = "";
this.multiPartData = "";
}
public void setUrl(String url)
{
this.url = url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl()
{
return this.url;
}
public String getUrl() {
return this.url;
}
public void setMethod(String method)
{
this.method = method;
}
public void setMethod(String method) {
this.method = method;
}
public String getMethod()
{
return this.method;
}
public String getMethod() {
return this.method;
}
public void setExpectedResult(String str)
{
this.expected_result = str;
}
public void setExpectedResult(String str) {
this.expected_result = str;
}
public String getExpectedResult()
{
return this.expected_result;
}
public String getExpectedResult() {
return this.expected_result;
}
public void setDelayTime(int seconds)
{
this.delayTime = seconds;
}
public void setDelayTime(int seconds) {
this.delayTime = seconds;
}
public int getDelayTime()
{
return this.delayTime;
}
public int getDelayTime() {
return this.delayTime;
}
public void setExpectedSize(int bytes)
{
this.expected_size = bytes;
}
public void setExpectedSize(int bytes) {
this.expected_size = bytes;
}
public int getExpectedSize()
{
return this.expected_size;
}
public int getExpectedSize() {
return this.expected_size;
}
public void setTimeout(int seconds)
{
this.timeout = seconds;
}
public void setTimeout(int seconds) {
this.timeout = seconds;
}
public int getTimeout()
{
return this.timeout;
}
public int getTimeout() {
return this.timeout;
}
public int getHeaderCount()
{
return this.headers.size();
}
public int getHeaderCount() {
return this.headers.size();
}
public HeaderValue[] getHeaders()
{
HeaderValue[] list = new HeaderValue[this.headers.size()];
this.headers.copyInto(list);
return list;
}
public HeaderValue[] getHeaders() {
HeaderValue[] list = new HeaderValue[this.headers.size()];
this.headers.copyInto(list);
return list;
}
public void addHeader(HeaderValue p)
{
this.headers.addElement(p);
}
public void addHeader(HeaderValue p) {
this.headers.addElement(p);
}
public void removeHeader(HeaderValue p)
{
this.headers.removeElement(p);
}
public void removeHeader(HeaderValue p) {
this.headers.removeElement(p);
}
public int getParamsCount()
{
return getParams().length;
}
public int getParamsCount() {
return getParams().length;
}
public int getQueryStringParamCount()
{
return this.queryStringParams.size();
}
public int getQueryStringParamCount() {
return this.queryStringParams.size();
}
public int getBodyParamCount()
{
return this.bodyParams.size();
}
public int getBodyParamCount() {
return this.bodyParams.size();
}
public Param[] getQueryStringParams()
{
Param[] list = new Param[this.queryStringParams.size()];
this.queryStringParams.copyInto(list);
return list;
}
public Param[] getQueryStringParams() {
Param[] list = new Param[this.queryStringParams.size()];
this.queryStringParams.copyInto(list);
return list;
}
public Param[] getBodyParams()
{
Param[] list = new Param[this.bodyParams.size()];
this.bodyParams.copyInto(list);
return list;
}
public Param[] getBodyParams() {
Param[] list = new Param[this.bodyParams.size()];
this.bodyParams.copyInto(list);
return list;
}
public Param[] getParams()
{
@SuppressWarnings("unchecked")
Vector<Param> v = (Vector<Param>)this.queryStringParams.clone();
v.addAll(this.bodyParams);
Param[] list = new Param[v.size()];
v.copyInto(list);
return list;
}
public Param[] getParams() {
@SuppressWarnings("unchecked")
Vector<Param> v = (Vector<Param>) this.queryStringParams.clone();
v.addAll(this.bodyParams);
Param[] list = new Param[v.size()];
v.copyInto(list);
return list;
}
public void addQueryStringParam(Param p)
{
this.queryStringParams.addElement(p);
}
public void addQueryStringParam(Param p) {
this.queryStringParams.addElement(p);
}
public void addBodyParam(Param p)
{
this.bodyParams.addElement(p);
}
public void addBodyParam(Param p) {
this.bodyParams.addElement(p);
}
public void removeQueryStringParam(Param p)
{
this.queryStringParams.removeElement(p);
}
public void removeQueryStringParam(Param p) {
this.queryStringParams.removeElement(p);
}
public void removeBodyParam(Param p)
{
this.bodyParams.removeElement(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) {
this.multiPartData = multiPartData;
}
public void setMultiPartData(String multiPartData)
{
this.multiPartData = multiPartData;
}
public String getMultiPartData()
{
return this.multiPartData;
}
public String getMultiPartData() {
return this.multiPartData;
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}