In the near future, a distributed pressure testing framework is on the agenda, and FunTester already has some of the functions used in distributed pressure testing.
For example, in the execution of the use case side: the use of reflection according to the method name to execute the method example, command line how to execute the jar package inside the method; Or in the use case writing side: how to unify the function of the interface test, automation and performance test cases, how to perform performance test happily in the Linux command line interface; Groovy reflection implementation method NoSuchMethodException solution, Groovy reflection invokeMethod parameter pass practice.
So far there have been several rough performance test case scenarios, some of which have been implemented and some of which I have abandoned. Share it out, sort of a comb.
The test case scenarios here fall into two categories: use case delivery and use case execution. At present, MY idea is to complete the use case transfer and execution control through the HTTP protocol interface. Control of execution in the form of scheduled tasks or round-robin polling. It’s definitely a Springboot project by now, but that’s another story.
Let’s share the first scenario:
Compression scenarios based on HttpRequestBase objects
This test scenario should be said very few, based on a single or multiple fixed HttpRequestBase object distributed pressure solution, in fact, a bit of overkill implementation. Simple request, no parameterization rules, no upstream and downstream interface calls, no pre – and post-processing, lack of link function support. With that said, the advantages of HttpRequestBase objects are simple to implement and very easy to do with use-case passing. Execution can also be done directly using the capabilities provided by the framework. Good compatibility, you can directly extract part of the use cases from the functional use cases and then execute, to achieve the purpose of multi-use cases.
To realize the Demo
There is a need to distinguish between use case sources. In general, writing a single use case can’t take you around a diagram:
The total is divided into three parts: the request line, the request header, and the request body. Take an HttpRequestBase object and split it into three sections, as we shared earlier. For example, we get a request as follows:
public static void main(String[] args) throws UnsupportedEncodingException {
HttpPost httpPost = getHttpPost("http://localhost:12345/test/qps");
httpPost.addHeader(getHeader("token"."324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
}
Copy the code
However, this does not help HttpRequestBase objects pass through the HTTP interface because there are no direct serialization and deserialization methods. So I wrote an intermediate object myself.
The initial idea was implemented with fastJSON:
public static void main(String[] args) {
HttpPost httpPost = getHttpPost("http://localhost:12345/test/qps");
httpPost.addHeader(getHeader("token"."324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
JSONObject httpResponse = getHttpResponse(httpPost);
output(httpResponse);
String s = JSON.toJSONString(httpPost);
HttpPost httpPost1 = JSON.parseObject(s, httpPost.getClass());
JSONObject httpResponse1 = getHttpResponse(httpPost1);
output(httpResponse1);
}
Copy the code
The test results are as follows:
INFO->The current user: oker, working directory: / Users/oker/IdeaProjects funtester/system coding formats: utf-8, Mac OS X system version: 10.16
WARN->The response body is not in JSON format and has been automatically converted to JSON format!
INFO->Request URI: http://localhost:12345/test/ QPS, time: 236ms, HTTPcode: 200
INFO-> ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ JSON ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ > {> (1). The "code" : 2, > 1). The "FunTester" : 200, > (1). "content" : "FunTester" >} ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ ~ ☢ ~ JSON ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~WARN->Error obtaining POST request parameters!
WARN->The fetch request failed! Request content :{requestType='POST', host=' ', apiName=' ', uri='http://localhost:12345/test/qps', headers={"Connection":"keep-alive"}, args={}, params={}, json={}, response={}}java.lang.UnsupportedOperationException: public abstract int org.apache.http.params.HttpParams.getIntParameter(java.lang.String,int) at Com. Alibaba. Fastjson. JSONObject. Invoke (JSONObject. Java: 485) ~ / fastjson - 1.2.62. Jar:? at com.sun.proxy.$Proxy22.getIntParameter(Unknown Source) ~[?:?] at org.apache.http.client.params.HttpClientParamConfig.getRequestConfig(HttpClientParamConfig.java:59) ~ [httpclient - 4.5.6. Jar: 4.5.6] at org. Apache. HTTP. Impl. Client. InternalHttpClient. The doExecute (InternalHttpClient. Java: 177) ~ [httpclient - 4.5.6. Jar: 4.5.6] at org. Apache. HTTP. Impl. Client. CloseableHttpClient. Execute (CloseableHttpClient. Java: 83) ~ [httpclient - 4.5.6. Jar: 4.5.6] at org. Apache. HTTP. Impl. Client. CloseableHttpClient. Execute (CloseableHttpClient. Java: 108) ~ [httpclient - 4.5.6. Jar: 4.5.6] at the funtester. Httpclient. FunLibrary. GetHttpResponse FunLibrary. Java: (352)/classes / :? at com.funtest.javatest.FF.main(FF.java:21) [classes/:?]INFO->The JSON object is empty!
Process finished with exit code 0
Copy the code
Error: POST request entity copy failed. So this method doesn’t work anymore, so I have to change to a self-implementation.
public static void main(String[] args) {
HttpPost httpPost = getHttpPost("http://localhost:12345/post");
httpPost.addHeader(getHeader("token"."324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
JSONObject httpResponse = getHttpResponse(httpPost);
output(httpResponse);
FunRequest funRequest = FunRequest.initFromRequest(httpPost);
HttpRequestBase request = funRequest.getRequest();
JSONObject httpResponse1 = getHttpResponse(request);
output(httpResponse1);
String text = JSON.toJSONString(funRequest);
HttpRequestBase httpRequestBase = FunRequest.initFromString(text).getRequest();
JSONObject httpResponse2 = getHttpResponse(httpRequestBase);
output(httpResponse2);
}
Copy the code
The test results are as follows:
INFO - > the current user: oker, working directory: / Users/oker/IdeaProjects funtester/system coding format: utf-88Mac OS X version:10.16WARN-> The response body is not in JSON format and has been automatically converted to JSON format! INFO-> Request URI: HTTP://localhost:12345/post, time: 242 ms, HTTPcode: 200INFO - > ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ JSON ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ > {> (1)."code": -2> 1)."FunTester":200> 1)."content":"FunTester">} ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ JSON ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ WARN - > response body the JSON format, and is automatically converted to JSON format! INFO-> Request URI: HTTP://localhost:12345/post, time :1 ms, HTTPcode: 200INFO - > ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ JSON ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ > {> (1)."code": -2> 1)."FunTester":200> 1)."content":"FunTester">} ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ JSON ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ WARN - > response body the JSON format, and is automatically converted to JSON format! INFO-> Request URI: HTTP://localhost:12345/post, time :1 ms, HTTPcode: 200WARN-> The response body is not in JSON format and has been automatically converted to JSON format! INFO-> Request URI: HTTP://localhost:12345/post, time: 2 ms, HTTPcode: 200INFO - > ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ JSON ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ > {> (1)."code": -2> 1)."FunTester":200> 1)."content":"FunTester">} ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ~ JSON ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ ~ ☢ ☢ ~ ~ ~ the Process finished with exit code0
Copy the code
Use case to create
Use case is very simple, is a HttpRequestBase object, here with com. Funtester. Httpclient. FunRequest class as a transit.
The code generates the FunRequest object
static FunRequest getCase001(a) {
HttpPost httpPost = getHttpPost("http://localhost:12345/post");
httpPost.addHeader(getHeader("token"."324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
return FunRequest.initFromRequest(httpPost);
}
Copy the code
So we get a FunRequest object.
string
There are two types of FunRequest: one is to create FunRequest from code and save it with string information.
static String getCase001(a) {
HttpPost httpPost = getHttpPost("http://localhost:12345/post");
httpPost.addHeader(getHeader("token"."324u2u09uweidlxnvldfsad"));
httpPost.setEntity(new StringEntity(getJson("name=FunTester").toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
FunRequest funRequest = FunRequest.initFromRequest(httpPost);
return JSON.toJSONString(funRequest);
}
Copy the code
The second is a string, or a record in a database, that is converted into a FunRequest object in some nondescribable way. Here is the method of reading FunRequest object from string, because the situation is too complicated, I will not write other cases, you can be interested in their own implementation.
/** * gets the request object * from the string@param fun
* @return* /
static FunRequest initFromString(String fun) {
def f = JSON.parseObject(fun)
RequestType requestType = RequestType.getInstance(f.requestType)
def request = new FunRequest(requestType)
request.host = f.host
request.path = f.path
request.uri = f.uri
request.args = f.args
request.json = f.json
request.params = f.params
f.headers.each {
request.addHeader(it.name,it.value)
}
request
}
Copy the code
Use case transmission
This is much easier to connect. Once a use case has been converted to a string, it can be uploaded to the Master service via the interface or assigned by the Master service to the Salve service (Springboot for now) for execution.
Upload the use case
Here is a simple POST interface upload use case Demo.
static boolean updateCase(a) {
HttpPost httpPost = getHttpPost("http://localhost:12345/updatecase");
httpPost.addHeader(getHeader("token"."324u2u09uweidlxnvldfsad"));
JSONObject json = getJson("name=FunTester");
json.put("FunTester", getCase002());
json.put("Various parameters", FunTester);
httpPost.setEntity(new StringEntity(json.toString(), DEFAULT_CHARSET));
httpPost.addHeader(HttpClientConstant.ContentType_JSON);
JSONObject httpResponse = getHttpResponse(httpPost);
return isRight(httpResponse);
}
Copy the code
Allocate cases
Instead of pushing the use case through the Socket protocol, I’m going to let Salve fetch the use case from the queue assigned by the master. Of course, the use case here contains the necessary runtime information, not just a FunRequest object.
static JSONObject returnCase(a) {
JSONObject json = getJson("name=FunTester");
json.put("FunTester", getCase002());
json.put("Various parameters"."FunTester");
return json;
}
Copy the code
Case execution
Salve takes the use case, parses the response, builds a multithreaded task object or list, and delivers it to the execution framework to execute the use case and display and record the data.
- I’m going to use it here just to save trouble
RequestThreadTimes
The model has been Demo, but the other three are not described here.
Single HttpRequestBase cases
Relatively simple, although it is possible to compress multiple HttpRequestBase objects by combining multiple individual use cases, I strongly recommend this, so I will reject this use case form in the following objects.
static void executeCase(CaseBase caseBase) {
FunRequest funRequest = caseBase.getFunRequest();
int thread = caseBase.getThread();
int times = caseBase.getTimes();
int runup = caseBase.getRunup();
String name = caseBase.getName();
RequestThreadTimes requestThreadTimes = new RequestThreadTimes(funRequest.getRequest(), times);
Concurrent concurrent = new Concurrent(requestThreadTimes, thread, name);
Constant.RUNUP_TIME = runup * 1.0;
concurrent.start();
}
Copy the code
More HttpRequestBase object
For this kind of force, the solution I take is to make a difference in the caseBase object, get the use case parsed into a list, then use the thread parameter thread to start from the list to get the FunRequest object, construct the multi-threaded task class RequestThreadTimes, When it’s done, hand it over to the implementation framework.
static void executeCase(CaseBase caseBase) {
List<FunRequest> funRequests = caseBase.getFunRequests();
int thread = caseBase.getThread();
int times = caseBase.getTimes();
int runup = caseBase.getRunup();
String name = caseBase.getName();
List<ThreadBase> collect = range(thread).mapToObj(f -> new RequestThreadTimes(funRequests.get(f % funRequests.size()).getRequest(), times)).collect(Collectors.toList());
Concurrent concurrent = new Concurrent(collect, name);
Constant.RUNUP_TIME = runup * 1.0;
concurrent.start();
}
Copy the code
FunRequest complete code
package com.funtester.httpclient
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.funtester.base.bean.RequestInfo
import com.funtester.base.exception.RequestException
import com.funtester.config.HttpClientConstant
import com.funtester.config.RequestType
import com.funtester.frame.Save
import com.funtester.frame.SourceCode
import com.funtester.utils.Time
import org.apache.commons.lang3.StringUtils
import org.apache.http.Header
import org.apache.http.HttpEntity
import org.apache.http.client.methods.HttpPost
import org.apache.http.client.methods.HttpPut
import org.apache.http.client.methods.HttpRequestBase
import org.apache.http.client.methods.RequestBuilder
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
/** * Rewrite FunLibrary to use object oriented thinking instead of using the set property method, which may be buggy */
class FunRequest extends SourceCode implements Serializable.Cloneable {
private static final long serialVersionUID = -4153600036943378727L
private static Logger logger = LogManager.getLogger(FunRequest.class)
/** * Request type, true for GET, false for POST */
RequestType requestType
/**
* 请求对象
*/
HttpRequestBase request
/** * host address */
String host = EMPTY
/** * Interface address */
String path = EMPTY
/** * request address, if empty, host and path concatenate */
String uri = EMPTY
/** * header set */
List<Header> headers = new ArrayList<>()
/** * get parameter */
JSONObject args = new JSONObject()
/**
* post参数,表单
*/
JSONObject params = new JSONObject()
/** * json parameter, used for POST and PUT */
JSONObject json = new JSONObject()
/** * response. Without this parameter, the getresponse method */ is automatically called when the funRequest object is converted into a JSON object
JSONObject response = new JSONObject()
/** * constructor **@param requestType
*/
private FunRequest(RequestType requestType) {
this.requestType = requestType
}
/** * get the get object **@return* /
static FunRequest isGet(a) {
new FunRequest(RequestType.GET)
}
/** * Get the POST object **@return* /
static FunRequest isPost(a) {
new FunRequest(RequestType.POST)
}
/** * Get the PUT request object *@return* /
static FunRequest isPut(a) {
new FunRequest(RequestType.PUT)
}
/** * get the delete request object *@return* /
static FunRequest isDelete(a) {
new FunRequest(RequestType.DELETE)
}
/** * set host **@param host
* @return* /
FunRequest setHost(String host) {
this.host = host
this
}
/** * Set the interface address **@param path
* @return* /
FunRequest setpath(String path) {
this.path = path
this
}
/** * Set uri **@param uri
* @return* /
FunRequest setUri(String uri) {
this.uri = uri
this
}
/** * Add the get argument **@param key
* @param value
* @return* /
FunRequest addArgs(Object key, Object value) {
args.put(key, value)
this
}
/** * Add the post argument **@param key
* @param value
* @return* /
FunRequest addParam(Object key, Object value) {
params.put(key, value)
this
}
/** * Add json parameter **@param key
* @param value
* @return* /
FunRequest addJson(Object key, Object value) {
json.put(key, value)
this
}
/** * add header **@param key
* @param value
* @return* /
FunRequest addHeader(Object key, Object value) {
headers << FunLibrary.getHeader(key.toString(), value.toString())
this
}
/** * add header **@param header
* @return* /
FunRequest addHeader(Header header) {
headers.add(header)
this
}
/** * Add header ** in batches@param header
* @return* /
FunRequest addHeader(List<Header> header) {
header.each {h -> headers << h}
this
}
/** * Add cookies in header **@param cookies
* @return* /
FunRequest addCookies(JSONObject cookies) {
headers << FunLibrary.getCookies(cookies)
this
}
FunRequest addHeaders(List<Header> headers) {
this.headers.addAll(headers)
this
}
FunRequest addHeaders(JSONObject headers) {
headers.each {x ->
this.headers.add(FunLibrary.getHeader(x.getKey().toString(), x.getValue().toString()))
}
this
}
FunRequest addArgs(JSONObject args) {
this.args.putAll(args)
this
}
FunRequest addParams(JSONObject params) {
this.params.putAll(params)
this
}
FunRequest addJson(JSONObject json) {
this.json.putAll(json)
this
}
/** * get the request response, compatible with related parameter methods, excluding file **@return* /
JSONObject getResponse(a) {
response = response.isEmpty() ? FunLibrary.getHttpResponse(request == null ? getRequest() : request) : response
response
}
/** * get the request object **@return* /
HttpRequestBase getRequest(a) {
if(request ! =null) request
if (StringUtils.isEmpty(uri))
uri = host + path
switch (requestType) {
case RequestType.GET:
request = FunLibrary.getHttpGet(uri, args)
break
caseRequestType.POST: request = ! params.isEmpty() ? FunLibrary.getHttpPost(uri + FunLibrary.changeJsonToArguments(args), params) : ! json.isEmpty() ? FunLibrary.getHttpPost(uri + FunLibrary.changeJsonToArguments(args), json.toString()) : FunLibrary.getHttpPost(uri + FunLibrary.changeJsonToArguments(args))break
case RequestType.PUT:
request = FunLibrary.getHttpPut(uri, json)
break
case RequestType.DELETE:
request = FunLibrary.getHttpDelete(uri)
break
case RequestType.PATCH:
request = FunLibrary.getHttpPatch(uri, params)
default:
break
}
for (Header it : headers) {
if(it.getName() ! = HttpClientConstant.ContentType_JSON.getName()) request.addHeader(it) } logger.debug("Request information: {}".new RequestInfo(this.request).toString())
request
}
FunRequest setHeaders(List<Header> headers) {
this.headers = headers
this
}
FunRequest setArgs(JSONObject args) {
this.args = args
this
}
FunRequest setParams(JSONObject params) {
this.params = params
this
}
FunRequest setJson(JSONObject json) {
this.json = json
this
}
@Override
FunRequest clone(a) {
initFromRequest(this.getRequest())
}
@Override
String toString(a) {
return "{" +
"requestType='" + requestType.getName() + '\' ' +
", host='" + host + '\' ' +
", path='" + path + '\' ' +
", uri='" + uri + '\' ' +
", headers=" + FunLibrary.header2Json(headers).toString() +
", args=" + args.toString() +
", params=" + params.toString() +
", json=" + json.toString() +
", response=" + response.toString() +
'} '
}
Curl curl curl curl curl curl curl curl curl@return* /
String toCurl(a) {
StringBuffer curl = new StringBuffer("curl -w HTTPcode%{http_code}: The proxy returns code%{http_connect}: data type %{content_type}:DNS resolution time %{time_NAMelookup}:%{time_redirect}: connection completion time %{ti Me_pretransfer}: connection time %{time_connect}: transfer start time %{time_startTransfer}: total time %{time_total}: download speed %{speed_download}:speed_upload%{SPE ed_upload} ")
curl << " -X ${requestType.getName()} "
headers.each {
curl << " -H '${it.getName()}:${it.getValue().replace(SPACE_1, EMPTY)}'"
}
switch (requestType) {
case RequestType.GET:
args.each {
curl << " -d '${it.key}=${it.value}'"
}
break
case RequestType.POST:
if(! params.isEmpty()) { curl <<" -H Content-Type:application/x-www-form-urlencoded"
params.each {
curl << " -F '${it.key}=${it.value}'"}}if(! json.isEmpty()) { curl <<" -H \"Content-Type:application/json\"" // do not build curl commands from the outside
json.each {
curl << " -d '${it.key}=${it.value}'"}}break
default:
break
}
curl << " ${uri}"
Curl << "--compressed" // curl <<" --compressed
curl.toString()
}
Curl curl curl curl curl curl curl curl curl@param requestBase
* @return* /
static String reqToCurl(HttpRequestBase requestBase) {
initFromRequest(requestBase).toCurl()
}
/** * Initialize funRequest * from the requestBase object@param base
* @return* /
static FunRequest initFromRequest(HttpRequestBase base) {
FunRequest request = null
String method = base.getMethod()
String uri = base.getURI().toString()
RequestType requestType = RequestType.getInstance(method)
List<Header> headers = Arrays.asList(base.getAllHeaders())
if (requestType == requestType.GET) {
request = isGet().setUri(uri).addHeaders(headers)
} else if (requestType == RequestType.POST) {
HttpPost post = (HttpPost) base
HttpEntity entity = post.getEntity()
if (entity == null) {
request = isPost().setUri(uri).addHeader(headers)
} else {
Header type = entity.getContentType()
String value = type == null ? EMPTY : type.getValue()
String content = FunLibrary.getContent(entity)
if (value.equalsIgnoreCase(HttpClientConstant.ContentType_TEXT.getValue()) || value.equalsIgnoreCase(HttpClientConstant.ContentType_JSON.getValue())) {
request = isPost().setUri(uri).addHeaders(headers).addJson(JSONObject.parseObject(content))
} else if (value.equalsIgnoreCase(HttpClientConstant.ContentType_FORM.getValue())) {
request = isPost().setUri(uri).addHeaders(headers).addParams(getJson(content.split("&")))}}}else if (requestType == RequestType.PUT) {
HttpPut put = (HttpPut) base
String content = FunLibrary.getContent(put.getEntity())
request = isPut().setUri(uri).addHeaders(headers).setJson(JSONObject.parseObject(content))
} else if (requestType == RequestType.DELETE) {
request = isDelete().setUri(uri)
} else {
RequestException.fail("Unsupported request type!")}return request
}
/** * gets the request object * from the string@param fun
* @return* /
static FunRequest initFromString(String fun) {
def f = JSON.parseObject(fun)
RequestType requestType = RequestType.getInstance(f.requestType)
def request = new FunRequest(requestType)
request.host = f.host
request.path = f.path
request.uri = f.uri
request.args = f.args
request.json = f.json
request.params = f.params
f.headers.each {
request.addHeader(it.name,it.value)
}
request
}
static HttpRequestBase doCopy(HttpRequestBase base) {
(HttpRequestBase) RequestBuilder.copy(base).build()
}
/** * Copy the HttpRequestBase object *@param base
* @return* /
static HttpRequestBase cloneRequest(HttpRequestBase base) {
initFromRequest(base).getRequest()
}
/** * Save request and response *@param base
* @param response
*/
static void save(HttpRequestBase base, JSONObject response) {
FunRequest request = initFromRequest(base)
request.setResponse(response)
Save.info("/request/" + Time.getDate().substring(8) + SPACE_1 + request.getUri().replace(OR, CONNECTOR).replaceAll("https*:_+", EMPTY), request.toString())
}
}
Copy the code
FunTester.Tencent Cloud Author of the Year,Boss direct hire contract author.Official GDevOps media partner, non-famous test development.
- FunTester test framework architecture diagram
- FunTester test project architecture diagram
- Dom-based XML file parsing class
- How to learn Java basics
- Soft start of performance test
- Java grid output class
- Manual testing or automated testing?
- Bind mobile phone number performance test
- Java multithreaded programming applied in JMeter
- Don’t always bend over in humility
- Details in the test case