From 04daa53a0046081490aa1b30472a8eae078d7811 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 13 Oct 2022 16:56:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=9C=BA=E6=99=AF=E5=88=97=E8=A1=A8=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E6=8C=89=E7=85=A7=E7=8E=AF=E5=A2=83=E7=AD=9B=E9=80=89=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1017922 --user=赵勇 【接口测试】接口自动化场景列表的运行环境不可筛选-接口case列表运行环境可以筛选 https://www.tapd.cn/55049933/s/1260705 --- .../dto/definition/request/ElementUtil.java | 2 +- .../dto/definition/request/MsScenario.java | 4 +-- .../request/processors/MsJSR223Processor.java | 4 +-- .../processors/post/MsJDBCPostProcessor.java | 4 +-- .../post/MsJSR223PostProcessor.java | 4 +-- .../processors/pre/MsJDBCPreProcessor.java | 4 +-- .../processors/pre/MsJSR223PreProcessor.java | 4 +-- .../request/sampler/MsDubboSampler.java | 2 +- .../request/sampler/MsHTTPSamplerProxy.java | 8 ++--- .../request/sampler/MsJDBCSampler.java | 4 +-- .../environment/EnvironmentConfig.java | 2 +- .../api/exec/api/ApiExecuteService.java | 4 +-- .../exec/scenario/ApiScenarioEnvService.java | 2 +- .../base/mapper/ext/ExtApiScenarioMapper.xml | 8 +++++ .../automation/scenario/ApiScenarioList.vue | 31 ++++++++++--------- .../automation/scenario/EditApiScenario.vue | 2 +- 16 files changed, 50 insertions(+), 39 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index c94c1d191a..4489642a11 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -448,7 +448,7 @@ public class ElementUtil { ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(finalEnvironmentMap.get(projectId)); if (environment != null && environment.getConfig() != null) { EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); - env.setApiEnvironmentid(environment.getId()); + env.setEnvironmentId(environment.getId()); envConfig.put(projectId, env); } }); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java index 563a9698a3..366ef8147e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/MsScenario.java @@ -243,7 +243,7 @@ public class MsScenario extends MsTestElement { ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(this.environmentMap.get(projectId)); if (environment != null && environment.getConfig() != null) { EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); - env.setApiEnvironmentid(environment.getId()); + env.setEnvironmentId(environment.getId()); envConfig.put(projectId, env); if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { this.setMockEnvironment(true); @@ -261,7 +261,7 @@ public class MsScenario extends MsTestElement { ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentMap.get(projectId)); if (environment != null && StringUtils.isNotEmpty(environment.getConfig())) { EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); - env.setApiEnvironmentid(environment.getId()); + env.setEnvironmentId(environment.getId()); envConfig.put(projectId, env); if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { this.setMockEnvironment(true); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java index 10f80278de..c818294dbb 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java @@ -36,13 +36,13 @@ public class MsJSR223Processor extends MsTestElement { if (StringUtils.isEmpty(this.getEnvironmentId())) { if (config.getConfig() != null) { if (config.getProjectId() != null) { - String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); + String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId(); this.setEnvironmentId(evnId); } else { Collection evnConfigList = config.getConfig().values(); if (evnConfigList != null && !evnConfigList.isEmpty()) { for (EnvironmentConfig configItem : evnConfigList) { - String evnId = configItem.getApiEnvironmentid(); + String evnId = configItem.getEnvironmentId(); this.setEnvironmentId(evnId); break; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java index 2b36019bf9..38f4fffc86 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java @@ -118,8 +118,8 @@ public class MsJDBCPostProcessor extends MsTestElement { if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs()) && isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) { EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); - if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())) { - this.environmentId = environmentConfig.getApiEnvironmentid(); + if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) { + this.environmentId = environmentConfig.getEnvironmentId(); } this.initDataSource(); } else { diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java index 134c895430..1aa6c47a5b 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java @@ -34,13 +34,13 @@ public class MsJSR223PostProcessor extends MsTestElement { if (StringUtils.isEmpty(this.getEnvironmentId())) { if (config.getConfig() != null) { if (config.getProjectId() != null && config.getConfig().containsKey(config.getProjectId())) { - String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); + String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId(); this.setEnvironmentId(evnId); } else { Collection evnConfigList = config.getConfig().values(); if (evnConfigList != null && !evnConfigList.isEmpty()) { for (EnvironmentConfig configItem : evnConfigList) { - String evnId = configItem.getApiEnvironmentid(); + String evnId = configItem.getEnvironmentId(); this.setEnvironmentId(evnId); break; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java index c6e0c37874..c8595c36a9 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java @@ -107,8 +107,8 @@ public class MsJDBCPreProcessor extends MsTestElement { if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs()) && isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) { EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); - if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())) { - this.environmentId = environmentConfig.getApiEnvironmentid(); + if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) { + this.environmentId = environmentConfig.getEnvironmentId(); } this.initDataSource(); } else { diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java index e8ae3ab888..566dcfbbbb 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java @@ -39,13 +39,13 @@ public class MsJSR223PreProcessor extends MsTestElement { if (StringUtils.isEmpty(this.getEnvironmentId())) { if (config.getConfig() != null) { if (config.getProjectId() != null) { - String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); + String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId(); this.setEnvironmentId(evnId); } else { Collection evnConfigList = config.getConfig().values(); if (evnConfigList != null && !evnConfigList.isEmpty()) { for (EnvironmentConfig configItem : evnConfigList) { - String evnId = configItem.getApiEnvironmentid(); + String evnId = configItem.getEnvironmentId(); this.setEnvironmentId(evnId); break; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java index 4947dd77bc..9781f78e1f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java @@ -110,7 +110,7 @@ public class MsDubboSampler extends MsTestElement { String environmentId = this.getEnvironmentId(); if (environmentId == null) { if (StringUtils.isEmpty(this.useEnvironment) && envConfig != null) { - environmentId = envConfig.getApiEnvironmentid(); + environmentId = envConfig.getEnvironmentId(); } else { environmentId = this.useEnvironment; } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 1703ae649d..181ce02503 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -276,7 +276,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { private void initConnectAndResponseTimeout(ParameterConfig config) { if (config.isEffective(this.getProjectId())) { - String useEvnId = config.getConfig().get(this.getProjectId()).getApiEnvironmentid(); + String useEvnId = config.getConfig().get(this.getProjectId()).getEnvironmentId(); if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) { this.setEnvironmentId(useEvnId); } @@ -304,7 +304,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { if (config.isEffective(this.getProjectId())) { EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); if (environmentConfig != null) { - String useEvnId = environmentConfig.getApiEnvironmentid(); + String useEvnId = environmentConfig.getEnvironmentId(); if (this.authManager == null && environmentConfig.getAuthManager() != null && environmentConfig.getAuthManager().getAuthManager() != null) { this.authManager = environmentConfig.getAuthManager().getAuthManager(); } @@ -335,7 +335,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { MSException.throwException(this.getName() + "接口,对应的环境无协议,请完善环境信息"); } if (StringUtils.isEmpty(this.useEnvironment)) { - this.useEnvironment = config.getConfig().get(this.getProjectId()).getApiEnvironmentid(); + this.useEnvironment = config.getConfig().get(this.getProjectId()).getEnvironmentId(); } String url = httpConfig.getProtocol() + "://" + httpConfig.getSocket(); if (isUrl()) { @@ -679,4 +679,4 @@ public class MsHTTPSamplerProxy extends MsTestElement { public static List findHttpSampleFromHashTree(MsTestElement hashTree) { return ElementUtil.findFromHashTreeByType(hashTree, MsHTTPSamplerProxy.class, null); } -} +} \ No newline at end of file diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index d10aeb90c7..e1f5e85a33 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -115,8 +115,8 @@ public class MsJDBCSampler extends MsTestElement { if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs()) && isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) { EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); - if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())) { - this.environmentId = environmentConfig.getApiEnvironmentid(); + if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) { + this.environmentId = environmentConfig.getEnvironmentId(); } this.dataSource = null; envConfig = this.initDataSource(); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java index 233fd5bfbd..f15f1784ca 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java @@ -15,7 +15,7 @@ import java.util.List; @Data public class EnvironmentConfig { - private String apiEnvironmentid; + private String environmentId; private CommonConfig commonConfig; private HttpConfig httpConfig; private List databaseConfigs; diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java index 0a8175a494..f431a589d6 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java @@ -179,7 +179,7 @@ public class ApiExecuteService { ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(map.get(key)); if (environment != null) { EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); - env.setApiEnvironmentid(environment.getId()); + env.setEnvironmentId(environment.getId()); envConfig.put(key, env); } } @@ -268,7 +268,7 @@ public class ApiExecuteService { Map envConfig = new HashMap<>(16); if (environment != null && environment.getConfig() != null) { EnvironmentConfig environmentConfig = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); - environmentConfig.setApiEnvironmentid(environment.getId()); + environmentConfig.setEnvironmentId(environment.getId()); envConfig.put(testCaseWithBLOBs.getProjectId(), environmentConfig); parameterConfig.setConfig(envConfig); } diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java index d97e2c8bf1..eed23dd67c 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java @@ -437,7 +437,7 @@ public class ApiScenarioEnvService { ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentMap.get(projectId)); if (environment != null && environment.getConfig() != null) { EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); - env.setApiEnvironmentid(environment.getId()); + env.setEnvironmentId(environment.getId()); envConfig.put(projectId, env); } }); diff --git a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index 51af2ec8cf..8e195c3123 100644 --- a/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/api-test/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -392,6 +392,14 @@ #{value} + + + and api_scenario.environment_json REGEXP CONCAT_WS('|', + + #{item} + + ) + diff --git a/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue b/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue index a9e2c8cd52..7bdf367820 100644 --- a/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue +++ b/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue @@ -154,6 +154,7 @@ @@ -375,6 +376,7 @@ import {getEnvironmentByProjectId} from "metersphere-frontend/src/api/environmen import {REPORT_STATUS} from "@/business/commons/js/commons"; import {usePerformanceStore} from "@/store"; import {request} from "metersphere-frontend/src/plugins/request" +import {parseEnvironment} from "@/business/environment/model/EnvironmentModel"; const performanceStore = usePerformanceStore(); export default { @@ -454,6 +456,7 @@ export default { }, data() { return { + environmentsFilters: [], projectName: "", result: false, tableHeaderKey: "API_SCENARIO", @@ -464,6 +467,7 @@ export default { condition: { components: this.trashEnable ? API_SCENARIO_CONFIGS_TRASH : API_SCENARIO_CONFIGS }, + projectId: "", scenarioId: "", isMoveBatch: true, currentScenario: {}, @@ -636,7 +640,7 @@ export default { this.getProjectName(); } this.condition.filters = {status: ["Prepare", "Underway", "Completed"]}; - + this.initEnvironment(); if (this.trashEnable) { this.condition.filters = {status: ["Trash"]}; this.condition.moduleIds = []; @@ -738,9 +742,18 @@ export default { } }); }, - selectByParam() { - this.changeSelectDataRangeAll(); - this.search(); + initEnvironment() { + if (this.projectId) { + getEnvironmentByProjectId(this.projectId).then(response => { + this.environments = response.data; + this.environments.forEach(environment => { + parseEnvironment(environment); + }); + this.environmentsFilters = response.data.map(u => { + return {text: u.name, value: u.id}; + }); + }); + } }, search(projectId) { if (this.needRefreshModule()) { @@ -945,16 +958,6 @@ export default { }); } }, - getEnvsOptions(option) { - getEnvironmentByProjectId(this.projectId).then(response => { - option.push(...response.data); - option.forEach(environment => { - if (!(environment.config instanceof Object)) { - environment.config = JSON.parse(environment.config); - } - }); - }); - }, cancel() { this.planVisible = false; }, diff --git a/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue b/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue index 98b15072ff..c0dda85536 100644 --- a/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue +++ b/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue @@ -1,7 +1,7 @@