From 91ded7f5ba90f1a8728f5debd86b76c2cecac94d Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 20 Jan 2021 14:53:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E5=8F=A6=E5=AD=98=E6=96=B0=E7=94=A8=E4=BE=8B=20TAG=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/extract/MsExtractCommon.java | 2 +- .../api/service/ApiTestCaseService.java | 25 ++++++++-- .../components/case/ApiCaseList.vue | 47 ++++++++++--------- .../components/list/ApiCaseSimpleList.vue | 13 ----- 4 files changed, 47 insertions(+), 40 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java index 3ac9f8a662..767a295102 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/extract/MsExtractCommon.java @@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils; @Data public class MsExtractCommon extends MsExtractType{ private String variable; - private String value; // value: ${variable} + private String value; private String expression; private String description; private boolean multipleMatching; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 29b18207bc..88fa857651 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -417,19 +417,34 @@ public class ApiTestCaseService { List bloBs = apiTestCaseMapper.selectByExampleWithBLOBs(apiDefinitionExample); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class); + + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); bloBs.forEach(apiTestCase -> { MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class); - if (StringUtils.isNotEmpty(request.getMethod())) { - req.setMethod(request.getMethod()); - } - if (StringUtils.isNotEmpty(request.getPath())) { - req.setPath(request.getPath()); + try { + JSONObject element = JSON.parseObject(apiTestCase.getRequest()); + if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) { + LinkedList elements = mapper.readValue(element.getString("hashTree"), new TypeReference>() { + }); + req.setHashTree(elements); + } + if (StringUtils.isNotEmpty(request.getMethod())) { + req.setMethod(request.getMethod()); + } + if (StringUtils.isNotEmpty(request.getPath())) { + req.setPath(request.getPath()); + } + } catch (Exception e) { + e.printStackTrace(); + LogUtil.error(e.getMessage()); } String requestStr = JSON.toJSONString(req); apiTestCase.setRequest(requestStr); batchMapper.updateByPrimaryKeySelective(apiTestCase); }); sqlSession.flushStatements(); + } } diff --git a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue index e72997102d..55cfccbcfe 100644 --- a/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue +++ b/frontend/src/business/components/api/definition/components/case/ApiCaseList.vue @@ -86,7 +86,7 @@ singleLoading: false, singleRunId: "", runData: [], - batchData: [], + selectdCases: [], reportId: "", projectId: "", testCaseId: "", @@ -128,8 +128,6 @@ this.projectId = getCurrentProjectID(); if (this.createCase) { this.sysAddition(); - } else { - this.getApiTest(); } }, computed: { @@ -153,11 +151,19 @@ this.condition.projectId = this.projectId; this.condition.apiDefinitionId = this.api.id; this.$post("/api/testcase/list", this.condition, response => { - for (let index in response.data) { - let test = response.data[index]; - test.request = JSON.parse(test.request); - } this.apiCaseList = response.data; + this.apiCaseList.forEach(apiCase => { + if (apiCase.tags && apiCase.tags.length > 0) { + apiCase.tags = JSON.parse(apiCase.tags); + this.$set(apiCase, 'selected', false); + } + if (Object.prototype.toString.call(apiCase.request).match(/\[object (\w+)\]/)[1].toLowerCase() != 'object') { + apiCase.request = JSON.parse(apiCase.request); + } + if (!apiCase.request.hashTree) { + apiCase.request.hashTree = []; + } + }) this.addCase(); }); }, @@ -200,24 +206,22 @@ this.condition.apiDefinitionId = this.api.id; } this.result = this.$post("/api/testcase/list", this.condition, response => { - for (let index in response.data) { - let test = response.data[index]; - test.request = JSON.parse(test.request); - if (!test.request.hashTree) { - test.request.hashTree = []; - } - } this.apiCaseList = response.data; - if (addCase && this.apiCaseList.length == 0 && !this.loaded) { - this.addCase(); - } this.apiCaseList.forEach(apiCase => { if (apiCase.tags && apiCase.tags.length > 0) { apiCase.tags = JSON.parse(apiCase.tags); this.$set(apiCase, 'selected', false); } + if (Object.prototype.toString.call(apiCase.request).match(/\[object (\w+)\]/)[1].toLowerCase() != 'object') { + apiCase.request = JSON.parse(apiCase.request); + } + if (!apiCase.request.hashTree) { + apiCase.request.hashTree = []; + } }) - + if (addCase && this.apiCaseList.length == 0 && !this.loaded) { + this.addCase(); + } }); } }, @@ -293,11 +297,11 @@ if (this.apiCaseList.length > 0) { this.apiCaseList.forEach(item => { if (item.selected && item.id) { - this.batchData.push(item.id); + this.selectdCases.push(item.id); } }) } - if (this.batchData.length == 0) { + if (this.selectdCases.length == 0) { this.$warning("请选择用例!"); return; } @@ -306,7 +310,7 @@ batchEdit(form) { let param = {}; param[form.type] = form.value; - param.ids = this.batchData; + param.ids = this.selectdCases; param.projectId = getCurrentProjectID(); if (this.api) { param.protocol = this.api.protocol; @@ -316,6 +320,7 @@ param = Object.assign(param, this.condition); this.$post('/api/testcase/batch/editByParam', param, () => { this.$success(this.$t('commons.save_success')); + this.selectdCases = []; this.getApiTest(); }); }, diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index 951cb2fad4..5b72cf06d5 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -413,19 +413,6 @@ this.initTable(); }); return; - // } - // this.$alert(this.$t('api_test.definition.request.delete_confirm') + ' ' + apiCase.name + " ?", '', { - // confirmButtonText: this.$t('commons.confirm'), - // callback: (action) => { - // if (action === 'confirm') { - // let ids = [apiCase.id]; - // this.$post('/api/testcase/removeToGc/', ids, () => { - // this.$success(this.$t('commons.delete_success')); - // this.initTable(); - // }); - // } - // } - // }); }, setEnvironment(data) { this.environmentId = data.id;