fix(测试跟踪): 修复测试计划切换环境,接口用例切换数据源失败的缺陷 (#17924)
--bug=1016635 --user=王孝刚 【测试跟踪】github#17753,接口场景切换环境后,SQL请求的数据源切换正常,但加入到测试计划后,数据源切换异常 https://www.tapd.cn/55049933/s/1243915 Co-authored-by: wxg0103 <727495428@qq.com>
This commit is contained in:
parent
45e8b3cd3c
commit
6c58415e7b
|
@ -12,6 +12,7 @@ import io.metersphere.api.dto.definition.request.controller.MsLoopController;
|
|||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
|
||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||
|
@ -785,4 +786,29 @@ public class ElementUtil {
|
|||
return evlValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static DatabaseConfig dataSource(String projectId, String dataSourceId, EnvironmentConfig envConfig) {
|
||||
try {
|
||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
List<ApiTestEnvironmentWithBLOBs> environment = environmentService.list(projectId);
|
||||
EnvironmentConfig dataConfig = null;
|
||||
List<String> dataName = new ArrayList<>();
|
||||
List<ApiTestEnvironmentWithBLOBs> orgDataSource = environment.stream().filter(ApiTestEnvironmentWithBLOBs -> ApiTestEnvironmentWithBLOBs.getConfig().contains(dataSourceId)).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(orgDataSource)) {
|
||||
dataConfig = JSONObject.parseObject(orgDataSource.get(0).getConfig(), EnvironmentConfig.class);
|
||||
if (CollectionUtils.isNotEmpty(dataConfig.getDatabaseConfigs())) {
|
||||
dataName = dataConfig.getDatabaseConfigs().stream().filter(DatabaseConfig -> DatabaseConfig.getId().equals(dataSourceId)).map(DatabaseConfig::getName).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
List<String> finalDataName = dataName;
|
||||
List<DatabaseConfig> collect = envConfig.getDatabaseConfigs().stream().filter(DatabaseConfig -> DatabaseConfig.getName().equals(finalDataName.get(0))).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(collect)) {
|
||||
return collect.get(0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -126,7 +126,12 @@ public class MsJDBCPostProcessor extends MsTestElement {
|
|||
} else {
|
||||
// 取当前环境下默认的一个数据源
|
||||
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
||||
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
||||
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
|
||||
if (dataSourceOrg != null) {
|
||||
this.dataSource = dataSourceOrg;
|
||||
} else {
|
||||
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,12 @@ public class MsJDBCPreProcessor extends MsTestElement {
|
|||
} else {
|
||||
// 取当前环境下默认的一个数据源
|
||||
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
|
||||
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
||||
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
|
||||
if (dataSourceOrg != null) {
|
||||
this.dataSource = dataSourceOrg;
|
||||
} else {
|
||||
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,10 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
if (config.isEffective(this.getProjectId())) {
|
||||
if (config.getConfig().get(this.getProjectId()) != null) {
|
||||
envConfig = config.getConfig().get(this.getProjectId());
|
||||
if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) {
|
||||
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, envConfig);
|
||||
if (dataSourceOrg != null) {
|
||||
this.dataSource = dataSourceOrg;
|
||||
} else {
|
||||
this.dataSource = envConfig.getDatabaseConfigs().get(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,11 @@ export default {
|
|||
let newEnvironment = {};
|
||||
newEnvironment = new Environment(environment);
|
||||
newEnvironment.id = null;
|
||||
newEnvironment.config.databaseConfigs.forEach(dataSource => {
|
||||
if (dataSource.id) {
|
||||
dataSource.id = getUUID();
|
||||
}
|
||||
})
|
||||
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
|
||||
if (!this.validateEnvironment(newEnvironment)) {
|
||||
return;
|
||||
|
|
|
@ -116,6 +116,11 @@ export default {
|
|||
let newEnvironment = {};
|
||||
newEnvironment = new Environment(environment);
|
||||
newEnvironment.id = null;
|
||||
newEnvironment.config.databaseConfigs.forEach(dataSource => {
|
||||
if (dataSource.id) {
|
||||
dataSource.id = getUUID();
|
||||
}
|
||||
})
|
||||
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
|
||||
if (!this.validateEnvironment(newEnvironment)) {
|
||||
return;
|
||||
|
|
|
@ -32,7 +32,9 @@
|
|||
<el-table-column :label="$t('api_test.environment.socket')" show-overflow-tooltip>
|
||||
<template v-slot="scope">
|
||||
<span v-if="parseDomainName(scope.row)!='SHOW_INFO'">{{ parseDomainName(scope.row) }}</span>
|
||||
<el-button size="mini" icon="el-icon-s-data" @click="showInfo(scope.row)" v-else>{{ $t('workspace.env_group.view_details') }}</el-button>
|
||||
<el-button v-else icon="el-icon-s-data" size="mini" @click="showInfo(scope.row)">
|
||||
{{ $t('workspace.env_group.view_details') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.operating')">
|
||||
|
@ -94,12 +96,14 @@
|
|||
{{ row.conditionType ? "-" : getDetails(row) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="description" show-overflow-tooltip min-width="120px" :label="$t('commons.description')">
|
||||
<el-table-column :label="$t('commons.description')" min-width="120px" prop="description"
|
||||
show-overflow-tooltip>
|
||||
<template v-slot:default="{row}">
|
||||
<span>{{ row.description ? row.description : "-" }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createTime" show-overflow-tooltip min-width="120px" :label="$t('commons.create_time')">
|
||||
<el-table-column :label="$t('commons.create_time')" min-width="120px" prop="createTime"
|
||||
show-overflow-tooltip>
|
||||
<template v-slot:default="{row}">
|
||||
<span v-if="!row.conditionType">{{ row.time | timestampFormatDate }}</span>
|
||||
<span v-else>-</span>
|
||||
|
@ -193,7 +197,7 @@ export default {
|
|||
}
|
||||
this.domainVisible = true;
|
||||
},
|
||||
save(){
|
||||
save() {
|
||||
this.$refs.environmentEdit.save();
|
||||
},
|
||||
getName(row) {
|
||||
|
@ -288,6 +292,11 @@ export default {
|
|||
parseEnvironment(temEnv); //parseEnvironment会改变环境对象的内部结构,从而影响前端列表的显示,所以复制一个环境对象作为代替
|
||||
let newEnvironment = new Environment(temEnv);
|
||||
newEnvironment.id = null;
|
||||
newEnvironment.config.databaseConfigs.forEach(dataSource => {
|
||||
if (dataSource.id) {
|
||||
dataSource.id = getUUID();
|
||||
}
|
||||
})
|
||||
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
|
||||
this.dialogVisible = true;
|
||||
this.currentEnvironment = newEnvironment;
|
||||
|
|
|
@ -38,7 +38,9 @@
|
|||
<el-table-column :label="$t('api_test.environment.socket')" show-overflow-tooltip>
|
||||
<template v-slot="scope">
|
||||
<span v-if="parseDomainName(scope.row)!='SHOW_INFO'">{{ parseDomainName(scope.row) }}</span>
|
||||
<el-button size="mini" icon="el-icon-s-data" @click="showInfo(scope.row)" v-else>{{ $t('workspace.env_group.view_details') }}</el-button>
|
||||
<el-button v-else icon="el-icon-s-data" size="mini" @click="showInfo(scope.row)">
|
||||
{{ $t('workspace.env_group.view_details') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.operating')">
|
||||
|
@ -323,7 +325,7 @@ export default {
|
|||
this.dialogVisible = true;
|
||||
this.ifCreate = false;
|
||||
},
|
||||
save(){
|
||||
save() {
|
||||
this.$refs.environmentEdit.save();
|
||||
},
|
||||
copyEnv(environment) {
|
||||
|
@ -334,6 +336,11 @@ export default {
|
|||
parseEnvironment(temEnv); //parseEnvironment会改变环境对象的内部结构,从而影响前端列表的显示,所以复制一个环境对象作为代替
|
||||
let newEnvironment = new Environment(temEnv);
|
||||
newEnvironment.id = null;
|
||||
newEnvironment.config.databaseConfigs.forEach(dataSource => {
|
||||
if (dataSource.id) {
|
||||
dataSource.id = getUUID();
|
||||
}
|
||||
})
|
||||
newEnvironment.name = this.getNoRepeatName(newEnvironment.name);
|
||||
this.dialogVisible = true;
|
||||
this.currentEnvironment = newEnvironment;
|
||||
|
@ -464,7 +471,7 @@ export default {
|
|||
this.selectRow.forEach(row => {
|
||||
map.set(row.projectId, row.id);
|
||||
})
|
||||
this.$post("/environment/group/batch/add", {map: strMapToObj(map), groupIds:value}, () => {
|
||||
this.$post("/environment/group/batch/add", {map: strMapToObj(map), groupIds: value}, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.getEnvironments();
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue