fix(接口测试): 修复导入chrome插件的json文件顺序和原始顺序不一致的缺陷
--bug=1030212 --user=王孝刚 【接口测试】github#26650,使用chrome接口录制插件录制后,导出json文件到MS系统接口定义中导入,导入后列表的排序和录制列表排序不一致 https://www.tapd.cn/55049933/s/1414365
This commit is contained in:
parent
75964efc2b
commit
3270bb2fe3
|
@ -25,27 +25,6 @@ public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
|||
private static final String HEADERS = "headers";
|
||||
private static final String BODY = "body";
|
||||
|
||||
protected List<MsHTTPSamplerProxy> parseMsHTTPSamplerProxy(JSONObject testObject, String tag, boolean isSetUrl) {
|
||||
JSONObject requests = testObject.optJSONObject(tag);
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = new ArrayList<>();
|
||||
if (requests != null) {
|
||||
requests.keySet().forEach(requestName -> {
|
||||
JSONObject requestObject = requests.optJSONObject(requestName);
|
||||
String path = requestObject.optString(URL);
|
||||
String method = requestObject.optString(METHOD);
|
||||
MsHTTPSamplerProxy request = buildRequest(requestName, path, method);
|
||||
parseBody(requestObject, request.getBody());
|
||||
parseHeader(requestObject, request.getHeaders());
|
||||
parsePath(request);
|
||||
if (isSetUrl) {
|
||||
request.setUrl(path);
|
||||
}
|
||||
msHTTPSamplerProxies.add(request);
|
||||
});
|
||||
}
|
||||
return msHTTPSamplerProxies;
|
||||
}
|
||||
|
||||
protected List<MsHTTPSamplerProxy> parseMsHTTPSamplerProxy(JsonNode requests, boolean isSetUrl) {
|
||||
List<MsHTTPSamplerProxy> samplerProxies = new ArrayList<>();
|
||||
Iterator<Map.Entry<String, JsonNode>> fields = requests.fields();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.api.parse.api;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.metersphere.api.dto.ApiTestImportRequest;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.response.HttpResponse;
|
||||
|
@ -19,10 +20,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
||||
|
@ -38,29 +36,38 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
if (testObject.opt("projectName") != null || testObject.opt("projectId") != null) {// metersphere 格式导入
|
||||
return parseMsFormat(testStr, request);
|
||||
} else { // chrome 插件录制格式导入
|
||||
JsonNode node = JSONUtil.parseNode(testStr);
|
||||
request.setPlatform(ApiImportPlatform.Plugin.name());
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
apiImport.setProtocol(RequestTypeConstants.HTTP);
|
||||
apiImport.setData(parsePluginFormat(testObject, request, true));
|
||||
apiImport.setData(parsePluginFormat(node, request));
|
||||
return apiImport;
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ApiDefinitionWithBLOBs> parsePluginFormat(JSONObject testObject, ApiTestImportRequest importRequest, Boolean isCreateModule) {
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
protected LinkedList<ApiDefinitionWithBLOBs> parsePluginFormat(JsonNode testObject, ApiTestImportRequest importRequest) {
|
||||
LinkedList<ApiDefinitionWithBLOBs> results = new LinkedList<>();
|
||||
if (testObject != null) {
|
||||
testObject.keySet().forEach(tag -> {
|
||||
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(testObject, tag, false);
|
||||
for (MsHTTPSamplerProxy msHTTPSamplerProxy : msHTTPSamplerProxies) {
|
||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(msHTTPSamplerProxy.getId(), msHTTPSamplerProxy.getName(), msHTTPSamplerProxy.getPath(), msHTTPSamplerProxy.getMethod(), importRequest);
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
apiDefinition.setModulePath(tag);
|
||||
apiDefinition.setRequest(JSON.toJSONString(msHTTPSamplerProxy));
|
||||
apiDefinition.setName(apiDefinition.getPath() + " [" + apiDefinition.getMethod() + "]");
|
||||
results.add(apiDefinition);
|
||||
Iterator<Map.Entry<String, JsonNode>> fields = testObject.fields();
|
||||
while (fields.hasNext()) {
|
||||
Map.Entry<String, JsonNode> field = fields.next();
|
||||
if (field.getValue().isNull()) {
|
||||
continue;
|
||||
}
|
||||
});
|
||||
testObject.forEach(node -> {
|
||||
if(node != null ) {
|
||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(node,false);
|
||||
for (MsHTTPSamplerProxy msHTTPSamplerProxy : msHTTPSamplerProxies) {
|
||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(msHTTPSamplerProxy.getId(), msHTTPSamplerProxy.getName(), msHTTPSamplerProxy.getPath(), msHTTPSamplerProxy.getMethod(), importRequest);
|
||||
apiDefinition.setProjectId(this.projectId);
|
||||
apiDefinition.setModulePath(field.getKey());
|
||||
apiDefinition.setRequest(JSON.toJSONString(msHTTPSamplerProxy));
|
||||
apiDefinition.setName(apiDefinition.getPath() + " [" + apiDefinition.getMethod() + "]");
|
||||
results.add(apiDefinition);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue