fix(接口测试): 修复jdbc类型请求切换数据源问题

--bug=1013318 --user=赵勇 【接口测试】场景中-请求中添加前后置sql-多个数据源切换数据源后-单独调试结果是旧数据源 https://www.tapd.cn/55049933/s/1162419
This commit is contained in:
fit2-zhao 2022-05-23 18:17:24 +08:00 committed by f2c-ci-robot[bot]
parent 64ed38e326
commit 19c11b1a62
2 changed files with 89 additions and 1 deletions

View File

@ -39,7 +39,7 @@ public class MsJSR223PostProcessor extends MsTestElement {
ParameterConfig config = (ParameterConfig) msParameter; ParameterConfig config = (ParameterConfig) msParameter;
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 && config.getConfig().containsKey(config.getProjectId())) {
String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid(); String evnId = config.getConfig().get(config.getProjectId()).getApiEnvironmentid();
this.setEnvironmentId(evnId); this.setEnvironmentId(evnId);
} else { } else {

View File

@ -580,6 +580,7 @@ export default {
this.getWsProjects(); this.getWsProjects();
this.getMaintainerOptions(); this.getMaintainerOptions();
this.getApiScenario(); this.getApiScenario();
this.getEnvironments();
this.buttonData = buttons(this); this.buttonData = buttons(this);
this.getPlugins().then(() => { this.getPlugins().then(() => {
this.initPlugins(); this.initPlugins();
@ -1847,6 +1848,93 @@ export default {
}); });
this.$store.state.scenarioEnvMap = map; this.$store.state.scenarioEnvMap = map;
this.setDomain(true); this.setDomain(true);
this.setStep(this.scenarioDefinition);
},
setStep(stepArray){
for (let i in stepArray) {
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
if(typeArray.indexOf(stepArray[i].type) !==-1) {
this.setStepEnv(stepArray[i]);
}
if (stepArray[i].hashTree && stepArray[i].hashTree.length > 0) {
this.setStep(stepArray[i].hashTree);
}
}
},
setStepEnv(request) {
let envId = "";
let projectId = request.projectId ? request.projectId : this.projectId;
if (this.projectEnvMap.has(projectId)) {
envId = this.projectEnvMap.get(projectId);
}
//
if (request.environmentEnable && request.refEevMap) {
let obj = Object.prototype.toString.call(request.refEevMap).match(/\[object (\w+)\]/)[1].toLowerCase();
if (obj !== 'object' && obj !== "map") {
request.refEevMap = objToStrMap(JSON.parse(request.refEevMap));
} else if (obj === 'object' && obj !== "map") {
request.refEevMap = objToStrMap(request.refEevMap);
}
if (request.refEevMap instanceof Map && request.refEevMap.has(projectId)) {
envId = request.refEevMap.get(projectId);
}
}
if(envId === request.originalEnvironmentId && request.originalDataSourceId) {
request.dataSourceId = request.originalDataSourceId;
}
let targetDataSourceName = "";
let currentEnvironment = {};
this.environments.forEach(environment => {
//
if (environment.id === request.environmentId && environment.id !== envId) {
if (environment.config && environment.config.databaseConfigs) {
environment.config.databaseConfigs.forEach(item => {
if (item.id === request.dataSourceId) {
targetDataSourceName = item.name;
}
});
}
}
if (envId && environment.id === envId) {
currentEnvironment = environment;
}
});
this.initDataSource(envId, currentEnvironment, targetDataSourceName,request);
},
initDataSource(envId, currentEnvironment, targetDataSourceName,request) {
this.databaseConfigsOptions = [];
if (envId) {
request.environmentId = envId;
} else {
for (let i in this.environments) {
if (this.environments[i].id === request.environmentId) {
currentEnvironment = this.environments[i];
break;
}
}
}
let flag = false;
if (currentEnvironment && currentEnvironment.config && currentEnvironment.config.databaseConfigs) {
currentEnvironment.config.databaseConfigs.forEach(item => {
if (item.id === request.dataSourceId) {
flag = true;
}
//
else if (targetDataSourceName && item.name === targetDataSourceName) {
request.dataSourceId = item.id;
flag = true;
}
this.databaseConfigsOptions.push(item);
});
if (!flag && currentEnvironment.config.databaseConfigs.length > 0) {
request.dataSourceId = currentEnvironment.config.databaseConfigs[0].id;
flag = true;
}
}
if (!flag) {
request.dataSourceId = "";
}
}, },
setEnvGroup(id) { setEnvGroup(id) {
this.envGroupId = id; this.envGroupId = id;