diff --git a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java index f40a332943..13ab227b63 100644 --- a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java +++ b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java @@ -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 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 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 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 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 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(); } diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index 398e34e106..14d2a81f82 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -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) {