refactor(接口测试): 场景列表补充按照环境筛选功能

--bug=1017922 --user=赵勇 【接口测试】接口自动化场景列表的运行环境不可筛选-接口case列表运行环境可以筛选 https://www.tapd.cn/55049933/s/1260705
This commit is contained in:
fit2-zhao 2022-10-13 16:56:44 +08:00 committed by fit2-zhao
parent b60b9c3b04
commit 04daa53a00
16 changed files with 50 additions and 39 deletions

View File

@ -448,7 +448,7 @@ public class ElementUtil {
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(finalEnvironmentMap.get(projectId)); ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(finalEnvironmentMap.get(projectId));
if (environment != null && environment.getConfig() != null) { if (environment != null && environment.getConfig() != null) {
EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
env.setApiEnvironmentid(environment.getId()); env.setEnvironmentId(environment.getId());
envConfig.put(projectId, env); envConfig.put(projectId, env);
} }
}); });

View File

@ -243,7 +243,7 @@ public class MsScenario extends MsTestElement {
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(this.environmentMap.get(projectId)); ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(this.environmentMap.get(projectId));
if (environment != null && environment.getConfig() != null) { if (environment != null && environment.getConfig() != null) {
EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
env.setApiEnvironmentid(environment.getId()); env.setEnvironmentId(environment.getId());
envConfig.put(projectId, env); envConfig.put(projectId, env);
if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) {
this.setMockEnvironment(true); this.setMockEnvironment(true);
@ -261,7 +261,7 @@ public class MsScenario extends MsTestElement {
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentMap.get(projectId)); ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentMap.get(projectId));
if (environment != null && StringUtils.isNotEmpty(environment.getConfig())) { if (environment != null && StringUtils.isNotEmpty(environment.getConfig())) {
EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
env.setApiEnvironmentid(environment.getId()); env.setEnvironmentId(environment.getId());
envConfig.put(projectId, env); envConfig.put(projectId, env);
if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) { if (StringUtils.equals(environment.getName(), MockConfigStaticData.MOCK_EVN_NAME)) {
this.setMockEnvironment(true); this.setMockEnvironment(true);

View File

@ -36,13 +36,13 @@ public class MsJSR223Processor extends MsTestElement {
if (StringUtils.isEmpty(this.getEnvironmentId())) { if (StringUtils.isEmpty(this.getEnvironmentId())) {
if (config.getConfig() != null) { if (config.getConfig() != null) {
if (config.getProjectId() != null) { if (config.getProjectId() != null) {
String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId();
this.setEnvironmentId(evnId); this.setEnvironmentId(evnId);
} else { } else {
Collection<EnvironmentConfig> evnConfigList = config.getConfig().values(); Collection<EnvironmentConfig> evnConfigList = config.getConfig().values();
if (evnConfigList != null && !evnConfigList.isEmpty()) { if (evnConfigList != null && !evnConfigList.isEmpty()) {
for (EnvironmentConfig configItem : evnConfigList) { for (EnvironmentConfig configItem : evnConfigList) {
String evnId = configItem.getApiEnvironmentid(); String evnId = configItem.getEnvironmentId();
this.setEnvironmentId(evnId); this.setEnvironmentId(evnId);
break; break;
} }

View File

@ -118,8 +118,8 @@ public class MsJDBCPostProcessor extends MsTestElement {
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs()) if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) { && isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())) { if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) {
this.environmentId = environmentConfig.getApiEnvironmentid(); this.environmentId = environmentConfig.getEnvironmentId();
} }
this.initDataSource(); this.initDataSource();
} else { } else {

View File

@ -34,13 +34,13 @@ public class MsJSR223PostProcessor extends MsTestElement {
if (StringUtils.isEmpty(this.getEnvironmentId())) { if (StringUtils.isEmpty(this.getEnvironmentId())) {
if (config.getConfig() != null) { if (config.getConfig() != null) {
if (config.getProjectId() != null && config.getConfig().containsKey(config.getProjectId())) { 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); this.setEnvironmentId(evnId);
} else { } else {
Collection<EnvironmentConfig> evnConfigList = config.getConfig().values(); Collection<EnvironmentConfig> evnConfigList = config.getConfig().values();
if (evnConfigList != null && !evnConfigList.isEmpty()) { if (evnConfigList != null && !evnConfigList.isEmpty()) {
for (EnvironmentConfig configItem : evnConfigList) { for (EnvironmentConfig configItem : evnConfigList) {
String evnId = configItem.getApiEnvironmentid(); String evnId = configItem.getEnvironmentId();
this.setEnvironmentId(evnId); this.setEnvironmentId(evnId);
break; break;
} }

View File

@ -107,8 +107,8 @@ public class MsJDBCPreProcessor extends MsTestElement {
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs()) if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) { && isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())) { if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) {
this.environmentId = environmentConfig.getApiEnvironmentid(); this.environmentId = environmentConfig.getEnvironmentId();
} }
this.initDataSource(); this.initDataSource();
} else { } else {

View File

@ -39,13 +39,13 @@ public class MsJSR223PreProcessor extends MsTestElement {
if (StringUtils.isEmpty(this.getEnvironmentId())) { if (StringUtils.isEmpty(this.getEnvironmentId())) {
if (config.getConfig() != null) { if (config.getConfig() != null) {
if (config.getProjectId() != null) { if (config.getProjectId() != null) {
String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); String evnId = config.getConfig().get(config.getProjectId()).getEnvironmentId();
this.setEnvironmentId(evnId); this.setEnvironmentId(evnId);
} else { } else {
Collection<EnvironmentConfig> evnConfigList = config.getConfig().values(); Collection<EnvironmentConfig> evnConfigList = config.getConfig().values();
if (evnConfigList != null && !evnConfigList.isEmpty()) { if (evnConfigList != null && !evnConfigList.isEmpty()) {
for (EnvironmentConfig configItem : evnConfigList) { for (EnvironmentConfig configItem : evnConfigList) {
String evnId = configItem.getApiEnvironmentid(); String evnId = configItem.getEnvironmentId();
this.setEnvironmentId(evnId); this.setEnvironmentId(evnId);
break; break;
} }

View File

@ -110,7 +110,7 @@ public class MsDubboSampler extends MsTestElement {
String environmentId = this.getEnvironmentId(); String environmentId = this.getEnvironmentId();
if (environmentId == null) { if (environmentId == null) {
if (StringUtils.isEmpty(this.useEnvironment) && envConfig != null) { if (StringUtils.isEmpty(this.useEnvironment) && envConfig != null) {
environmentId = envConfig.getApiEnvironmentid(); environmentId = envConfig.getEnvironmentId();
} else { } else {
environmentId = this.useEnvironment; environmentId = this.useEnvironment;
} }

View File

@ -276,7 +276,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
private void initConnectAndResponseTimeout(ParameterConfig config) { private void initConnectAndResponseTimeout(ParameterConfig config) {
if (config.isEffective(this.getProjectId())) { 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())) { if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) {
this.setEnvironmentId(useEvnId); this.setEnvironmentId(useEvnId);
} }
@ -304,7 +304,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
if (config.isEffective(this.getProjectId())) { if (config.isEffective(this.getProjectId())) {
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
if (environmentConfig != null) { if (environmentConfig != null) {
String useEvnId = environmentConfig.getApiEnvironmentid(); String useEvnId = environmentConfig.getEnvironmentId();
if (this.authManager == null && environmentConfig.getAuthManager() != null && environmentConfig.getAuthManager().getAuthManager() != null) { if (this.authManager == null && environmentConfig.getAuthManager() != null && environmentConfig.getAuthManager().getAuthManager() != null) {
this.authManager = environmentConfig.getAuthManager().getAuthManager(); this.authManager = environmentConfig.getAuthManager().getAuthManager();
} }
@ -335,7 +335,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
MSException.throwException(this.getName() + "接口,对应的环境无协议,请完善环境信息"); MSException.throwException(this.getName() + "接口,对应的环境无协议,请完善环境信息");
} }
if (StringUtils.isEmpty(this.useEnvironment)) { 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(); String url = httpConfig.getProtocol() + "://" + httpConfig.getSocket();
if (isUrl()) { if (isUrl()) {

View File

@ -115,8 +115,8 @@ public class MsJDBCSampler extends MsTestElement {
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs()) if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) { && isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId()); EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())) { if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getEnvironmentId())) {
this.environmentId = environmentConfig.getApiEnvironmentid(); this.environmentId = environmentConfig.getEnvironmentId();
} }
this.dataSource = null; this.dataSource = null;
envConfig = this.initDataSource(); envConfig = this.initDataSource();

View File

@ -15,7 +15,7 @@ import java.util.List;
@Data @Data
public class EnvironmentConfig { public class EnvironmentConfig {
private String apiEnvironmentid; private String environmentId;
private CommonConfig commonConfig; private CommonConfig commonConfig;
private HttpConfig httpConfig; private HttpConfig httpConfig;
private List<DatabaseConfig> databaseConfigs; private List<DatabaseConfig> databaseConfigs;

View File

@ -179,7 +179,7 @@ public class ApiExecuteService {
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(map.get(key)); ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(map.get(key));
if (environment != null) { if (environment != null) {
EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
env.setApiEnvironmentid(environment.getId()); env.setEnvironmentId(environment.getId());
envConfig.put(key, env); envConfig.put(key, env);
} }
} }
@ -268,7 +268,7 @@ public class ApiExecuteService {
Map<String, EnvironmentConfig> envConfig = new HashMap<>(16); Map<String, EnvironmentConfig> envConfig = new HashMap<>(16);
if (environment != null && environment.getConfig() != null) { if (environment != null && environment.getConfig() != null) {
EnvironmentConfig environmentConfig = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); EnvironmentConfig environmentConfig = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
environmentConfig.setApiEnvironmentid(environment.getId()); environmentConfig.setEnvironmentId(environment.getId());
envConfig.put(testCaseWithBLOBs.getProjectId(), environmentConfig); envConfig.put(testCaseWithBLOBs.getProjectId(), environmentConfig);
parameterConfig.setConfig(envConfig); parameterConfig.setConfig(envConfig);
} }

View File

@ -437,7 +437,7 @@ public class ApiScenarioEnvService {
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentMap.get(projectId)); ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentService.get(environmentMap.get(projectId));
if (environment != null && environment.getConfig() != null) { if (environment != null && environment.getConfig() != null) {
EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class); EnvironmentConfig env = JSONUtil.parseObject(environment.getConfig(), EnvironmentConfig.class);
env.setApiEnvironmentid(environment.getId()); env.setEnvironmentId(environment.getId());
envConfig.put(projectId, env); envConfig.put(projectId, env);
} }
}); });

View File

@ -392,6 +392,14 @@
#{value} #{value}
</foreach> </foreach>
</when> </when>
<when test="key=='environment_map'">
and api_scenario.environment_json REGEXP CONCAT_WS('|',
<foreach collection="values" item="item" open="" close="" separator=",">
#{item}
</foreach>
)
</when>
</choose> </choose>
</if> </if>
</foreach> </foreach>

View File

@ -154,6 +154,7 @@
<ms-table-column <ms-table-column
:field="item" :field="item"
:fields-width="fieldsWidth" :fields-width="fieldsWidth"
:filters="environmentsFilters"
prop="environmentMap" prop="environmentMap"
:label="$t('commons.environment')" :label="$t('commons.environment')"
min-width="180"> min-width="180">
@ -375,6 +376,7 @@ import {getEnvironmentByProjectId} from "metersphere-frontend/src/api/environmen
import {REPORT_STATUS} from "@/business/commons/js/commons"; import {REPORT_STATUS} from "@/business/commons/js/commons";
import {usePerformanceStore} from "@/store"; import {usePerformanceStore} from "@/store";
import {request} from "metersphere-frontend/src/plugins/request" import {request} from "metersphere-frontend/src/plugins/request"
import {parseEnvironment} from "@/business/environment/model/EnvironmentModel";
const performanceStore = usePerformanceStore(); const performanceStore = usePerformanceStore();
export default { export default {
@ -454,6 +456,7 @@ export default {
}, },
data() { data() {
return { return {
environmentsFilters: [],
projectName: "", projectName: "",
result: false, result: false,
tableHeaderKey: "API_SCENARIO", tableHeaderKey: "API_SCENARIO",
@ -464,6 +467,7 @@ export default {
condition: { condition: {
components: this.trashEnable ? API_SCENARIO_CONFIGS_TRASH : API_SCENARIO_CONFIGS components: this.trashEnable ? API_SCENARIO_CONFIGS_TRASH : API_SCENARIO_CONFIGS
}, },
projectId: "",
scenarioId: "", scenarioId: "",
isMoveBatch: true, isMoveBatch: true,
currentScenario: {}, currentScenario: {},
@ -636,7 +640,7 @@ export default {
this.getProjectName(); this.getProjectName();
} }
this.condition.filters = {status: ["Prepare", "Underway", "Completed"]}; this.condition.filters = {status: ["Prepare", "Underway", "Completed"]};
this.initEnvironment();
if (this.trashEnable) { if (this.trashEnable) {
this.condition.filters = {status: ["Trash"]}; this.condition.filters = {status: ["Trash"]};
this.condition.moduleIds = []; this.condition.moduleIds = [];
@ -738,9 +742,18 @@ export default {
} }
}); });
}, },
selectByParam() { initEnvironment() {
this.changeSelectDataRangeAll(); if (this.projectId) {
this.search(); 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) { search(projectId) {
if (this.needRefreshModule()) { 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() { cancel() {
this.planVisible = false; this.planVisible = false;
}, },

View File

@ -1,7 +1,7 @@
<template> <template>
<ms-container> <ms-container>
<ms-aside-container :height="'calc(100vh - 90px)'"> <ms-aside-container :height="'calc(100vh - 90px)'">
<div @click="showAll"> <div @click="showAll" style="overflow-x: hidden">
<div class="tip">{{ $t('test_track.plan_view.base_info') }}</div> <div class="tip">{{ $t('test_track.plan_view.base_info') }}</div>
<el-form :model="currentScenario" label-position="right" label-width="80px" size="small" :rules="rules" <el-form :model="currentScenario" label-position="right" label-width="80px" size="small" :rules="rules"
ref="currentScenario"> ref="currentScenario">