fix(接口测试): 修复导入Swagger数据展示错误问题
--bug=1018065 --user=赵勇 【接口测试】swagger导入接口定义,接口请求头有信息,但是接口编辑页面没显示请求头数量统计 https://www.tapd.cn/55049933/s/1262261
This commit is contained in:
parent
68de854ca5
commit
aba8a2ba42
|
@ -381,7 +381,7 @@ public class ElementUtil {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (element.has(ElementConstants.HASH_TREE)) {
|
if (element.has(ElementConstants.HASH_TREE)) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(ElementConstants.HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(ElementConstants.HASH_TREE);
|
||||||
relationships(elementJSONArray, referenceRelationships);
|
relationships(elementJSONArray, referenceRelationships);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -399,7 +399,7 @@ public class ElementUtil {
|
||||||
element.put(ElementConstants.CLAZZ_NAME, clazzMap.get(element.optString(PropertyConstant.TYPE)));
|
element.put(ElementConstants.CLAZZ_NAME, clazzMap.get(element.optString(PropertyConstant.TYPE)));
|
||||||
}
|
}
|
||||||
if (element.has(ElementConstants.HASH_TREE)) {
|
if (element.has(ElementConstants.HASH_TREE)) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(ElementConstants.HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(ElementConstants.HASH_TREE);
|
||||||
dataFormatting(elementJSONArray);
|
dataFormatting(elementJSONArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,7 +411,7 @@ public class ElementUtil {
|
||||||
}
|
}
|
||||||
formatSampler(element);
|
formatSampler(element);
|
||||||
if (element != null && element.has(ElementConstants.HASH_TREE)) {
|
if (element != null && element.has(ElementConstants.HASH_TREE)) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(ElementConstants.HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(ElementConstants.HASH_TREE);
|
||||||
dataFormatting(elementJSONArray);
|
dataFormatting(elementJSONArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ public class ElementUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (element.has(ElementConstants.HASH_TREE)) {
|
if (element.has(ElementConstants.HASH_TREE)) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(ElementConstants.HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(ElementConstants.HASH_TREE);
|
||||||
if (isScenarioEnv) {
|
if (isScenarioEnv) {
|
||||||
dataSetDomain(elementJSONArray, config);
|
dataSetDomain(elementJSONArray, config);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -190,7 +190,7 @@ public class MsScenario extends MsTestElement {
|
||||||
if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
|
if (scenario != null && StringUtils.isNotEmpty(scenario.getScenarioDefinition())) {
|
||||||
JSONObject element = JSONUtil.parseObject(scenario.getScenarioDefinition());
|
JSONObject element = JSONUtil.parseObject(scenario.getScenarioDefinition());
|
||||||
// 历史数据处理
|
// 历史数据处理
|
||||||
ElementUtil.dataFormatting(element.getJSONArray(ElementConstants.HASH_TREE));
|
ElementUtil.dataFormatting(element.optJSONArray(ElementConstants.HASH_TREE));
|
||||||
this.setName(scenario.getName());
|
this.setName(scenario.getName());
|
||||||
this.setProjectId(scenario.getProjectId());
|
this.setProjectId(scenario.getProjectId());
|
||||||
LinkedList<MsTestElement> sourceHashTree = mapper.readValue(element.optString(ElementConstants.HASH_TREE), new TypeReference<LinkedList<MsTestElement>>() {
|
LinkedList<MsTestElement> sourceHashTree = mapper.readValue(element.optString(ElementConstants.HASH_TREE), new TypeReference<LinkedList<MsTestElement>>() {
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class ApiEnvironmentRunningParamService {
|
||||||
if (configObj.has("commonConfig")) {
|
if (configObj.has("commonConfig")) {
|
||||||
JSONObject commonConfig = configObj.optJSONObject("commonConfig");
|
JSONObject commonConfig = configObj.optJSONObject("commonConfig");
|
||||||
if (commonConfig.has("variables")) {
|
if (commonConfig.has("variables")) {
|
||||||
JSONArray variables = commonConfig.getJSONArray("variables");
|
JSONArray variables = commonConfig.optJSONArray("variables");
|
||||||
List<JSONObject> variableList = new LinkedList<>();
|
List<JSONObject> variableList = new LinkedList<>();
|
||||||
for (Map.Entry<String, String> entry : varMap.entrySet()) {
|
for (Map.Entry<String, String> entry : varMap.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package io.metersphere.api.parse;
|
package io.metersphere.api.parse;
|
||||||
|
|
||||||
import io.metersphere.api.parse.api.ms.NodeTree;
|
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||||
import io.metersphere.api.dto.scenario.Body;
|
import io.metersphere.api.dto.scenario.Body;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
|
import io.metersphere.api.parse.api.ms.NodeTree;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -19,19 +19,21 @@ public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
||||||
protected List<MsHTTPSamplerProxy> parseMsHTTPSamplerProxy(JSONObject testObject, String tag, boolean isSetUrl) {
|
protected List<MsHTTPSamplerProxy> parseMsHTTPSamplerProxy(JSONObject testObject, String tag, boolean isSetUrl) {
|
||||||
JSONObject requests = testObject.optJSONObject(tag);
|
JSONObject requests = testObject.optJSONObject(tag);
|
||||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = new ArrayList<>();
|
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = new ArrayList<>();
|
||||||
requests.keySet().forEach(requestName -> {
|
if (requests != null) {
|
||||||
JSONObject requestObject = requests.optJSONObject(requestName);
|
requests.keySet().forEach(requestName -> {
|
||||||
String path = requestObject.optString("url");
|
JSONObject requestObject = requests.optJSONObject(requestName);
|
||||||
String method = requestObject.optString("method");
|
String path = requestObject.optString("url");
|
||||||
MsHTTPSamplerProxy request = buildRequest(requestName, path, method);
|
String method = requestObject.optString("method");
|
||||||
parseBody(requestObject, request.getBody());
|
MsHTTPSamplerProxy request = buildRequest(requestName, path, method);
|
||||||
parseHeader(requestObject, request.getHeaders());
|
parseBody(requestObject, request.getBody());
|
||||||
parsePath(request);
|
parseHeader(requestObject, request.getHeaders());
|
||||||
if (isSetUrl) {
|
parsePath(request);
|
||||||
request.setUrl(path);
|
if (isSetUrl) {
|
||||||
}
|
request.setUrl(path);
|
||||||
msHTTPSamplerProxies.add(request);
|
}
|
||||||
});
|
msHTTPSamplerProxies.add(request);
|
||||||
|
});
|
||||||
|
}
|
||||||
return msHTTPSamplerProxies;
|
return msHTTPSamplerProxies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +66,7 @@ public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseHeader(JSONObject requestObject, List<KeyValue> msHeaders) {
|
private void parseHeader(JSONObject requestObject, List<KeyValue> msHeaders) {
|
||||||
JSONArray headers = requestObject.getJSONArray("headers");
|
JSONArray headers = requestObject.optJSONArray("headers");
|
||||||
if (headers != null) {
|
if (headers != null) {
|
||||||
for (int i = 0; i < headers.length(); i++) {
|
for (int i = 0; i < headers.length(); i++) {
|
||||||
JSONObject header = headers.optJSONObject(i);
|
JSONObject header = headers.optJSONObject(i);
|
||||||
|
@ -77,7 +79,7 @@ public abstract class MsAbstractParser<T> extends ApiImportAbstractParser<T> {
|
||||||
if (requestObject.has("body")) {
|
if (requestObject.has("body")) {
|
||||||
Object body = requestObject.get("body");
|
Object body = requestObject.get("body");
|
||||||
if (body instanceof JSONArray) {
|
if (body instanceof JSONArray) {
|
||||||
JSONArray bodies = requestObject.getJSONArray("body");
|
JSONArray bodies = requestObject.optJSONArray("body");
|
||||||
if (bodies != null) {
|
if (bodies != null) {
|
||||||
StringBuilder bodyStr = new StringBuilder();
|
StringBuilder bodyStr = new StringBuilder();
|
||||||
for (int i = 0; i < bodies.length(); i++) {
|
for (int i = 0; i < bodies.length(); i++) {
|
||||||
|
|
|
@ -50,18 +50,20 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
||||||
|
|
||||||
protected List<ApiDefinitionWithBLOBs> parsePluginFormat(JSONObject testObject, ApiTestImportRequest importRequest, Boolean isCreateModule) {
|
protected List<ApiDefinitionWithBLOBs> parsePluginFormat(JSONObject testObject, ApiTestImportRequest importRequest, Boolean isCreateModule) {
|
||||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||||
testObject.keySet().forEach(tag -> {
|
if (testObject != null) {
|
||||||
|
testObject.keySet().forEach(tag -> {
|
||||||
|
|
||||||
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(testObject, tag, false);
|
List<MsHTTPSamplerProxy> msHTTPSamplerProxies = parseMsHTTPSamplerProxy(testObject, tag, false);
|
||||||
for (MsHTTPSamplerProxy msHTTPSamplerProxy : msHTTPSamplerProxies) {
|
for (MsHTTPSamplerProxy msHTTPSamplerProxy : msHTTPSamplerProxies) {
|
||||||
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(msHTTPSamplerProxy.getId(), msHTTPSamplerProxy.getName(), msHTTPSamplerProxy.getPath(), msHTTPSamplerProxy.getMethod(), importRequest);
|
ApiDefinitionWithBLOBs apiDefinition = buildApiDefinition(msHTTPSamplerProxy.getId(), msHTTPSamplerProxy.getName(), msHTTPSamplerProxy.getPath(), msHTTPSamplerProxy.getMethod(), importRequest);
|
||||||
apiDefinition.setProjectId(this.projectId);
|
apiDefinition.setProjectId(this.projectId);
|
||||||
apiDefinition.setModulePath(tag);
|
apiDefinition.setModulePath(tag);
|
||||||
apiDefinition.setRequest(JSON.toJSONString(msHTTPSamplerProxy));
|
apiDefinition.setRequest(JSON.toJSONString(msHTTPSamplerProxy));
|
||||||
apiDefinition.setName(apiDefinition.getPath() + " [" + apiDefinition.getMethod() + "]");
|
apiDefinition.setName(apiDefinition.getPath() + " [" + apiDefinition.getMethod() + "]");
|
||||||
results.add(apiDefinition);
|
results.add(apiDefinition);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -695,7 +695,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
}};
|
}};
|
||||||
Set<String> typeKeys = typeMap.keySet();
|
Set<String> typeKeys = typeMap.keySet();
|
||||||
for (String type : typeKeys) {
|
for (String type : typeKeys) {
|
||||||
JSONArray params = request.getJSONArray(type); // 获得请求参数列表
|
JSONArray params = request.optJSONArray(type); // 获得请求参数列表
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
for (int i = 0; i < params.length(); ++i) {
|
for (int i = 0; i < params.length(); ++i) {
|
||||||
JSONObject param = params.optJSONObject(i); // 对于每个参数:
|
JSONObject param = params.optJSONObject(i); // 对于每个参数:
|
||||||
|
@ -942,7 +942,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
JSONObject statusCodeInfo = new JSONObject();
|
JSONObject statusCodeInfo = new JSONObject();
|
||||||
// build 请求头
|
// build 请求头
|
||||||
JSONObject headers = new JSONObject();
|
JSONObject headers = new JSONObject();
|
||||||
JSONArray headValueList = response.getJSONArray("headers");
|
JSONArray headValueList = response.optJSONArray("headers");
|
||||||
if (headValueList != null) {
|
if (headValueList != null) {
|
||||||
for (Object item : headValueList) {
|
for (Object item : headValueList) {
|
||||||
if (item instanceof JSONObject && ((JSONObject) item).optString("name") != null) {
|
if (item instanceof JSONObject && ((JSONObject) item).optString("name") != null) {
|
||||||
|
@ -960,7 +960,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
statusCodeInfo.put("content", buildContent(response));
|
statusCodeInfo.put("content", buildContent(response));
|
||||||
statusCodeInfo.put("description", "");
|
statusCodeInfo.put("description", "");
|
||||||
// 返回code
|
// 返回code
|
||||||
JSONArray statusCode = response.getJSONArray("statusCode");
|
JSONArray statusCode = response.optJSONArray("statusCode");
|
||||||
responseBody.put(statusCode.toString(), statusCodeInfo);
|
responseBody.put(statusCode.toString(), statusCodeInfo);
|
||||||
return responseBody;
|
return responseBody;
|
||||||
}
|
}
|
||||||
|
@ -997,19 +997,19 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
JSONObject jsonObject = JSONUtil.parseObject(jsonSchema);
|
JSONObject jsonObject = JSONUtil.parseObject(jsonSchema);
|
||||||
JSONArray required = new JSONArray();
|
JSONArray required = new JSONArray();
|
||||||
if (jsonObject != null) {
|
if (jsonObject != null) {
|
||||||
required = jsonObject.getJSONArray(PropertyConstant.REQUIRED);
|
required = jsonObject.optJSONArray(PropertyConstant.REQUIRED);
|
||||||
}
|
}
|
||||||
if (required == null) {
|
if (required == null) {
|
||||||
JSONObject items = jsonObject.optJSONObject(PropertyConstant.ITEMS);
|
JSONObject items = jsonObject.optJSONObject(PropertyConstant.ITEMS);
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
required = items.getJSONArray(PropertyConstant.REQUIRED);
|
required = items.optJSONArray(PropertyConstant.REQUIRED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bodyInfo = buildJsonSchema(jsonObject, required);
|
bodyInfo = buildJsonSchema(jsonObject, required);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try { // 若请求体是一个 object
|
try { // 若请求体是一个 object
|
||||||
bodyInfo = buildRequestBodyJsonInfo(body.getJSONArray("raw"));
|
bodyInfo = buildRequestBodyJsonInfo(body.optJSONArray("raw"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
bodyInfo = buildRequestBodyJsonInfo(body.optJSONObject("raw"));
|
bodyInfo = buildRequestBodyJsonInfo(body.optJSONObject("raw"));
|
||||||
}
|
}
|
||||||
|
@ -1032,7 +1032,7 @@ public class Swagger3Parser extends SwaggerAbstractParser {
|
||||||
JSONObject xmlToJson = XMLUtil.XmlToJson(xmlText);
|
JSONObject xmlToJson = XMLUtil.XmlToJson(xmlText);
|
||||||
bodyInfo = buildRequestBodyJsonInfo(xmlToJson);
|
bodyInfo = buildRequestBodyJsonInfo(xmlToJson);
|
||||||
} else if (bodyType != null && (bodyType.equalsIgnoreCase("WWW_FORM") || bodyType.equalsIgnoreCase("Form Data") || bodyType.equalsIgnoreCase("BINARY"))) { // key-value 类格式
|
} else if (bodyType != null && (bodyType.equalsIgnoreCase("WWW_FORM") || bodyType.equalsIgnoreCase("Form Data") || bodyType.equalsIgnoreCase("BINARY"))) { // key-value 类格式
|
||||||
JSONObject formData = getformDataProperties(body.getJSONArray("kvs"));
|
JSONObject formData = getformDataProperties(body.optJSONArray("kvs"));
|
||||||
bodyInfo = buildFormDataSchema(formData);
|
bodyInfo = buildFormDataSchema(formData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -296,8 +296,8 @@ public class ApiScenarioImportUtil {
|
||||||
object.put("index", i + 1);
|
object.put("index", i + 1);
|
||||||
object.put("resourceId", UUID.randomUUID().toString());
|
object.put("resourceId", UUID.randomUUID().toString());
|
||||||
hashTree.put(i, object);
|
hashTree.put(i, object);
|
||||||
if (object.has(ElementConstants.HASH_TREE) && object.getJSONArray(ElementConstants.HASH_TREE) != null) {
|
if (object.has(ElementConstants.HASH_TREE) && object.optJSONArray(ElementConstants.HASH_TREE) != null) {
|
||||||
formatHashTree(object.getJSONArray(ElementConstants.HASH_TREE));
|
formatHashTree(object.optJSONArray(ElementConstants.HASH_TREE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler;
|
||||||
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
|
||||||
import io.metersphere.api.dto.scenario.Body;
|
import io.metersphere.api.dto.scenario.Body;
|
||||||
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
import io.metersphere.log.utils.ApiDefinitionDiffUtil;
|
import io.metersphere.log.utils.ApiDefinitionDiffUtil;
|
||||||
import io.metersphere.log.utils.ReflexObjectUtil;
|
import io.metersphere.log.utils.ReflexObjectUtil;
|
||||||
import io.metersphere.log.utils.diff.json.JacksonDiff;
|
import io.metersphere.log.utils.diff.json.JacksonDiff;
|
||||||
|
@ -94,21 +95,21 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
Map<String, String> diffMap = new LinkedHashMap<>();
|
Map<String, String> diffMap = new LinkedHashMap<>();
|
||||||
diffMap.put(TYPE, bloBsIsNew.getString(TYPE));
|
diffMap.put(TYPE, bloBsIsNew.getString(TYPE));
|
||||||
JsonDiff jsonDiff = new JacksonDiff();
|
JsonDiff jsonDiff = new JacksonDiff();
|
||||||
if (bloBsIsNew.getString(TYPE).equals("TCPSampler")) {
|
if (bloBsIsNew.getString(TYPE).equals(ElementConstants.TCP_SAMPLER)) {
|
||||||
MsTCPSampler tcpSamplerNew = JSONUtil.parseObject(bloBsIsNew.toString(), MsTCPSampler.class);
|
MsTCPSampler tcpSamplerNew = JSON.parseObject(bloBsIsNew.toString(), MsTCPSampler.class);
|
||||||
MsTCPSampler tcpSamplerOld = JSONUtil.parseObject(bloBsIsOld.toString(), MsTCPSampler.class);
|
MsTCPSampler tcpSamplerOld = JSON.parseObject(bloBsIsOld.toString(), MsTCPSampler.class);
|
||||||
diffTcp(tcpSamplerNew, tcpSamplerOld, jsonDiff, diffMap);
|
diffTcp(tcpSamplerNew, tcpSamplerOld, jsonDiff, diffMap);
|
||||||
} else if (bloBsIsNew.getString(TYPE).equals("HTTPSamplerProxy")) {
|
} else if (bloBsIsNew.getString(TYPE).equals(ElementConstants.HTTP_SAMPLER)) {
|
||||||
MsHTTPSamplerProxy httpSamplerProxyNew = JSONUtil.parseObject(bloBsIsNew.toString(), MsHTTPSamplerProxy.class);
|
MsHTTPSamplerProxy httpSamplerProxyNew = JSON.parseObject(bloBsIsNew.toString(), MsHTTPSamplerProxy.class);
|
||||||
MsHTTPSamplerProxy httpSamplerProxyOld = JSONUtil.parseObject(bloBsIsOld.toString(), MsHTTPSamplerProxy.class);
|
MsHTTPSamplerProxy httpSamplerProxyOld = JSON.parseObject(bloBsIsOld.toString(), MsHTTPSamplerProxy.class);
|
||||||
diffHttp(httpSamplerProxyNew, httpSamplerProxyOld, jsonDiff, diffMap);
|
diffHttp(httpSamplerProxyNew, httpSamplerProxyOld, jsonDiff, diffMap);
|
||||||
} else if (bloBsIsNew.getString(TYPE).equals("JDBCSampler")) {
|
} else if (bloBsIsNew.getString(TYPE).equals(ElementConstants.JDBC_SAMPLER)) {
|
||||||
MsJDBCSampler jdbcSamplerNew = JSONUtil.parseObject(bloBsIsNew.toString(), MsJDBCSampler.class);
|
MsJDBCSampler jdbcSamplerNew = JSON.parseObject(bloBsIsNew.toString(), MsJDBCSampler.class);
|
||||||
MsJDBCSampler jdbcSamplerOld = JSONUtil.parseObject(bloBsIsOld.toString(), MsJDBCSampler.class);
|
MsJDBCSampler jdbcSamplerOld = JSON.parseObject(bloBsIsOld.toString(), MsJDBCSampler.class);
|
||||||
diffJdbc(jdbcSamplerNew, jdbcSamplerOld, jsonDiff, diffMap);
|
diffJdbc(jdbcSamplerNew, jdbcSamplerOld, jsonDiff, diffMap);
|
||||||
} else {
|
} else {
|
||||||
MsDubboSampler dubboSamplerNew = JSONUtil.parseObject(bloBsIsNew.toString(), MsDubboSampler.class);
|
MsDubboSampler dubboSamplerNew = JSON.parseObject(bloBsIsNew.toString(), MsDubboSampler.class);
|
||||||
MsDubboSampler dubboSamplerOld = JSONUtil.parseObject(bloBsIsOld.toString(), MsDubboSampler.class);
|
MsDubboSampler dubboSamplerOld = JSON.parseObject(bloBsIsOld.toString(), MsDubboSampler.class);
|
||||||
diffDubbo(dubboSamplerNew, dubboSamplerOld, jsonDiff, diffMap);
|
diffDubbo(dubboSamplerNew, dubboSamplerOld, jsonDiff, diffMap);
|
||||||
}
|
}
|
||||||
if (diffMap.size() > 1) {
|
if (diffMap.size() > 1) {
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class GenerateHashTreeUtil {
|
||||||
ElementUtil.dataFormatting(element);
|
ElementUtil.dataFormatting(element);
|
||||||
// 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取
|
// 多态JSON普通转换会丢失内容,需要通过 ObjectMapper 获取
|
||||||
if (element != null && element.has(ElementConstants.HASH_TREE)) {
|
if (element != null && element.has(ElementConstants.HASH_TREE)) {
|
||||||
LinkedList<MsTestElement> elements = mapper.readValue(element.getJSONArray(ElementConstants.HASH_TREE).toString(), new TypeReference<LinkedList<MsTestElement>>() {
|
LinkedList<MsTestElement> elements = mapper.readValue(element.optJSONArray(ElementConstants.HASH_TREE).toString(), new TypeReference<LinkedList<MsTestElement>>() {
|
||||||
});
|
});
|
||||||
scenario.setHashTree(elements);
|
scenario.setHashTree(elements);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public class GenerateHashTreeUtil {
|
||||||
try {
|
try {
|
||||||
if (element != null && element.has(ElementConstants.HASH_TREE)) {
|
if (element != null && element.has(ElementConstants.HASH_TREE)) {
|
||||||
ElementUtil.dataFormatting(element);
|
ElementUtil.dataFormatting(element);
|
||||||
return objectMapper.readValue(element.getJSONArray(ElementConstants.HASH_TREE).toString(), new TypeReference<LinkedList<MsTestElement>>() {
|
return objectMapper.readValue(element.optJSONArray(ElementConstants.HASH_TREE).toString(), new TypeReference<LinkedList<MsTestElement>>() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class HashTreeUtil {
|
||||||
JSONObject commonConfig = configJson.optJSONObject(COMMON_CONFIG);
|
JSONObject commonConfig = configJson.optJSONObject(COMMON_CONFIG);
|
||||||
if (commonConfig.has(VARIABLES)) {
|
if (commonConfig.has(VARIABLES)) {
|
||||||
Map<String, String> envHeadMap = new HashMap<>();
|
Map<String, String> envHeadMap = new HashMap<>();
|
||||||
JSONArray variablesArr = commonConfig.getJSONArray(VARIABLES);
|
JSONArray variablesArr = commonConfig.optJSONArray(VARIABLES);
|
||||||
for (int i = 0; i < variablesArr.length(); i++) {
|
for (int i = 0; i < variablesArr.length(); i++) {
|
||||||
JSONObject object = variablesArr.optJSONObject(i);
|
JSONObject object = variablesArr.optJSONObject(i);
|
||||||
if (object.has(NAME) && object.has(VALUE)) {
|
if (object.has(NAME) && object.has(VALUE)) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class XMLUtil {
|
||||||
jsonToXmlStr(jo, buffer, nowTab.append("\t"));
|
jsonToXmlStr(jo, buffer, nowTab.append("\t"));
|
||||||
buffer.append(tab).append("</").append(en.getKey()).append(">\n");
|
buffer.append(tab).append("</").append(en.getKey()).append(">\n");
|
||||||
} else if (en.getValue() instanceof JSONArray) {
|
} else if (en.getValue() instanceof JSONArray) {
|
||||||
JSONArray array = jObj.getJSONArray(en.getKey());
|
JSONArray array = jObj.optJSONArray(en.getKey());
|
||||||
for (int i = 0; i < array.length(); i++) {
|
for (int i = 0; i < array.length(); i++) {
|
||||||
buffer.append(tab).append("<").append(en.getKey()).append(">\n");
|
buffer.append(tab).append("<").append(en.getKey()).append(">\n");
|
||||||
if (StringUtils.isNotBlank(array.optString(i))) {
|
if (StringUtils.isNotBlank(array.optString(i))) {
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class MockApiUtils {
|
||||||
} else if (StringUtils.equalsAnyIgnoreCase(type, "Form Data", "WWW_FORM")) {
|
} else if (StringUtils.equalsAnyIgnoreCase(type, "Form Data", "WWW_FORM")) {
|
||||||
if (bodyObj.has("kvs")) {
|
if (bodyObj.has("kvs")) {
|
||||||
JSONObject bodyParamArr = new JSONObject();
|
JSONObject bodyParamArr = new JSONObject();
|
||||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
JSONArray kvsArr = bodyObj.optJSONArray("kvs");
|
||||||
for (int i = 0; i < kvsArr.length(); i++) {
|
for (int i = 0; i < kvsArr.length(); i++) {
|
||||||
JSONObject kv = kvsArr.optJSONObject(i);
|
JSONObject kv = kvsArr.optJSONObject(i);
|
||||||
if (kv.has("name")) {
|
if (kv.has("name")) {
|
||||||
|
@ -200,7 +200,7 @@ public class MockApiUtils {
|
||||||
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
|
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
|
||||||
Map<String, String> paramMap = new LinkedHashMap<>();
|
Map<String, String> paramMap = new LinkedHashMap<>();
|
||||||
if (bodyObj.has("kvs")) {
|
if (bodyObj.has("kvs")) {
|
||||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
JSONArray kvsArr = bodyObj.optJSONArray("kvs");
|
||||||
for (int i = 0; i < kvsArr.length(); i++) {
|
for (int i = 0; i < kvsArr.length(); i++) {
|
||||||
JSONObject kv = kvsArr.optJSONObject(i);
|
JSONObject kv = kvsArr.optJSONObject(i);
|
||||||
if (kv.has("name")) {
|
if (kv.has("name")) {
|
||||||
|
@ -223,7 +223,7 @@ public class MockApiUtils {
|
||||||
responseDTO.setReturnData(returnStr);
|
responseDTO.setReturnData(returnStr);
|
||||||
}
|
}
|
||||||
if (respObj.has("statusCode")) {
|
if (respObj.has("statusCode")) {
|
||||||
JSONArray statusCodeArray = respObj.getJSONArray("statusCode");
|
JSONArray statusCodeArray = respObj.optJSONArray("statusCode");
|
||||||
int code = 200;
|
int code = 200;
|
||||||
if (statusCodeArray != null) {
|
if (statusCodeArray != null) {
|
||||||
for (int i = 0; i < statusCodeArray.length(); i++) {
|
for (int i = 0; i < statusCodeArray.length(); i++) {
|
||||||
|
@ -241,7 +241,7 @@ public class MockApiUtils {
|
||||||
responseDTO.setReturnCode(code);
|
responseDTO.setReturnCode(code);
|
||||||
}
|
}
|
||||||
if (respObj.has("headers")) {
|
if (respObj.has("headers")) {
|
||||||
JSONArray jsonArray = respObj.getJSONArray("headers");
|
JSONArray jsonArray = respObj.optJSONArray("headers");
|
||||||
Map<String, String> headMap = new HashMap<>();
|
Map<String, String> headMap = new HashMap<>();
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject headObj = jsonArray.optJSONObject(i);
|
JSONObject headObj = jsonArray.optJSONObject(i);
|
||||||
|
|
|
@ -335,7 +335,7 @@ public class MockConfigService {
|
||||||
JSONObject expectParamsObj = mockExpectRequestObj.optJSONObject("params");
|
JSONObject expectParamsObj = mockExpectRequestObj.optJSONObject("params");
|
||||||
if (expectParamsObj.has("headers")) {
|
if (expectParamsObj.has("headers")) {
|
||||||
//检测headers
|
//检测headers
|
||||||
JSONArray headerArr = expectParamsObj.getJSONArray("headers");
|
JSONArray headerArr = expectParamsObj.optJSONArray("headers");
|
||||||
for (int i = 0; i < headerArr.length(); i++) {
|
for (int i = 0; i < headerArr.length(); i++) {
|
||||||
JSONObject jsonObject = headerArr.optJSONObject(i);
|
JSONObject jsonObject = headerArr.optJSONObject(i);
|
||||||
if (jsonObject.has("name") && jsonObject.has("value")) {
|
if (jsonObject.has("name") && jsonObject.has("value")) {
|
||||||
|
@ -359,7 +359,7 @@ public class MockConfigService {
|
||||||
paramsFilterType = expectBodyObject.optString("paramsFilterType");
|
paramsFilterType = expectBodyObject.optString("paramsFilterType");
|
||||||
}
|
}
|
||||||
if (StringUtils.equalsAnyIgnoreCase(type, "Form Data", "WWW_FORM") && expectBodyObject.has("kvs")) {
|
if (StringUtils.equalsAnyIgnoreCase(type, "Form Data", "WWW_FORM") && expectBodyObject.has("kvs")) {
|
||||||
JSONArray kvsArr = expectBodyObject.getJSONArray("kvs");
|
JSONArray kvsArr = expectBodyObject.optJSONArray("kvs");
|
||||||
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(kvsArr);
|
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(kvsArr);
|
||||||
if (CollectionUtils.isNotEmpty(mockConfigRequestParams)) {
|
if (CollectionUtils.isNotEmpty(mockConfigRequestParams)) {
|
||||||
if (!MockApiUtils.checkParamsCompliance(jsonArray, mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
if (!MockApiUtils.checkParamsCompliance(jsonArray, mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
||||||
|
@ -386,7 +386,7 @@ public class MockConfigService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expectParamsObj.has("arguments")) {
|
if (expectParamsObj.has("arguments")) {
|
||||||
JSONArray argumentsArray = expectParamsObj.getJSONArray("arguments");
|
JSONArray argumentsArray = expectParamsObj.optJSONArray("arguments");
|
||||||
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(argumentsArray);
|
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(argumentsArray);
|
||||||
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getQueryParamsObj(), mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getQueryParamsObj(), mockConfigRequestParams, StringUtils.equals(paramsFilterType, "And"))) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -398,7 +398,7 @@ public class MockConfigService {
|
||||||
restFilterType = expectParamsObj.optString("restFilterType");
|
restFilterType = expectParamsObj.optString("restFilterType");
|
||||||
}
|
}
|
||||||
if (expectParamsObj.has("rest")) {
|
if (expectParamsObj.has("rest")) {
|
||||||
JSONArray restArray = expectParamsObj.getJSONArray("rest");
|
JSONArray restArray = expectParamsObj.optJSONArray("rest");
|
||||||
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(restArray);
|
List<MockConfigRequestParams> mockConfigRequestParams = MockApiUtils.getParamsByJSONArray(restArray);
|
||||||
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getRestParamsObj(), mockConfigRequestParams, StringUtils.equals(restFilterType, "And"))) {
|
if (!MockApiUtils.checkParamsCompliance(requestMockParams.getRestParamsObj(), mockConfigRequestParams, StringUtils.equals(restFilterType, "And"))) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -424,7 +424,7 @@ public class MockConfigService {
|
||||||
mockExpectJson = mockExpectJsonItem;
|
mockExpectJson = mockExpectJsonItem;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JSONArray jsonArray = mockExpectRequestObj.getJSONArray("variables");
|
JSONArray jsonArray = mockExpectRequestObj.optJSONArray("variables");
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject object = jsonArray.optJSONObject(i);
|
JSONObject object = jsonArray.optJSONObject(i);
|
||||||
String name = "";
|
String name = "";
|
||||||
|
@ -470,14 +470,14 @@ public class MockConfigService {
|
||||||
if (requestObj.has("params")) {
|
if (requestObj.has("params")) {
|
||||||
JSONObject paramsObj = requestObj.optJSONObject("params");
|
JSONObject paramsObj = requestObj.optJSONObject("params");
|
||||||
if (paramsObj.has("headers")) {
|
if (paramsObj.has("headers")) {
|
||||||
JSONArray headArray = paramsObj.getJSONArray("headers");
|
JSONArray headArray = paramsObj.optJSONArray("headers");
|
||||||
boolean isHeadMatch = MockApiUtils.matchRequestHeader(headArray, requestHeaderMap);
|
boolean isHeadMatch = MockApiUtils.matchRequestHeader(headArray, requestHeaderMap);
|
||||||
if (!isHeadMatch) {
|
if (!isHeadMatch) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//判断rest为空
|
//判断rest为空
|
||||||
if (paramsObj.has("rest")) {
|
if (paramsObj.has("rest")) {
|
||||||
JSONArray restArray = paramsObj.getJSONArray("rest");
|
JSONArray restArray = paramsObj.optJSONArray("rest");
|
||||||
for (int i = 0; i < restArray.length(); i++) {
|
for (int i = 0; i < restArray.length(); i++) {
|
||||||
JSONObject restObj = restArray.optJSONObject(i);
|
JSONObject restObj = restArray.optJSONObject(i);
|
||||||
if (restObj.has("name") && restObj.has("value")) {
|
if (restObj.has("name") && restObj.has("value")) {
|
||||||
|
@ -487,7 +487,7 @@ public class MockConfigService {
|
||||||
}
|
}
|
||||||
//判断arguments为空
|
//判断arguments为空
|
||||||
if (paramsObj.has("arguments")) {
|
if (paramsObj.has("arguments")) {
|
||||||
JSONArray argumentsArray = paramsObj.getJSONArray("arguments");
|
JSONArray argumentsArray = paramsObj.optJSONArray("arguments");
|
||||||
for (int i = 0; i < argumentsArray.length(); i++) {
|
for (int i = 0; i < argumentsArray.length(); i++) {
|
||||||
JSONObject argumentsObj = argumentsArray.optJSONObject(i);
|
JSONObject argumentsObj = argumentsArray.optJSONObject(i);
|
||||||
if (argumentsObj.has("name") && argumentsObj.has("value")) {
|
if (argumentsObj.has("name") && argumentsObj.has("value")) {
|
||||||
|
@ -513,7 +513,7 @@ public class MockConfigService {
|
||||||
}
|
}
|
||||||
} else if (StringUtils.equalsAnyIgnoreCase(type, "KeyValue", "Form Data", "WWW_FORM")) {
|
} else if (StringUtils.equalsAnyIgnoreCase(type, "KeyValue", "Form Data", "WWW_FORM")) {
|
||||||
if (bodyObj.has("kvs")) {
|
if (bodyObj.has("kvs")) {
|
||||||
JSONArray kvsArray = bodyObj.getJSONArray("kvs");
|
JSONArray kvsArray = bodyObj.optJSONArray("kvs");
|
||||||
for (int i = 0; i < kvsArray.length(); i++) {
|
for (int i = 0; i < kvsArray.length(); i++) {
|
||||||
JSONObject kvsObj = kvsArray.optJSONObject(i);
|
JSONObject kvsObj = kvsArray.optJSONObject(i);
|
||||||
if (kvsObj.has("name") && kvsObj.has("value")) {
|
if (kvsObj.has("name") && kvsObj.has("value")) {
|
||||||
|
@ -547,7 +547,7 @@ public class MockConfigService {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JSONObject mockExpectJson = new JSONObject();
|
JSONObject mockExpectJson = new JSONObject();
|
||||||
JSONArray jsonArray = requestObj.getJSONArray("variables");
|
JSONArray jsonArray = requestObj.optJSONArray("variables");
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject object = jsonArray.optJSONObject(i);
|
JSONObject object = jsonArray.optJSONObject(i);
|
||||||
String name = "";
|
String name = "";
|
||||||
|
@ -583,7 +583,7 @@ public class MockConfigService {
|
||||||
if (responseObj.has("responseResult")) {
|
if (responseObj.has("responseResult")) {
|
||||||
JSONObject responseJsonObj = responseObj.optJSONObject("responseResult");
|
JSONObject responseJsonObj = responseObj.optJSONObject("responseResult");
|
||||||
if (responseJsonObj.has("headers")) {
|
if (responseJsonObj.has("headers")) {
|
||||||
JSONArray jsonArray = responseJsonObj.getJSONArray("headers");
|
JSONArray jsonArray = responseJsonObj.optJSONArray("headers");
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject object = jsonArray.optJSONObject(i);
|
JSONObject object = jsonArray.optJSONObject(i);
|
||||||
if (object.has("name") && object.has("value")) {
|
if (object.has("name") && object.has("value")) {
|
||||||
|
@ -618,7 +618,7 @@ public class MockConfigService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JSONArray jsonArray = responseObj.getJSONArray("httpHeads");
|
JSONArray jsonArray = responseObj.optJSONArray("httpHeads");
|
||||||
for (int i = 0; i < jsonArray.length(); i++) {
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
JSONObject object = jsonArray.optJSONObject(i);
|
JSONObject object = jsonArray.optJSONObject(i);
|
||||||
String name = null;
|
String name = null;
|
||||||
|
@ -746,7 +746,7 @@ public class MockConfigService {
|
||||||
//url参数赋值
|
//url参数赋值
|
||||||
if (requestObj.has("arguments")) {
|
if (requestObj.has("arguments")) {
|
||||||
try {
|
try {
|
||||||
JSONArray headArr = requestObj.getJSONArray("arguments");
|
JSONArray headArr = requestObj.optJSONArray("arguments");
|
||||||
for (int index = 0; index < headArr.length(); index++) {
|
for (int index = 0; index < headArr.length(); index++) {
|
||||||
|
|
||||||
JSONObject headObj = headArr.optJSONObject(index);
|
JSONObject headObj = headArr.optJSONObject(index);
|
||||||
|
@ -759,7 +759,7 @@ public class MockConfigService {
|
||||||
}
|
}
|
||||||
if (requestObj.has("rest")) {
|
if (requestObj.has("rest")) {
|
||||||
try {
|
try {
|
||||||
JSONArray headArr = requestObj.getJSONArray("rest");
|
JSONArray headArr = requestObj.optJSONArray("rest");
|
||||||
for (int index = 0; index < headArr.length(); index++) {
|
for (int index = 0; index < headArr.length(); index++) {
|
||||||
JSONObject headObj = headArr.optJSONObject(index);
|
JSONObject headObj = headArr.optJSONObject(index);
|
||||||
if (headObj.has("name") && !restParamList.contains(headObj.has("name"))) {
|
if (headObj.has("name") && !restParamList.contains(headObj.has("name"))) {
|
||||||
|
@ -778,7 +778,7 @@ public class MockConfigService {
|
||||||
|
|
||||||
if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
|
if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
|
||||||
if (bodyObj.has("kvs")) {
|
if (bodyObj.has("kvs")) {
|
||||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
JSONArray kvsArr = bodyObj.optJSONArray("kvs");
|
||||||
for (int i = 0; i < kvsArr.length(); i++) {
|
for (int i = 0; i < kvsArr.length(); i++) {
|
||||||
JSONObject kv = kvsArr.optJSONObject(i);
|
JSONObject kv = kvsArr.optJSONObject(i);
|
||||||
if (kv.has("name") && !formDataList.contains(kv.has("name"))) {
|
if (kv.has("name") && !formDataList.contains(kv.has("name"))) {
|
||||||
|
|
|
@ -100,8 +100,8 @@ public class MsHashTreeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (object != null && object.getJSONArray(HASH_TREE) != null) {
|
if (object != null && object.optJSONArray(HASH_TREE) != null) {
|
||||||
setHashTree(object.getJSONArray(HASH_TREE));
|
setHashTree(object.optJSONArray(HASH_TREE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class MsHashTreeService {
|
||||||
if (StringUtils.equalsIgnoreCase(element.optString(REFERENCED), REF)) {
|
if (StringUtils.equalsIgnoreCase(element.optString(REFERENCED), REF)) {
|
||||||
JSONObject refElement = JSONUtil.parseObject(apiTestCase.getRequest());
|
JSONObject refElement = JSONUtil.parseObject(apiTestCase.getRequest());
|
||||||
ElementUtil.dataFormatting(refElement);
|
ElementUtil.dataFormatting(refElement);
|
||||||
JSONArray array = refElement.getJSONArray(HASH_TREE);
|
JSONArray array = refElement.optJSONArray(HASH_TREE);
|
||||||
ElementUtil.copyBean(element, refElement);
|
ElementUtil.copyBean(element, refElement);
|
||||||
element.put(HEADERS, refElement.opt(HEADERS));
|
element.put(HEADERS, refElement.opt(HEADERS));
|
||||||
element.put(REST, refElement.opt(REST));
|
element.put(REST, refElement.opt(REST));
|
||||||
|
@ -133,9 +133,9 @@ public class MsHashTreeService {
|
||||||
element.put(ARGUMENTS, refElement.opt(ARGUMENTS));
|
element.put(ARGUMENTS, refElement.opt(ARGUMENTS));
|
||||||
element.put(PROJECT_ID, apiTestCase.getProjectId());
|
element.put(PROJECT_ID, apiTestCase.getProjectId());
|
||||||
if (array != null) {
|
if (array != null) {
|
||||||
JSONArray sourceHashTree = element.getJSONArray(HASH_TREE);
|
JSONArray sourceHashTree = element.optJSONArray(HASH_TREE);
|
||||||
Map<String, List<JSONObject>> groupMap = ElementUtil.group(sourceHashTree);
|
Map<String, List<JSONObject>> groupMap = ElementUtil.group(sourceHashTree);
|
||||||
Map<String, List<JSONObject>> targetGroupMap = ElementUtil.group(refElement.getJSONArray(HASH_TREE));
|
Map<String, List<JSONObject>> targetGroupMap = ElementUtil.group(refElement.optJSONArray(HASH_TREE));
|
||||||
|
|
||||||
List<JSONObject> pre = ElementUtil.mergeHashTree(groupMap.get("PRE"), targetGroupMap.get("PRE"));
|
List<JSONObject> pre = ElementUtil.mergeHashTree(groupMap.get("PRE"), targetGroupMap.get("PRE"));
|
||||||
List<JSONObject> post = ElementUtil.mergeHashTree(groupMap.get("POST"), targetGroupMap.get("POST"));
|
List<JSONObject> post = ElementUtil.mergeHashTree(groupMap.get("POST"), targetGroupMap.get("POST"));
|
||||||
|
@ -223,7 +223,7 @@ public class MsHashTreeService {
|
||||||
hashTree.put(i, element);
|
hashTree.put(i, element);
|
||||||
}
|
}
|
||||||
if (element.has(HASH_TREE)) {
|
if (element.has(HASH_TREE)) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(HASH_TREE);
|
||||||
dataFormatting(elementJSONArray);
|
dataFormatting(elementJSONArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ public class MsHashTreeService {
|
||||||
element = this.setRequest(element);
|
element = this.setRequest(element);
|
||||||
}
|
}
|
||||||
if (element != null && element.has(HASH_TREE)) {
|
if (element != null && element.has(HASH_TREE)) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(HASH_TREE);
|
||||||
dataFormatting(elementJSONArray);
|
dataFormatting(elementJSONArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class ApiScenarioReferenceIdService {
|
||||||
if (!jsonObject.has(MsHashTreeService.HASH_TREE)) {
|
if (!jsonObject.has(MsHashTreeService.HASH_TREE)) {
|
||||||
return returnList;
|
return returnList;
|
||||||
}
|
}
|
||||||
JSONArray hashTree = jsonObject.getJSONArray(MsHashTreeService.HASH_TREE);
|
JSONArray hashTree = jsonObject.optJSONArray(MsHashTreeService.HASH_TREE);
|
||||||
for (int index = 0; index < hashTree.length(); index++) {
|
for (int index = 0; index < hashTree.length(); index++) {
|
||||||
JSONObject item = hashTree.optJSONObject(index);
|
JSONObject item = hashTree.optJSONObject(index);
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
|
@ -140,7 +140,7 @@ public class ApiScenarioReferenceIdService {
|
||||||
returnList.add(saveItem);
|
returnList.add(saveItem);
|
||||||
}
|
}
|
||||||
if (item.has(MsHashTreeService.HASH_TREE)) {
|
if (item.has(MsHashTreeService.HASH_TREE)) {
|
||||||
returnList.addAll(this.deepElementRelation(scenario.getId(), item.getJSONArray(MsHashTreeService.HASH_TREE)));
|
returnList.addAll(this.deepElementRelation(scenario.getId(), item.optJSONArray(MsHashTreeService.HASH_TREE)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ public class ApiScenarioReferenceIdService {
|
||||||
deepRelations.add(saveItem);
|
deepRelations.add(saveItem);
|
||||||
}
|
}
|
||||||
if (item.has(MsHashTreeService.HASH_TREE)) {
|
if (item.has(MsHashTreeService.HASH_TREE)) {
|
||||||
deepRelations.addAll(this.deepElementRelation(scenarioId, item.getJSONArray(MsHashTreeService.HASH_TREE)));
|
deepRelations.addAll(this.deepElementRelation(scenarioId, item.optJSONArray(MsHashTreeService.HASH_TREE)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ public class ApiScenarioReportStructureService {
|
||||||
StepTreeDTO dto = new StepTreeDTO(name, resourceId, element.optString(TYPE), resourceId, 1);
|
StepTreeDTO dto = new StepTreeDTO(name, resourceId, element.optString(TYPE), resourceId, 1);
|
||||||
dto.setAllIndex(null);
|
dto.setAllIndex(null);
|
||||||
if (element.has(HASH_TREE) && !REQUESTS.contains(dto.getType())) {
|
if (element.has(HASH_TREE) && !REQUESTS.contains(dto.getType())) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(HASH_TREE);
|
||||||
dataFormatting(elementJSONArray, dto, id, reportType);
|
dataFormatting(elementJSONArray, dto, id, reportType);
|
||||||
}
|
}
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -221,7 +221,7 @@ public class ApiScenarioReportStructureService {
|
||||||
}
|
}
|
||||||
dto.getChildren().add(children);
|
dto.getChildren().add(children);
|
||||||
if (element.has(HASH_TREE) && !REQUESTS.contains(children.getType())) {
|
if (element.has(HASH_TREE) && !REQUESTS.contains(children.getType())) {
|
||||||
JSONArray elementJSONArray = element.getJSONArray(HASH_TREE);
|
JSONArray elementJSONArray = element.optJSONArray(HASH_TREE);
|
||||||
dataFormatting(elementJSONArray, children, id, reportType);
|
dataFormatting(elementJSONArray, children, id, reportType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,7 @@ public class ApiScenarioService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject element = JSONUtil.parseObject(scenario.getScenarioDefinition());
|
JSONObject element = JSONUtil.parseObject(scenario.getScenarioDefinition());
|
||||||
JSONArray hashTree = element.getJSONArray(ElementConstants.HASH_TREE);
|
JSONArray hashTree = element.optJSONArray(ElementConstants.HASH_TREE);
|
||||||
ApiScenarioImportUtil.formatHashTree(hashTree);
|
ApiScenarioImportUtil.formatHashTree(hashTree);
|
||||||
setReferenced(hashTree, scenario.getVersionId(), scenario.getProjectId(), apiTestCaseMapper, apiDefinitionMapper, true);
|
setReferenced(hashTree, scenario.getVersionId(), scenario.getProjectId(), apiTestCaseMapper, apiDefinitionMapper, true);
|
||||||
scenario.setScenarioDefinition(element.toString());
|
scenario.setScenarioDefinition(element.toString());
|
||||||
|
@ -731,8 +731,8 @@ public class ApiScenarioService {
|
||||||
for (int i = 0; i < valueArray.length(); i++) {
|
for (int i = 0; i < valueArray.length(); i++) {
|
||||||
try {
|
try {
|
||||||
JSONObject obj = (JSONObject) valueArray.get(i);
|
JSONObject obj = (JSONObject) valueArray.get(i);
|
||||||
JSONObject targetValue = jsonMerge(obj, (JSONObject) target.getJSONArray(key).get(i));
|
JSONObject targetValue = jsonMerge(obj, (JSONObject) target.optJSONArray(key).get(i));
|
||||||
target.getJSONArray(key).put(i, targetValue);
|
target.optJSONArray(key).put(i, targetValue);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
}
|
}
|
||||||
|
@ -783,7 +783,7 @@ public class ApiScenarioService {
|
||||||
ParameterConfig config = new ParameterConfig();
|
ParameterConfig config = new ParameterConfig();
|
||||||
apiScenarioEnvService.setEnvConfig(environmentMap, config);
|
apiScenarioEnvService.setEnvConfig(environmentMap, config);
|
||||||
if (config.getConfig() != null && !config.getConfig().isEmpty()) {
|
if (config.getConfig() != null && !config.getConfig().isEmpty()) {
|
||||||
ElementUtil.dataSetDomain(element.getJSONArray(ElementConstants.HASH_TREE), config);
|
ElementUtil.dataSetDomain(element.optJSONArray(ElementConstants.HASH_TREE), config);
|
||||||
}
|
}
|
||||||
return element.toString();
|
return element.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1490,7 +1490,7 @@ public class ApiScenarioService {
|
||||||
}
|
}
|
||||||
JSONObject element = JSONUtil.parseObject(scenario.getScenarioDefinition());
|
JSONObject element = JSONUtil.parseObject(scenario.getScenarioDefinition());
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
JSONArray hashTree = element.getJSONArray(ElementConstants.HASH_TREE);
|
JSONArray hashTree = element.optJSONArray(ElementConstants.HASH_TREE);
|
||||||
ApiScenarioImportUtil.formatHashTree(hashTree);
|
ApiScenarioImportUtil.formatHashTree(hashTree);
|
||||||
setHashTree(hashTree);
|
setHashTree(hashTree);
|
||||||
scenario.setScenarioDefinition(element.toString());
|
scenario.setScenarioDefinition(element.toString());
|
||||||
|
@ -1511,19 +1511,19 @@ public class ApiScenarioService {
|
||||||
String refType = object.optString("refType");
|
String refType = object.optString("refType");
|
||||||
if (StringUtils.isNotEmpty(refType)) {
|
if (StringUtils.isNotEmpty(refType)) {
|
||||||
if (refType.equals("CASE")) {
|
if (refType.equals("CASE")) {
|
||||||
if (object.getJSONArray(ElementConstants.HASH_TREE) == null || object.getJSONArray(ElementConstants.HASH_TREE).length() == 0) {
|
if (object.optJSONArray(ElementConstants.HASH_TREE) == null || object.optJSONArray(ElementConstants.HASH_TREE).length() == 0) {
|
||||||
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.optString("id"));
|
ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.optString("id"));
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
JSONObject element = JSONUtil.parseObject(model.getRequest());
|
JSONObject element = JSONUtil.parseObject(model.getRequest());
|
||||||
object.put(ElementConstants.HASH_TREE, element.getJSONArray(ElementConstants.HASH_TREE));
|
object.put(ElementConstants.HASH_TREE, element.optJSONArray(ElementConstants.HASH_TREE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(object.optString("refType"))) {
|
if (StringUtils.isNotEmpty(object.optString("refType"))) {
|
||||||
if (object.getJSONArray(ElementConstants.HASH_TREE) != null) {
|
if (object.optJSONArray(ElementConstants.HASH_TREE) != null) {
|
||||||
setHashTree(object.getJSONArray(ElementConstants.HASH_TREE));
|
setHashTree(object.optJSONArray(ElementConstants.HASH_TREE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2099,12 +2099,12 @@ public class ApiScenarioService {
|
||||||
object.put("environmentMap", new HashMap<>());
|
object.put("environmentMap", new HashMap<>());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(object.optString("refType")) && object.optString("refType").equals("CASE")) {
|
if (StringUtils.isNotEmpty(object.optString("refType")) && object.optString("refType").equals("CASE")) {
|
||||||
if (object.has(ElementConstants.HASH_TREE) && object.getJSONArray(ElementConstants.HASH_TREE) != null) {
|
if (object.has(ElementConstants.HASH_TREE) && object.optJSONArray(ElementConstants.HASH_TREE) != null) {
|
||||||
setReferenced(object.getJSONArray(ElementConstants.HASH_TREE), versionId, projectId, apiTestCaseMapper, apiDefinitionMapper, true);
|
setReferenced(object.optJSONArray(ElementConstants.HASH_TREE), versionId, projectId, apiTestCaseMapper, apiDefinitionMapper, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (object.has(ElementConstants.HASH_TREE) && object.getJSONArray(ElementConstants.HASH_TREE) != null) {
|
if (object.has(ElementConstants.HASH_TREE) && object.optJSONArray(ElementConstants.HASH_TREE) != null) {
|
||||||
setReferenced(object.getJSONArray(ElementConstants.HASH_TREE), versionId, projectId, apiTestCaseMapper, apiDefinitionMapper, false);
|
setReferenced(object.optJSONArray(ElementConstants.HASH_TREE), versionId, projectId, apiTestCaseMapper, apiDefinitionMapper, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,12 +100,9 @@ export default {
|
||||||
this.$emit('runRefresh', {});
|
this.$emit('runRefresh', {});
|
||||||
|
|
||||||
let url = '/api/automation/run/debug';
|
let url = '/api/automation/run/debug';
|
||||||
if (this.runData.type === 'UiScenario') {
|
|
||||||
url = '/ui/automation/run/debug';
|
|
||||||
}
|
|
||||||
saveScenario(url, reqObj, this.runData.hashTree, this, (response) => {
|
saveScenario(url, reqObj, this.runData.hashTree, this, (response) => {
|
||||||
if (response.data !== "SUCCESS") {
|
if (response.data !== "SUCCESS") {
|
||||||
this.$error(response.message ? response.message : this.$t('commons.run_fail'));
|
this.$error(response.data ? response.data : this.$t('commons.run_fail'));
|
||||||
this.$emit('errorRefresh');
|
this.$emit('errorRefresh');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -273,7 +273,7 @@ import {
|
||||||
initCondition
|
initCondition
|
||||||
} from "metersphere-frontend/src/utils/tableUtils";
|
} from "metersphere-frontend/src/utils/tableUtils";
|
||||||
import HeaderLabelOperate from "metersphere-frontend/src/components/head/HeaderLabelOperate";
|
import HeaderLabelOperate from "metersphere-frontend/src/components/head/HeaderLabelOperate";
|
||||||
import {Body} from "@/business/definition/model/ApiTestModel";
|
import {Body, KeyValue} from "@/business/definition/model/ApiTestModel";
|
||||||
import {getGraphByCondition} from "@/api/graph";
|
import {getGraphByCondition} from "@/api/graph";
|
||||||
import ListItemDeleteConfirm from "metersphere-frontend/src/components/ListItemDeleteConfirm";
|
import ListItemDeleteConfirm from "metersphere-frontend/src/components/ListItemDeleteConfirm";
|
||||||
import MsSearch from "metersphere-frontend/src/components/search/MsSearch";
|
import MsSearch from "metersphere-frontend/src/components/search/MsSearch";
|
||||||
|
@ -718,6 +718,11 @@ export default {
|
||||||
}
|
}
|
||||||
if (!item.request.headers) {
|
if (!item.request.headers) {
|
||||||
item.request.headers = [];
|
item.request.headers = [];
|
||||||
|
} else if (item.request.headers.length === 1) {
|
||||||
|
let values = item.request.headers.filter(tab => tab.name !== '');
|
||||||
|
if (values.length > 0) {
|
||||||
|
item.request.headers.push(new KeyValue({enable: true}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!item.request.body.kvs) {
|
if (!item.request.body.kvs) {
|
||||||
item.request.body.kvs = [];
|
item.request.body.kvs = [];
|
||||||
|
@ -727,8 +732,20 @@ export default {
|
||||||
i.files = []
|
i.files = []
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!item.request.rest) {
|
if (!item.request.rest) {
|
||||||
item.request.rest = [];
|
item.request.rest = [];
|
||||||
|
} else if (item.request.rest.length === 1) {
|
||||||
|
let values = item.request.rest.filter(tab => tab.name !== '');
|
||||||
|
if (values.length > 0) {
|
||||||
|
item.request.rest.push(new KeyValue({enable: true}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.request.query && item.request.query.length === 1) {
|
||||||
|
let values = item.request.query.filter(tab => tab.name !== '');
|
||||||
|
if (values.length > 0) {
|
||||||
|
item.request.query.push(new KeyValue({enable: true}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!item.request.arguments) {
|
if (!item.request.arguments) {
|
||||||
item.request.arguments = [{
|
item.request.arguments = [{
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<el-tooltip class="item-tabs" effect="dark" :content="$t('api_test.definition.request.query_info')"
|
<el-tooltip class="item-tabs" effect="dark" :content="$t('api_test.definition.request.query_info')"
|
||||||
placement="top-start" slot="label">
|
placement="top-start" slot="label">
|
||||||
<span>{{ $t('api_test.definition.request.query_param') }}
|
<span>{{ $t('api_test.definition.request.query_param') }}
|
||||||
<div class="el-step__icon is-text ms-api-col ms-header" v-if="request.arguments.length>1">
|
<div class="el-step__icon is-text ms-api-col ms-header" v-if="request.arguments.length > 1">
|
||||||
<div class="el-step__icon-inner">{{ request.arguments.length - 1 }}</div>
|
<div class="el-step__icon-inner">{{ request.arguments.length - 1 }}</div>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
placement="top-start" slot="label">
|
placement="top-start" slot="label">
|
||||||
<span>
|
<span>
|
||||||
{{ $t('api_test.definition.request.rest_param') }}
|
{{ $t('api_test.definition.request.rest_param') }}
|
||||||
<div class="el-step__icon is-text ms-api-col ms-header" v-if="request.rest.length>1">
|
<div class="el-step__icon is-text ms-api-col ms-header" v-if="request.rest.length > 1">
|
||||||
<div class="el-step__icon-inner">{{ request.rest.length - 1 }}</div>
|
<div class="el-step__icon-inner">{{ request.rest.length - 1 }}</div>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
|
|
Loading…
Reference in New Issue