diff --git a/backend/src/main/java/io/metersphere/api/controller/MockConfigController.java b/backend/src/main/java/io/metersphere/api/controller/MockConfigController.java index 48c7810fb4..fd8029240e 100644 --- a/backend/src/main/java/io/metersphere/api/controller/MockConfigController.java +++ b/backend/src/main/java/io/metersphere/api/controller/MockConfigController.java @@ -1,5 +1,6 @@ package io.metersphere.api.controller; +import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.mock.MockParamSuggestions; import io.metersphere.api.dto.mock.MockTestDataRequest; import io.metersphere.api.dto.mockconfig.MockConfigRequest; @@ -82,4 +83,10 @@ public class MockConfigController { return testDataUtil.parseTestDataByRequest(requestArray); } + @PostMapping("/getTcpMockTestData") + public List getTcpMockTestData(@RequestBody List requestArray) { + MockTestDataUtil testDataUtil = new MockTestDataUtil(); + return testDataUtil.parseTestDataByTcpTreeTableData(requestArray); + } + } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java b/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java index 6a545c4efd..eebc6379d3 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/TcpTreeTableDataStruct.java @@ -28,6 +28,7 @@ public class TcpTreeTableDataStruct { private String type; private String systemName; private String contentType; + private String condition; private boolean required; private String description; private List children; @@ -114,7 +115,6 @@ public class TcpTreeTableDataStruct { try { element = document.addElement(this.name); if (StringUtils.equalsAnyIgnoreCase(type, "string", "array")) { - long lengthNum = Long.parseLong(this.contentType); String attrString = ""; if (StringUtils.equalsIgnoreCase(this.type, "string")) { attrString = "s," + contentType; @@ -153,7 +153,6 @@ public class TcpTreeTableDataStruct { try { element = document.addElement(this.name); if (StringUtils.equalsAnyIgnoreCase(type, "string", "array")) { - long lengthNum = Long.parseLong(this.contentType); String attrString = ""; if (StringUtils.equalsIgnoreCase(this.type, "string")) { attrString = "s," + contentType; diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/TcpTreeTableDataParser.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/TcpTreeTableDataParser.java index ec675f19fe..badad420f3 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/TcpTreeTableDataParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/TcpTreeTableDataParser.java @@ -1,12 +1,17 @@ package io.metersphere.api.dto.automation.parse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; +import io.metersphere.api.dto.mock.MockConfigRequestParams; +import io.metersphere.api.mock.utils.MockApiUtils; import io.metersphere.commons.utils.LogUtil; import org.apache.commons.lang3.StringUtils; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; +import org.springframework.util.CollectionUtils; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -32,11 +37,11 @@ public class TcpTreeTableDataParser { Document document = DocumentHelper.createDocument(); TcpTreeTableDataStruct dataStruct = null; - if(treeDataList.size()>1){ + if (treeDataList.size() > 1) { dataStruct = new TcpTreeTableDataStruct(); dataStruct.setName("ROOT"); dataStruct.setChildren(treeDataList); - }else { + } else { dataStruct = treeDataList.get(0); } @@ -77,4 +82,60 @@ public class TcpTreeTableDataParser { return xmlString; } + public static boolean isMatchTreeTableData(JSONObject sourceObj, List tcpDataList) { + if (CollectionUtils.isEmpty(tcpDataList)) { + return true; + } + if (sourceObj == null) { + sourceObj = new JSONObject(); + } + + boolean isMatch = false; + for (TcpTreeTableDataStruct dataStruct : tcpDataList) { + if(isMatch){ + break; + } + String key = dataStruct.getName(); + if (sourceObj.containsKey(key)) { + Object sourceObjItem = sourceObj.get(key); + if (sourceObjItem instanceof JSONObject) { + if (!CollectionUtils.isEmpty(dataStruct.getChildren())) { + if (!isMatchTreeTableData((JSONObject) sourceObjItem, dataStruct.getChildren())) { + continue; + } + } else { + continue; + } + } else if (sourceObjItem instanceof JSONArray) { + if (!CollectionUtils.isEmpty(dataStruct.getChildren())) { + JSONArray jsonArray = (JSONArray) sourceObjItem; + for (int i = 0; i < jsonArray.size(); i ++){ + Object itemObj = jsonArray.get(i); + if(itemObj instanceof JSONObject){ + if (!isMatchTreeTableData((JSONObject) itemObj, dataStruct.getChildren())) { + continue; + } + }else { + continue; + } + } + } else { + continue; + } + } else { + String sourceValues = String.valueOf(sourceObjItem); + MockConfigRequestParams mockParams = new MockConfigRequestParams(); + mockParams.setKey(dataStruct.getName()); + mockParams.setValue(dataStruct.getValue()); + mockParams.setCondition(dataStruct.getCondition()); + if (!MockApiUtils.isValueMatch(sourceValues, mockParams)) { + continue; + } + } + } + isMatch = true; + } + + return isMatch; + } } diff --git a/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java b/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java index 6644ef1e00..ba46189cfa 100644 --- a/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java +++ b/backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java @@ -701,7 +701,7 @@ public class MockApiUtils { return false; } - private static boolean isValueMatch(String requestParam, MockConfigRequestParams params) { + public static boolean isValueMatch(String requestParam, MockConfigRequestParams params) { if (StringUtils.equals(params.getCondition(), MockParamConditionEnum.VALUE_EQUALS.name())) { return StringUtils.equals(requestParam, params.getValue()); } else if (StringUtils.equals(params.getCondition(), MockParamConditionEnum.VALUE_NOT_EQUALS.name())) { diff --git a/backend/src/main/java/io/metersphere/api/mock/utils/MockTestDataUtil.java b/backend/src/main/java/io/metersphere/api/mock/utils/MockTestDataUtil.java index 62ea255e3f..d2d36a976f 100644 --- a/backend/src/main/java/io/metersphere/api/mock/utils/MockTestDataUtil.java +++ b/backend/src/main/java/io/metersphere/api/mock/utils/MockTestDataUtil.java @@ -1,11 +1,13 @@ package io.metersphere.api.mock.utils; import com.mifmif.common.regex.Generex; +import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.mock.MockTestDataRequest; import io.metersphere.api.mock.dto.MockParamConditionEnum; import io.metersphere.commons.utils.LogUtil; import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; import java.util.List; @@ -50,4 +52,49 @@ public class MockTestDataUtil { return ""; } } + + public String getTestData(TcpTreeTableDataStruct condition) { + if (StringUtils.equals(MockApiUtils.parseCondition(condition.getCondition()), MockParamConditionEnum.VALUE_EQUALS.name())) { + return condition.getValue(); + } else if (StringUtils.equalsAny(MockApiUtils.parseCondition(condition.getCondition()), MockParamConditionEnum.VALUE_CONTAINS.name(), MockParamConditionEnum.VALUE_NOT_EQUALS.name())) { + return condition.getValue() + "A"; + } else if (StringUtils.equals(MockApiUtils.parseCondition(condition.getCondition()), MockParamConditionEnum.LENGTH_EQUALS.name())) { + int length = Integer.parseInt(condition.getValue()); + return RandomStringUtils.randomAlphanumeric(length); + } else if (StringUtils.equalsAny(MockApiUtils.parseCondition(condition.getCondition()), MockParamConditionEnum.LENGTH_NOT_EQUALS.name(), MockParamConditionEnum.LENGTH_LARGE_THAN.name())) { + int length = Integer.parseInt(condition.getValue()) + 1; + return RandomStringUtils.randomAlphanumeric(length); + } else if (StringUtils.equals(MockApiUtils.parseCondition(condition.getCondition()), MockParamConditionEnum.LENGTH_SHOT_THAN.name())) { + int length = Integer.parseInt(condition.getValue()); + if(length > 1){ + return RandomStringUtils.randomAlphanumeric(length); + }else { + return ""; + } + } else if (StringUtils.equals(MockApiUtils.parseCondition(condition.getCondition()), MockParamConditionEnum.REGULAR_MATCH.name())) { + if (StringUtils.isNotEmpty(condition.getValue())) { + Generex generex = new Generex(condition.getValue()); + String randomStr = generex.random(); + return randomStr; + }else { + return ""; + } + } else { + return ""; + } + } + + public List parseTestDataByTcpTreeTableData(List requestArray) { + for (TcpTreeTableDataStruct request : requestArray) { + try{ + request.setValue(this.getTestData(request)); + if(!CollectionUtils.isEmpty(request.getChildren())){ + this.parseTestDataByTcpTreeTableData(request.getChildren()); + } + }catch (Exception e){ + LogUtil.error(e); + } + } + return requestArray; + } } 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 a5d4e61353..0bb6ec1e01 100644 --- a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java +++ b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java @@ -1292,15 +1292,12 @@ public class MockConfigService { } else if (isXMLMessage && StringUtils.equalsIgnoreCase(reportType, "xml")) { if (requestJson.containsKey("xmlDataStruct")) { JSONObject sourceObj = XMLUtils.XmlToJson(message); - String xmlStr = ""; try { List tcpDataList = JSONArray.parseArray(requestJson.getString("xmlDataStruct"), TcpTreeTableDataStruct.class); - xmlStr = TcpTreeTableDataParser.treeTableData2Xml(tcpDataList); + isMatch = TcpTreeTableDataParser.isMatchTreeTableData(sourceObj,tcpDataList); } catch (Exception e) { LogUtil.error(e); } - JSONObject matchObj = XMLUtils.XmlToJson(xmlStr); - isMatch = JsonStructUtils.checkJsonObjCompliance(sourceObj, matchObj); } } else if (StringUtils.equalsIgnoreCase(reportType, "raw")) { if (requestJson.containsKey("rawDataStruct")) { diff --git a/backend/src/main/java/io/metersphere/api/tcp/server/TCPServicer.java b/backend/src/main/java/io/metersphere/api/tcp/server/TCPServicer.java index 2c0a1b7b8f..f56893726d 100644 --- a/backend/src/main/java/io/metersphere/api/tcp/server/TCPServicer.java +++ b/backend/src/main/java/io/metersphere/api/tcp/server/TCPServicer.java @@ -16,6 +16,7 @@ public class TCPServicer { private InputStream is; private OutputStream os; private int port; + public TCPServicer(Socket s, int port) { this.s = s; this.port = port; @@ -29,49 +30,50 @@ public class TCPServicer { is = s.getInputStream(); os = s.getOutputStream(); int len = is.read(b); - message = new String(b,0,len); + message = new String(b, 0, len); returnMsg = this.getReturnMsg(message); os.write(returnMsg.getBytes()); } catch (Exception e) { LogUtil.error(e); - }finally { + } finally { this.close(); } } private String getReturnMsg(String message) { + LogUtil.info("TCP-Mock start. port: " + this.port + "; Message:" + message); MockConfigService mockConfigService = CommonBeanFactory.getBean(MockConfigService.class); - MockExpectConfigWithBLOBs matchdMockExpect = mockConfigService.matchTcpMockExpect(message,this.port); + MockExpectConfigWithBLOBs matchdMockExpect = mockConfigService.matchTcpMockExpect(message, this.port); String returnMsg = ""; - if(matchdMockExpect != null){ + if (matchdMockExpect != null) { String response = matchdMockExpect.getResponse(); JSONObject responseObj = JSONObject.parseObject(response); int delayed = 0; try { - if(responseObj.containsKey("delayed")){ + if (responseObj.containsKey("delayed")) { delayed = responseObj.getInteger("delayed"); } } catch (Exception e) { LogUtil.error(e); } - if(responseObj.containsKey("responseResult")){ + if (responseObj.containsKey("responseResult")) { JSONObject respResultObj = responseObj.getJSONObject("responseResult"); - if(respResultObj.containsKey("body")){ + if (respResultObj.containsKey("body")) { MockApiUtils mockApiUtils = new MockApiUtils(); boolean useScript = false; - if(respResultObj.containsKey("usePostScript")){ + if (respResultObj.containsKey("usePostScript")) { useScript = respResultObj.getBoolean("usePostScript"); } - returnMsg = mockApiUtils.getResultByResponseResult(respResultObj.getJSONObject("body"),"",null,null,useScript); + returnMsg = mockApiUtils.getResultByResponseResult(respResultObj.getJSONObject("body"), "", null, null, useScript); } try { - if(respResultObj.containsKey("delayed")){ + if (respResultObj.containsKey("delayed")) { delayed = respResultObj.getInteger("delayed"); } } catch (Exception e) { LogUtil.error(e); } - }else { + } else { returnMsg = responseObj.getString("body"); } @@ -86,16 +88,20 @@ public class TCPServicer { public void close() { //关闭资源 - try{ + try { is.close(); - }catch (Exception e){}finally { - try{ + } catch (Exception e) { + LogUtil.error(e); + } finally { + try { os.close(); - }catch (Exception e){}finally { - try{ + } catch (Exception e) { + LogUtil.error(e); + } finally { + try { s.close(); - }catch (Exception e){}finally { - + } catch (Exception e) { + LogUtil.error(e); } } } diff --git a/backend/src/main/java/io/metersphere/commons/utils/XMLUtils.java b/backend/src/main/java/io/metersphere/commons/utils/XMLUtils.java index 77943d0230..51cd2b272b 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/XMLUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/XMLUtils.java @@ -71,13 +71,9 @@ public class XMLUtils { } xml = xml.substring(begin + 2); } // 若存在,则去除 - String rgex = "\\s*"; + String rgex = ">"; Pattern pattern = Pattern.compile(rgex); Matcher m = pattern.matcher(xml); - xml = m.replaceAll(""); - rgex = ">"; - pattern = Pattern.compile(rgex); - m = pattern.matcher(xml); xml = m.replaceAll("> "); rgex = "\\s*
- @@ -19,33 +19,48 @@ - {{scope.row.type}} + {{ scope.row.type }} + + + @@ -67,53 +86,134 @@ export default { components: {}, props: { tableData: Array, - showOptionsButton:Boolean, + showOptionsButton: Boolean, + showOperationCol: { + type: Boolean, + default: false + }, }, data() { return { - loading:false, - typeSelectOptions:[ - { value: 'object', label: '[object]' }, - { value: 'string', label: '[string]' }, - { value: 'array', label: '[array]' }, + loading: false, + rangeTypeOptions: [ + { + value: "", + label: this.$t("commons.please_select"), + }, + { + value: "value_eq", + label: this.$t("api_test.mock.range_type.value_eq"), + }, + { + value: "value_not_eq", + label: this.$t("api_test.mock.range_type.value_not_eq"), + }, + { + value: "value_contain", + label: this.$t("api_test.mock.range_type.value_contain"), + }, + { + value: "length_eq", + label: this.$t("api_test.mock.range_type.length_eq"), + }, + { + value: "length_not_eq", + label: this.$t("api_test.mock.range_type.length_not_eq"), + }, + { + value: "length_large_than", + label: this.$t("api_test.mock.range_type.length_large_than"), + }, + { + value: "length_shot_than", + label: this.$t("api_test.mock.range_type.length_shot_than"), + }, + { + value: "regular_match", + label: this.$t("api_test.mock.range_type.regular_match"), + }, ], - requiredSelectOptions:[ - { value: true, label: '必填' }, - { value: false, label: '非必填' }, + typeSelectOptions: [ + {value: 'object', label: '[object]'}, + {value: 'string', label: '[string]'}, + {value: 'array', label: '[array]'}, ], - tableExpandRowKayArray:["name","systemName"], + requiredSelectOptions: [ + {value: true, label: '必填'}, + {value: false, label: '非必填'}, + ], + tableExpandRowKayArray: ["name", "systemName"], } }, created() { - if(this.tableData && this.tableData.length>0){ + if (this.tableData && this.tableData.length > 0) { this.tableData.forEach(row => { - if(row.name == null || row.name === ""){ + if (row.name == null || row.name === "") { this.remove(row); } }) } + }, + computed: { + }, methods: { - saveTableData:function(){ - this.$emit('saveTableData',this.tableData); + parseRangeType(type) { + if (!type) { + type = ""; + } + let returnValue = null; + switch (type) { + case "value_eq": + returnValue = this.$t("api_test.mock.range_type.value_eq"); + break; + case "value_not_eq": + returnValue = this.$t("api_test.mock.range_type.value_not_eq"); + break; + case "value_contain": + returnValue = this.$t("api_test.mock.range_type.value_contain"); + break; + case "length_eq": + returnValue = this.$t("api_test.mock.range_type.length_eq"); + break; + case "length_not_eq": + returnValue = this.$t("api_test.mock.range_type.length_not_eq"); + break; + case "length_large_than": + returnValue = this.$t("api_test.mock.range_type.length_large_than"); + break; + case "length_shot_than": + returnValue = this.$t("api_test.mock.range_type.length_shot_than"); + break; + case "regular_match": + returnValue = this.$t("api_test.mock.range_type.regular_match"); + break; + default: + returnValue = ""; + break; + } + return returnValue; + }, + saveTableData: function () { + this.$emit('saveTableData', this.tableData); }, remove: function (row) { this.removeTableRow(row); }, add: function (r) { let row = this.getNewRow(null); - this.pushTableData(row,"root"); + this.pushTableData(row, "root"); }, - nextRow:function (row) { + nextRow: function (row) { //首先保存当前行内容 let confirmRowFlag = this.confirm(row); - if(confirmRowFlag){ + if (confirmRowFlag) { let nextRow = this.getNewRow(null); - this.pushTableData(nextRow,row.uuid); + this.pushTableData(nextRow, row.uuid); } }, //复制当前数据结构 - copyDataStructConfirm:function (row){ + copyDataStructConfirm: function (row) { this.$alert(this.$t('api_test.definition.request.esb_copy_confirm') + " ?", '', { confirmButtonText: this.$t('commons.confirm'), callback: (action) => { @@ -123,21 +223,21 @@ export default { } }); }, - copyDataStruct:function (row){ - let parentRow = this.selectParentRow(this.tableData,row.uuid); + copyDataStruct: function (row) { + let parentRow = this.selectParentRow(this.tableData, row.uuid); let newRow = this.createNewId(row); - if(parentRow!=null){ - if(parentRow.children == null){ - parentRow.children = []; + if (parentRow != null) { + if (parentRow.children == null) { + parentRow.children = []; } parentRow.children.push(newRow); - }else{ - this.$emit('xmlTableDataPushRow',newRow); + } else { + this.$emit('xmlTableDataPushRow', newRow); } }, - createNewId(row){ + createNewId(row) { let newRow = this.getNewRow(row); - if(row.children!=null && row.children.length > 0){ + if (row.children != null && row.children.length > 0) { row.children.forEach(child => { let newChild = this.createNewId(child); newRow.children.push(newChild); @@ -145,24 +245,24 @@ export default { } return newRow; }, - selectParentRow(dataStruct,rowId){ + selectParentRow(dataStruct, rowId) { let returnRow = null; - if(dataStruct == null || dataStruct.length === 0){ + if (dataStruct == null || dataStruct.length === 0) { return returnRow; } - dataStruct.forEach( itemData => { - if(itemData.children != null && itemData.children.length > 0){ - itemData.children.forEach( child => { - if(child.uuid === rowId){ + dataStruct.forEach(itemData => { + if (itemData.children != null && itemData.children.length > 0) { + itemData.children.forEach(child => { + if (child.uuid === rowId) { returnRow = itemData; return returnRow; } }); } - if(returnRow == null ){ - if(itemData.children != null && itemData.children.length > 0){ - returnRow = this.selectParentRow(itemData.children,rowId); - if(returnRow!=null){ + if (returnRow == null) { + if (itemData.children != null && itemData.children.length > 0) { + returnRow = this.selectParentRow(itemData.children, rowId); + if (returnRow != null) { return returnRow; } } @@ -177,13 +277,21 @@ export default { } return false; }, - getNewRow(param){ - if(param == null ){ + getNewRow(param) { + if (param == null) { let row = { - name: '',systemName: '',status: 'edit',type: '[object]',contentType: '',required: false,description: '',uuid: this.uuid(),children: [] + name: '', + systemName: '', + status: 'edit', + type: '[object]', + contentType: '', + required: false, + description: '', + uuid: this.uuid(), + children: [] } return row; - }else{ + } else { let row = { name: param.name, systemName: param.systemName, @@ -199,15 +307,15 @@ export default { } }, validateRowData(row) { - if(row.name == null || row.name === ''){ + if (row.name == null || row.name === '') { // this.$warning(this.$t('load_test.input_ip')); - this.$warning("参数名"+"不能为空,且不能包含英文小数点[.]"); + this.$warning("参数名" + "不能为空,且不能包含英文小数点[.]"); return false; - }else if(row.name.indexOf(".")>0){ - this.$warning("参数名["+row.name+"]不合法,不能包含英文小数点\".\"!"); + } else if (row.name.indexOf(".") > 0) { + this.$warning("参数名[" + row.name + "]不合法,不能包含英文小数点\".\"!"); return false; - }else if(row.type == null || row.type === ''){ - this.$warning("类型"+"不能为空!"); + } else if (row.type == null || row.type === '') { + this.$warning("类型" + "不能为空!"); return false; } return true; @@ -218,48 +326,48 @@ export default { uuid: function () { return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1); }, - pushTableData: function(dataRow,rowId){ - if(rowId === "" || rowId == null){ - if(this.tableData){ + pushTableData: function (dataRow, rowId) { + if (rowId === "" || rowId == null) { + if (this.tableData) { this.$emit("initXmlTableData"); } - this.$emit("xmlTablePushRow",dataRow); - } else if(rowId === "root"){ - this.$emit("xmlTablePushRow",dataRow); - }else { - this.appendDataWithDeepForeach(this.tableData,rowId,dataRow); + this.$emit("xmlTablePushRow", dataRow); + } else if (rowId === "root") { + this.$emit("xmlTablePushRow", dataRow); + } else { + this.appendDataWithDeepForeach(this.tableData, rowId, dataRow); } }, - appendDataWithDeepForeach(datas,rowId,appendData){ - datas.forEach( row => { - if(row.uuid === rowId){ - if(row.children == null){ + appendDataWithDeepForeach(datas, rowId, appendData) { + datas.forEach(row => { + if (row.uuid === rowId) { + if (row.children == null) { row.children = []; } row.children.push(appendData); - }else if(row.children.length>0){ - let appendResult = this.appendDataWithDeepForeach(row.children,rowId,appendData); - if(appendResult){ + } else if (row.children.length > 0) { + let appendResult = this.appendDataWithDeepForeach(row.children, rowId, appendData); + if (appendResult) { return appendResult; } } }); return false; }, - removeTableRow: function (row){ - this.removeFromDataStruct(this.tableData,row); + removeTableRow: function (row) { + this.removeFromDataStruct(this.tableData, row); }, - removeFromDataStruct(dataStruct,row){ - if(dataStruct == null || dataStruct.length === 0){ + removeFromDataStruct(dataStruct, row) { + if (dataStruct == null || dataStruct.length === 0) { return; } let rowIndex = dataStruct.indexOf(row); - if(rowIndex >= 0){ - dataStruct.splice(rowIndex,1); - }else { - dataStruct.forEach( itemData => { - if(itemData.children != null && itemData.children.length > 0){ - this.removeFromDataStruct(itemData.children,row); + if (rowIndex >= 0) { + dataStruct.splice(rowIndex, 1); + } else { + dataStruct.forEach(itemData => { + if (itemData.children != null && itemData.children.length > 0) { + this.removeFromDataStruct(itemData.children, row); } }); } diff --git a/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue b/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue index 74156b5b0d..54dfc17d56 100644 --- a/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue +++ b/frontend/src/business/components/api/definition/components/environment/EnvironmentSelect.vue @@ -106,6 +106,9 @@ }, setEnvironment(enviromentId){ this.currentData.environmentId = enviromentId; + if (this.currentData.request) { + this.currentData.request.useEnvironment = enviromentId; + } } } } diff --git a/frontend/src/business/components/api/definition/components/mock/MockEditDrawer.vue b/frontend/src/business/components/api/definition/components/mock/MockEditDrawer.vue index 19105aeefd..75f16faf0b 100644 --- a/frontend/src/business/components/api/definition/components/mock/MockEditDrawer.vue +++ b/frontend/src/business/components/api/definition/components/mock/MockEditDrawer.vue @@ -16,7 +16,7 @@
{ + let returnData = response.data; + if (returnData) { + requestParam.xmlDataStruct = returnData; + } + this.$emit("redirectToTest", requestParam); + }, error => { + this.$emit("redirectToTest", requestParam); + }); + } + }, + getHttpMockTestData(requestParam) { + if (requestParam && requestParam.params) { let selectParma = []; - if(requestParam.params.arguments && requestParam.params.arguments.length > 0){ + if (requestParam.params.arguments && requestParam.params.arguments.length > 0) { requestParam.params.arguments.forEach(item => { - if(item.rangeType && item.value &&item.uuid){ - let paramObj = {id:item.uuid,value:item.value,condition:item.rangeType}; + if (item.rangeType && item.value && item.uuid) { + let paramObj = {id: item.uuid, value: item.value, condition: item.rangeType}; selectParma.push(paramObj); } }); } - if(requestParam.params.rest && requestParam.params.rest.length > 0){ + if (requestParam.params.rest && requestParam.params.rest.length > 0) { requestParam.params.rest.forEach(item => { - if(item.rangeType && item.value &&item.uuid){ - let paramObj = {id:item.uuid,value:item.value,condition:item.rangeType}; + if (item.rangeType && item.value && item.uuid) { + let paramObj = {id: item.uuid, value: item.value, condition: item.rangeType}; selectParma.push(paramObj); } }); } - if(requestParam.params.body.kvs && requestParam.params.body.kvs.length > 0){ + if (requestParam.params.body.kvs && requestParam.params.body.kvs.length > 0) { requestParam.params.body.kvs.forEach(item => { - if(item.rangeType && item.value &&item.uuid){ - let paramObj = {id:item.uuid,value:item.value,condition:item.rangeType}; + if (item.rangeType && item.value && item.uuid) { + let paramObj = {id: item.uuid, value: item.value, condition: item.rangeType}; selectParma.push(paramObj); } }); @@ -184,25 +207,25 @@ export default { //调用后台生成符合mock需求的测试数据 this.$post("/mockConfig/getMockTestData", selectParma, response => { let returnData = response.data; - if(returnData && returnData.length > 0){ + if (returnData && returnData.length > 0) { returnData.forEach(data => { - if(requestParam.params.arguments && requestParam.params.arguments.length > 0){ - for(let i = 0; i < requestParam.params.arguments.length; i++){ - if(requestParam.params.arguments[i].uuid === data.id){ + if (requestParam.params.arguments && requestParam.params.arguments.length > 0) { + for (let i = 0; i < requestParam.params.arguments.length; i++) { + if (requestParam.params.arguments[i].uuid === data.id) { requestParam.params.arguments[i].value = data.value; } } } - if(requestParam.params.rest && requestParam.params.rest.length > 0){ - for(let i = 0; i < requestParam.params.rest.length; i++){ - if(requestParam.params.rest[i].uuid === data.id){ + if (requestParam.params.rest && requestParam.params.rest.length > 0) { + for (let i = 0; i < requestParam.params.rest.length; i++) { + if (requestParam.params.rest[i].uuid === data.id) { requestParam.params.rest[i].value = data.value; } } } - if(requestParam.params.body.kvs && requestParam.params.body.kvs.length > 0){ - for(let i = 0; i < requestParam.params.body.kvs.length; i++){ - if(requestParam.params.body.kvs[i].uuid === data.id){ + if (requestParam.params.body.kvs && requestParam.params.body.kvs.length > 0) { + for (let i = 0; i < requestParam.params.body.kvs.length; i++) { + if (requestParam.params.body.kvs[i].uuid === data.id) { requestParam.params.body.kvs[i].value = data.value; } } diff --git a/frontend/src/business/components/api/definition/components/request/tcp/TcpParams.vue b/frontend/src/business/components/api/definition/components/request/tcp/TcpParams.vue index d91c5fa296..9aff405340 100644 --- a/frontend/src/business/components/api/definition/components/request/tcp/TcpParams.vue +++ b/frontend/src/business/components/api/definition/components/request/tcp/TcpParams.vue @@ -13,7 +13,7 @@
- @@ -74,6 +74,10 @@ export default { type: Boolean, default: false }, + showOperationCol: { + type: Boolean, + default: false + }, showScript: { type: Boolean, default: true, @@ -167,6 +171,11 @@ export default { }); } }, + saveData(){ + if(this.request && this.request.reportType === 'xml' && this.$refs.treeTable){ + this.$refs.treeTable.saveTableData(); + } + }, checkXmlTableDataStructData(dataStruct){ let allCheckResult = true; if(this.$refs.treeTable){