feat(测试用例、Mock测试): 修复测试用例导入和删除的缺陷、Mock测试的缺陷
--bug=1005212 --user=宋天阳 【回收站】-删除用例统计信息不正常 https://www.tapd.cn/55049933/s/1026637;--bug=1005228 --user=宋天阳 【mock】不满足mock期望,仍返回200 https://www.tapd.cn/55049933/s/1026636;--bug=1005266 --user=宋天阳 【测试用例】导入excel用例,名称显示... https://www.tapd.cn/55049933/s/1026633
This commit is contained in:
parent
b4a5a008b6
commit
09e9b5b79d
|
@ -17,6 +17,7 @@ import io.metersphere.commons.utils.JsonPathUtils;
|
|||
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.json.XML;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -392,120 +393,129 @@ public class MockConfigService {
|
|||
public String updateHttpServletResponse(List<ApiDefinitionWithBLOBs> apis, HttpServletResponse response) {
|
||||
String returnStr = "";
|
||||
try {
|
||||
for (ApiDefinitionWithBLOBs api : apis) {
|
||||
if (api.getResponse() != null) {
|
||||
JSONObject respObj = JSONObject.parseObject(api.getResponse());
|
||||
if (respObj.containsKey("headers")) {
|
||||
JSONArray headersArr = respObj.getJSONArray("headers");
|
||||
for (int i = 0; i < headersArr.size(); i++) {
|
||||
JSONObject obj = headersArr.getJSONObject(i);
|
||||
if (obj.containsKey("name") && obj.containsKey("value") && StringUtils.isNotEmpty(obj.getString("name"))) {
|
||||
response.setHeader(obj.getString("name"), obj.getString("value"));
|
||||
if(CollectionUtils.isEmpty(apis)){
|
||||
response.setStatus(404);
|
||||
}else {
|
||||
for (ApiDefinitionWithBLOBs api : apis) {
|
||||
int status = 404;
|
||||
if (api.getResponse() != null) {
|
||||
JSONObject respObj = JSONObject.parseObject(api.getResponse());
|
||||
if (respObj.containsKey("headers")) {
|
||||
JSONArray headersArr = respObj.getJSONArray("headers");
|
||||
for (int i = 0; i < headersArr.size(); i++) {
|
||||
JSONObject obj = headersArr.getJSONObject(i);
|
||||
if (obj.containsKey("name") && obj.containsKey("value") && StringUtils.isNotEmpty(obj.getString("name"))) {
|
||||
response.setHeader(obj.getString("name"), obj.getString("value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (respObj.containsKey("statusCode")) {
|
||||
JSONArray statusCodeArr = respObj.getJSONArray("statusCode");
|
||||
for (int i = 0; i < statusCodeArr.size(); i++) {
|
||||
JSONObject obj = statusCodeArr.getJSONObject(i);
|
||||
if (obj.containsKey("name") && obj.containsKey("value") && StringUtils.isNotEmpty(obj.getString("name"))) {
|
||||
if (respObj.containsKey("statusCode")) {
|
||||
JSONArray statusCodeArr = respObj.getJSONArray("statusCode");
|
||||
for (int i = 0; i < statusCodeArr.size(); i++) {
|
||||
JSONObject obj = statusCodeArr.getJSONObject(i);
|
||||
if (obj.containsKey("name") && obj.containsKey("value") && StringUtils.isNotEmpty(obj.getString("name"))) {
|
||||
// response.setHeader(obj.getString("name"), obj.getString("value"));
|
||||
try {
|
||||
int headInt = Integer.parseInt(obj.getString("name"));
|
||||
response.setStatus(headInt);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
status = Integer.parseInt(obj.getString("name"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (respObj.containsKey("body")) {
|
||||
JSONObject bodyObj = respObj.getJSONObject("body");
|
||||
if (bodyObj.containsKey("type")) {
|
||||
String type = bodyObj.getString("type");
|
||||
if (StringUtils.equals(type, "JSON")) {
|
||||
//判断是否是JsonSchema
|
||||
boolean isJsonSchema = false;
|
||||
if (bodyObj.containsKey("format")) {
|
||||
String foramtValue = String.valueOf(bodyObj.get("format"));
|
||||
if (StringUtils.equals("JSON-SCHEMA", foramtValue)) {
|
||||
isJsonSchema = true;
|
||||
if (respObj.containsKey("body")) {
|
||||
JSONObject bodyObj = respObj.getJSONObject("body");
|
||||
if (bodyObj.containsKey("type")) {
|
||||
String type = bodyObj.getString("type");
|
||||
if (StringUtils.equals(type, "JSON")) {
|
||||
//判断是否是JsonSchema
|
||||
boolean isJsonSchema = false;
|
||||
if (bodyObj.containsKey("format")) {
|
||||
String foramtValue = String.valueOf(bodyObj.get("format"));
|
||||
if (StringUtils.equals("JSON-SCHEMA", foramtValue)) {
|
||||
isJsonSchema = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isJsonSchema) {
|
||||
if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) {
|
||||
String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString();
|
||||
JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr);
|
||||
JSONObject returnObj = this.parseJsonSchema(bodyReturnObj);
|
||||
returnStr = returnObj.toJSONString();
|
||||
if (isJsonSchema) {
|
||||
if (bodyObj.containsKey("jsonSchema") && bodyObj.getJSONObject("jsonSchema").containsKey("properties")) {
|
||||
String bodyRetunStr = bodyObj.getJSONObject("jsonSchema").getJSONObject("properties").toJSONString();
|
||||
JSONObject bodyReturnObj = JSONObject.parseObject(bodyRetunStr);
|
||||
JSONObject returnObj = this.parseJsonSchema(bodyReturnObj);
|
||||
returnStr = returnObj.toJSONString();
|
||||
}
|
||||
} else {
|
||||
if (bodyObj.containsKey("raw")) {
|
||||
returnStr = bodyObj.getString("raw");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (StringUtils.equalsAny(type, "XML", "Raw")) {
|
||||
if (bodyObj.containsKey("raw")) {
|
||||
returnStr = bodyObj.getString("raw");
|
||||
String raw = bodyObj.getString("raw");
|
||||
returnStr = raw;
|
||||
}
|
||||
}
|
||||
} else if (StringUtils.equalsAny(type, "XML", "Raw")) {
|
||||
if (bodyObj.containsKey("raw")) {
|
||||
String raw = bodyObj.getString("raw");
|
||||
returnStr = raw;
|
||||
}
|
||||
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
|
||||
Map<String, String> paramMap = new LinkedHashMap<>();
|
||||
if (bodyObj.containsKey("kvs")) {
|
||||
JSONArray bodyParamArr = new JSONArray();
|
||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
||||
for (int i = 0; i < kvsArr.size(); i++) {
|
||||
JSONObject kv = kvsArr.getJSONObject(i);
|
||||
if (kv.containsKey("name")) {
|
||||
String values = kv.getString("value");
|
||||
if (StringUtils.isEmpty(values)) {
|
||||
values = "";
|
||||
} else {
|
||||
try {
|
||||
values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
paramMap.put(kv.getString("name"), values);
|
||||
}
|
||||
}
|
||||
}
|
||||
returnStr = JSONObject.toJSONString(paramMap);
|
||||
} else if (StringUtils.equals(type, "BINARY")) {
|
||||
Map<String, String> paramMap = new LinkedHashMap<>();
|
||||
if (bodyObj.containsKey("binary")) {
|
||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
||||
for (int i = 0; i < kvsArr.size(); i++) {
|
||||
JSONObject kv = kvsArr.getJSONObject(i);
|
||||
if (kv.containsKey("description") && kv.containsKey("files")) {
|
||||
String name = kv.getString("description");
|
||||
JSONArray fileArr = kv.getJSONArray("files");
|
||||
String allValue = "";
|
||||
for (int j = 0; j < fileArr.size(); j++) {
|
||||
JSONObject fileObj = fileArr.getJSONObject(j);
|
||||
if (fileObj.containsKey("name")) {
|
||||
String values = fileObj.getString("name");
|
||||
if (StringUtils.isEmpty(values)) {
|
||||
values = "";
|
||||
} else {
|
||||
try {
|
||||
values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} else if (StringUtils.equalsAny(type, "Form Data", "WWW_FORM")) {
|
||||
Map<String, String> paramMap = new LinkedHashMap<>();
|
||||
if (bodyObj.containsKey("kvs")) {
|
||||
JSONArray bodyParamArr = new JSONArray();
|
||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
||||
for (int i = 0; i < kvsArr.size(); i++) {
|
||||
JSONObject kv = kvsArr.getJSONObject(i);
|
||||
if (kv.containsKey("name")) {
|
||||
String values = kv.getString("value");
|
||||
if (StringUtils.isEmpty(values)) {
|
||||
values = "";
|
||||
} else {
|
||||
try {
|
||||
values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
allValue += values + " ;";
|
||||
}
|
||||
paramMap.put(kv.getString("name"), values);
|
||||
}
|
||||
paramMap.put(name, allValue);
|
||||
}
|
||||
}
|
||||
returnStr = JSONObject.toJSONString(paramMap);
|
||||
} else if (StringUtils.equals(type, "BINARY")) {
|
||||
Map<String, String> paramMap = new LinkedHashMap<>();
|
||||
if (bodyObj.containsKey("binary")) {
|
||||
JSONArray kvsArr = bodyObj.getJSONArray("kvs");
|
||||
for (int i = 0; i < kvsArr.size(); i++) {
|
||||
JSONObject kv = kvsArr.getJSONObject(i);
|
||||
if (kv.containsKey("description") && kv.containsKey("files")) {
|
||||
String name = kv.getString("description");
|
||||
JSONArray fileArr = kv.getJSONArray("files");
|
||||
String allValue = "";
|
||||
for (int j = 0; j < fileArr.size(); j++) {
|
||||
JSONObject fileObj = fileArr.getJSONObject(j);
|
||||
if (fileObj.containsKey("name")) {
|
||||
String values = fileObj.getString("name");
|
||||
if (StringUtils.isEmpty(values)) {
|
||||
values = "";
|
||||
} else {
|
||||
try {
|
||||
values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
allValue += values + " ;";
|
||||
}
|
||||
}
|
||||
paramMap.put(name, allValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
returnStr = JSONObject.toJSONString(paramMap);
|
||||
}
|
||||
returnStr = JSONObject.toJSONString(paramMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotEmpty(returnStr) && status == 404){
|
||||
status = 200;
|
||||
}
|
||||
response.setStatus(status);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -502,10 +502,13 @@ export default {
|
|||
// param.planId = this.planId;
|
||||
this.condition.planId = this.planId;
|
||||
}
|
||||
if (this.selectNodeIds && this.selectNodeIds.length > 0) {
|
||||
// param.nodeIds = this.selectNodeIds;
|
||||
this.condition.nodeIds = this.selectNodeIds;
|
||||
if(!this.trashEnable){
|
||||
if (this.selectNodeIds && this.selectNodeIds.length > 0) {
|
||||
// param.nodeIds = this.selectNodeIds;
|
||||
this.condition.nodeIds = this.selectNodeIds;
|
||||
}
|
||||
}
|
||||
|
||||
this.getData();
|
||||
},
|
||||
getData() {
|
||||
|
@ -546,6 +549,9 @@ export default {
|
|||
this.page.data = data.listObject;
|
||||
if (this.$refs.table) {
|
||||
this.$refs.table.clear();
|
||||
this.$nextTick(() => {
|
||||
this.$refs.table.doLayout();
|
||||
});
|
||||
}
|
||||
this.page.data.forEach(item => {
|
||||
if (item.customFields) {
|
||||
|
|
Loading…
Reference in New Issue