From d71bf052ceadfd1569185bdf6753c1d03191681f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 1 Apr 2022 14:25:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DJDBC=E8=AF=B7=E6=B1=82=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E6=89=80=E5=B1=9E=E7=8E=AF=E5=A2=83=E6=9C=AA=E9=9A=8F=E5=85=AC?= =?UTF-8?q?=E5=85=B1=E7=8E=AF=E5=A2=83=E5=8F=98=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1011789 --user=赵勇 【接口测试】场景-引用场景为sql接口-更换运行环境-调试-返回结果后查看数据源名称-仍显示之前的数据源源名称 https://www.tapd.cn/55049933/s/1128715 --- .../api/exec/api/ApiCaseExecuteService.java | 9 +- .../api/service/ApiScenarioReportService.java | 5 +- .../api/service/MsHashTreeService.java | 9 +- .../automation/scenario/EditApiScenario.vue | 5 - .../scenario/component/ApiComponent.vue | 133 +---- .../request/database/BasisParameters.vue | 469 +++++++++--------- 6 files changed, 257 insertions(+), 373 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java index 398433a376..8965f08bc2 100644 --- a/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java +++ b/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseExecuteService.java @@ -178,6 +178,7 @@ public class ApiCaseExecuteService { } } } + /** * 接口定义case执行 * @@ -199,6 +200,8 @@ public class ApiCaseExecuteService { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiTestCaseMapper.selectIdsByQuery((ApiTestCaseRequest) query)); + List responseDTOS = new LinkedList<>(); + ApiTestCaseExample example = new ApiTestCaseExample(); example.createCriteria().andIdIn(request.getIds()); List caseList = apiTestCaseMapper.selectByExampleWithBLOBs(example); @@ -222,6 +225,7 @@ public class ApiCaseExecuteService { apiScenarioReportStructureService.save(serialReportId, new ArrayList<>()); apiCaseResultService.batchSave(executeQueue); + responseDTOS.add(new MsExecResponseDTO(JSON.toJSONString(request.getIds()), report.getId(), request.getTriggerMode())); } if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) { @@ -238,7 +242,6 @@ public class ApiCaseExecuteService { request.setTriggerMode(ApiRunMode.DEFINITION.name()); } - List responseDTOS = new LinkedList<>(); Map executeQueue = new LinkedHashMap<>(); String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name(); @@ -254,7 +257,9 @@ public class ApiCaseExecuteService { report.setIntegratedReportId(serialReportId); } executeQueue.put(caseWithBLOBs.getId(), report); - responseDTOS.add(new MsExecResponseDTO(caseWithBLOBs.getId(), report.getId(), request.getTriggerMode())); + if (!StringUtils.equals(request.getConfig().getReportType(), RunModeConstants.SET_REPORT.toString())) { + responseDTOS.add(new MsExecResponseDTO(caseWithBLOBs.getId(), report.getId(), request.getTriggerMode())); + } } apiCaseResultService.batchSave(executeQueue); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 0003e4e7f2..5289fa4323 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -349,6 +349,7 @@ public class ApiScenarioReportService { execResultExample.createCriteria().andIntegratedReportIdEqualTo(reportId).andStatusEqualTo("Error"); long size = definitionExecResultMapper.countByExample(execResultExample); result.setStatus(size > 0 ? ScenarioStatus.Error.name() : ScenarioStatus.Success.name()); + result.setEndTime(System.currentTimeMillis()); definitionExecResultMapper.updateByPrimaryKeySelective(result); } else { ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId); @@ -385,9 +386,9 @@ public class ApiScenarioReportService { } long successSize = requestResults.stream().filter(requestResult -> StringUtils.equalsIgnoreCase(requestResult.getStatus(), ScenarioStatus.Success.name())).count(); - if(requestResults.size() == 0){ + if (requestResults.size() == 0) { scenario.setPassRate("0%"); - }else { + } else { scenario.setPassRate(new DecimalFormat("0%").format((float) successSize / requestResults.size())); } diff --git a/backend/src/main/java/io/metersphere/api/service/MsHashTreeService.java b/backend/src/main/java/io/metersphere/api/service/MsHashTreeService.java index 47b1adb5c1..46d183f1c4 100644 --- a/backend/src/main/java/io/metersphere/api/service/MsHashTreeService.java +++ b/backend/src/main/java/io/metersphere/api/service/MsHashTreeService.java @@ -58,6 +58,8 @@ public class MsHashTreeService { private static final String BODY = "body"; private static final String ARGUMENTS = "arguments"; private static final String AUTH_MANAGER = "authManager"; + private static final String PROJECT_ID = "projectId"; + private static final String ACTIVE = "active"; public void setHashTree(JSONArray hashTree) { // 将引用转成复制 @@ -187,11 +189,12 @@ public class MsHashTreeService { element.put(REST, refElement.get(REST)); element.put(PATH, refElement.get(PATH)); element.put(BODY, refElement.get(BODY)); - element.put("active", false); + element.put(ACTIVE, false); element.put(AUTH_MANAGER, refElement.get(AUTH_MANAGER)); element.put(ARGUMENTS, refElement.get(ARGUMENTS)); + element.put(PROJECT_ID, apiTestCase.getProjectId()); if (array != null) { - JSONArray sourceHashTree = element.getJSONArray("hashTree"); + JSONArray sourceHashTree = element.getJSONArray(HASH_TREE); Map> groupMap = ElementUtil.group(sourceHashTree); Map> targetGroupMap = ElementUtil.group(refElement.getJSONArray(HASH_TREE)); @@ -208,7 +211,7 @@ public class MsHashTreeService { if (CollectionUtils.isNotEmpty(rules)) { step.addAll(rules); } - element.put("hashTree", step); + element.put(HASH_TREE, step); } element.put(REFERENCED, REF); element.put(DISABLED, true); diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 38c57871ff..cd2e911425 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -734,11 +734,6 @@ export default { this.getEnvDomain(data.hashTree, domainMap); this.margeDomain(this.scenarioDefinition, domainMap); this.cancelBatchProcessing(); - if (this.$store.state.currentApiCase) { - this.$store.state.currentApiCase.resetDataSource = getUUID(); - } else { - this.$store.state.currentApiCase = {resetDataSource: getUUID()}; - } } } }) diff --git a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue index 4913828b10..e0643328f5 100644 --- a/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue +++ b/frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue @@ -270,32 +270,16 @@ export default { if (requireComponent != null && JSON.stringify(esbDefinition) != '{}' && JSON.stringify(esbDefinitionResponse) != '{}') { this.showXpackCompnent = true; } - this.getEnvironments(this.environmentGroupId); }, watch: { - envMap(val) { - this.getEnvironments(); - this.environmentMap = val; - }, message() { this.forStatus(); this.reload(); }, - environmentGroupId(val) { - this.getEnvironments(val); - }, - environmentType(val) { - this.envType = val; - }, '$store.state.currentApiCase.debugLoop'() { this.forStatus(); this.reload(); }, - '$store.state.currentApiCase.resetDataSource'() { - if (this.request.id && this.request.referenced !== 'REF') { - this.initDataSource(); - } - }, }, computed: { displayColor() { @@ -391,50 +375,7 @@ export default { this.response = this.request.requestResult[0]; } }, - initDataSource() { - let databaseConfigsOptions = []; - if (this.request.protocol === 'SQL' || this.request.type === 'JDBCSampler') { - if (this.environment && this.environment.config) { - let config = JSON.parse(this.environment.config); - if (config && config.databaseConfigs) { - config.databaseConfigs.forEach(item => { - databaseConfigsOptions.push(item); - }); - } - } - } - if (databaseConfigsOptions.length > 0 && this.request.environmentId !== this.environment.id) { - this.request.dataSourceId = databaseConfigsOptions[0].id; - this.request.environmentId = this.environment.id; - } - }, - getEnvironments(groupId) { - this.environment = {}; - let id = undefined; - if (groupId) { - this.$get("/environment/group/project/map/" + groupId, res => { - let data = res.data; - if (data) { - this.environmentMap = new Map(Object.entries(data)); - id = new Map(Object.entries(data)).get(this.request.projectId); - if (id) { - this.$get('/api/environment/get/' + id, response => { - this.environment = response.data; - this.initDataSource(); - }); - } - } - }) - } else { - id = this.envMap.get(this.request.projectId); - if (id) { - this.$get('/api/environment/get/' + id, response => { - this.environment = response.data; - this.initDataSource(); - }); - } - } - }, + remove() { this.$emit('remove', this.request, this.node); }, @@ -454,78 +395,6 @@ export default { } } }, - getApiInfo() { - if (this.request.id && this.request.referenced === 'REF') { - let requestResult = this.request.requestResult; - let enable = this.request.enable; - this.$get("/api/testcase/get/" + this.request.id, response => { - if (response.data) { - let hashTree = []; - if (this.request.hashTree) { - hashTree = JSON.parse(JSON.stringify(this.request.hashTree)); - } - Object.assign(this.request, JSON.parse(response.data.request)); - this.request.name = response.data.name; - this.request.referenced = "REF"; - this.request.enable = enable; - if (response.data.path && response.data.path != null) { - this.request.path = response.data.path; - this.request.url = response.data.url; - } - if (response.data.method && response.data.method != null) { - this.request.method = response.data.method; - } - if (requestResult && Object.prototype.toString.call(requestResult) !== '[object Array]') { - this.request.requestResult = [requestResult]; - } else { - this.request.requestResult = requestResult; - } - if (response.data.num) { - this.request.num = response.data.num; - } - this.request.id = response.data.id; - this.request.disabled = true; - this.request.root = true; - this.request.projectId = response.data.projectId; - this.request.versionName = response.data.versionName; - this.request.versionEnable = response.data.versionEnable; - let req = JSON.parse(response.data.request); - if (req && this.request) { - this.request.hashTree = hashTree; - this.mergeHashTree(req.hashTree); - } - this.initDataSource(); - this.forStatus(); - this.sort(); - this.reload(); - } - }) - } else if (this.request.id && this.request.referenced === 'Copy') { - if (this.request.refType === 'CASE') { - this.$get("/api/testcase/get/" + this.request.id, response => { - if (response.data) { - if (response.data.num) { - this.request.num = response.data.num; - } - this.request.id = response.data.id; - this.request.versionName = response.data.versionName; - this.request.versionEnable = response.data.versionEnable; - } - }) - } else if (this.request.refType === 'API') { - this.$get("/api/definition/get/" + this.request.id, response => { - if (response.data) { - if (response.data.num) { - this.request.num = response.data.num; - } - this.request.id = response.data.id; - this.request.versionName = response.data.versionName; - this.request.versionEnable = response.data.versionEnable; - } - }) - } - } - }, mergeHashTree(targetHashTree) { let sourceHashTree = this.request.hashTree; // 历史数据兼容 diff --git a/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue b/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue index ca18998cec..974b51ec5a 100644 --- a/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue +++ b/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue @@ -108,252 +108,263 @@