fix(接口测试): 修复jdbc请求执行环境切换问题

https://www.tapd.cn/55049933/s/1127130
This commit is contained in:
fit2-zhao 2022-04-06 15:47:55 +08:00 committed by fit2-zhao
parent db46056049
commit b8cbee5615
8 changed files with 57 additions and 62 deletions

View File

@ -92,10 +92,6 @@ public class MsJDBCPostProcessor extends MsTestElement {
// 数据兼容处理 // 数据兼容处理
if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) { if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) {
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
if(environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())){
this.environmentId = environmentConfig.getApiEnvironmentid();
}
// 1.8 之后 当前正常数据 // 1.8 之后 当前正常数据
} else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) { } else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 前后 混合数据 // 1.8 前后 混合数据
@ -119,6 +115,10 @@ 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());
if (environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())) {
this.environmentId = environmentConfig.getApiEnvironmentid();
}
this.initDataSource(); this.initDataSource();
} else { } else {
// 取当前环境下默认的一个数据源 // 取当前环境下默认的一个数据源

View File

@ -92,10 +92,6 @@ public class MsJDBCPreProcessor extends MsTestElement {
// 数据兼容处理 // 数据兼容处理
if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) { if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) {
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
if(environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())){
this.environmentId = environmentConfig.getApiEnvironmentid();
}
// 1.8 之后 当前正常数据 // 1.8 之后 当前正常数据
} else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) { } else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 前后 混合数据 // 1.8 前后 混合数据
@ -119,6 +115,10 @@ 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());
if(environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())){
this.environmentId = environmentConfig.getApiEnvironmentid();
}
this.initDataSource(); this.initDataSource();
} else { } else {
// 取当前环境下默认的一个数据源 // 取当前环境下默认的一个数据源

View File

@ -102,10 +102,6 @@ public class MsJDBCSampler extends MsTestElement {
// 数据兼容处理 // 数据兼容处理
if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) { if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) {
EnvironmentConfig environmentConfig = config.getConfig().get(this.getProjectId());
if(environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())){
this.environmentId = environmentConfig.getApiEnvironmentid();
}
// 1.8 之后 当前正常数据 // 1.8 之后 当前正常数据
} else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) { } else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 前后 混合数据 // 1.8 前后 混合数据
@ -128,6 +124,10 @@ 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());
if(environmentConfig.getDatabaseConfigs() != null && StringUtils.isNotEmpty(environmentConfig.getApiEnvironmentid())){
this.environmentId = environmentConfig.getApiEnvironmentid();
}
this.dataSource = null; this.dataSource = null;
envConfig = this.initDataSource(); envConfig = this.initDataSource();
} else { } else {

View File

@ -127,6 +127,14 @@ export default {
return getCurrentProjectID(); return getCurrentProjectID();
}, },
}, },
watch: {
'$store.state.scenarioEnvMap': {
handler(v) {
this.getEnvironments();
},
deep: true
}
},
methods: { methods: {
remove(row) { remove(row) {
let index = this.request.hashTree.indexOf(row); let index = this.request.hashTree.indexOf(row);
@ -167,38 +175,30 @@ export default {
this.environments.forEach(environment => { this.environments.forEach(environment => {
parseEnvironment(environment); parseEnvironment(environment);
}); });
let hasEnvironment = false; let envId = "";
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map) {
if (this.$store.state.scenarioEnvMap.has(this.projectId) &&
this.$store.state.scenarioEnvMap.get(this.projectId) === this.request.environmentId) {
hasEnvironment = true;
}
} else {
hasEnvironment = true;
}
break;
}
}
if (!hasEnvironment) {
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has(this.projectId)) { && this.$store.state.scenarioEnvMap.has(this.projectId)) {
this.request.environmentId = this.$store.state.scenarioEnvMap.get(this.projectId); envId = this.$store.state.scenarioEnvMap.get(this.projectId);
} }
} this.initDataSource(envId);
if (!this.request.environmentId) {
this.request.dataSourceId = undefined;
}
this.initDataSource();
}); });
}, },
openEnvironmentConfig() { openEnvironmentConfig() {
this.$refs.environmentConfig.open(getCurrentProjectID()); this.$refs.environmentConfig.open(getCurrentProjectID());
}, },
initDataSource() { initDataSource(envId) {
let flag = false; let flag = false;
let environment = {}; let environment = {};
if (envId) {
for (let i in this.environments) {
if (this.environments[i].id === envId && this.environments[i].config && this.environments[i].config.databaseConfigs
&& this.environments[i].config.databaseConfigs.length > 0) {
this.request.environmentId = envId;
this.request.dataSourceId = this.environments[i].config.databaseConfigs[0].id;
}
}
}
for (let i in this.environments) { for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) { if (this.environments[i].id === this.request.environmentId) {
environment = this.environments[i]; environment = this.environments[i];

View File

@ -43,6 +43,7 @@ import MsTag from "../../../../common/components/MsTag";
import MsEnvironmentSelect from "./MsEnvironmentSelect"; import MsEnvironmentSelect from "./MsEnvironmentSelect";
import {API_METHOD_COLOUR} from "../../model/JsonData"; import {API_METHOD_COLOUR} from "../../model/JsonData";
import ApiCaseItem from "@/business/components/api/definition/components/case/ApiCaseItem"; import ApiCaseItem from "@/business/components/api/definition/components/case/ApiCaseItem";
import {getCurrentProjectID} from "@/common/js/utils";
export default { export default {
name: "ApiCaseHeader", name: "ApiCaseHeader",
@ -99,6 +100,8 @@ export default {
setEnvironment(data) { setEnvironment(data) {
if (data) { if (data) {
this.$emit('setEnvironment', data.id); this.$emit('setEnvironment', data.id);
this.$store.state.scenarioEnvMap = new Map();
this.$store.state.scenarioEnvMap.set(getCurrentProjectID(), data.id);
} }
}, },
open() { open() {

View File

@ -262,6 +262,7 @@ export default {
maintainerOptions: Array, maintainerOptions: Array,
}, },
created() { created() {
this.$store.state.scenarioEnvMap = undefined;
if (requireComponent != null && JSON.stringify(esbDefinition) != '{}' && JSON.stringify(esbDefinitionResponse) != '{}') { if (requireComponent != null && JSON.stringify(esbDefinition) != '{}' && JSON.stringify(esbDefinitionResponse) != '{}') {
this.isXpack = true; this.isXpack = true;
} }

View File

@ -365,6 +365,7 @@ export default {
uuid: newUuid, uuid: newUuid,
caseStatus: "Underway" caseStatus: "Underway"
}; };
request.projectId = getCurrentProjectID();
obj.request = request; obj.request = request;
this.apiCaseList.unshift(obj); this.apiCaseList.unshift(obj);
} }

View File

@ -114,8 +114,6 @@ import MsApiExtract from "../../extract/ApiExtract";
import ApiRequestMethodSelect from "../../collapse/ApiRequestMethodSelect"; import ApiRequestMethodSelect from "../../collapse/ApiRequestMethodSelect";
import MsCodeEdit from "../../../../../common/components/MsCodeEdit"; import MsCodeEdit from "../../../../../common/components/MsCodeEdit";
import MsApiScenarioVariables from "../../ApiScenarioVariables"; import MsApiScenarioVariables from "../../ApiScenarioVariables";
import {createComponent} from "../../jmeter/components";
import {Assertions, Extract} from "../../../model/ApiTestModel";
import {parseEnvironment} from "../../../model/EnvironmentModel"; import {parseEnvironment} from "../../../model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig"; import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
import {getCurrentProjectID} from "@/common/js/utils"; import {getCurrentProjectID} from "@/common/js/utils";
@ -251,38 +249,30 @@ export default {
this.environments.forEach(environment => { this.environments.forEach(environment => {
parseEnvironment(environment); parseEnvironment(environment);
}); });
let hasEnvironment = false; let envId = "";
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map) {
if (this.$store.state.scenarioEnvMap.has(this.projectId) &&
this.$store.state.scenarioEnvMap.get(this.projectId) === this.request.environmentId) {
hasEnvironment = true;
}
} else {
hasEnvironment = true;
}
break;
}
}
if (!hasEnvironment) {
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has(this.projectId)) { && this.$store.state.scenarioEnvMap.has(this.projectId)) {
this.request.environmentId = this.$store.state.scenarioEnvMap.get(this.projectId); envId = this.$store.state.scenarioEnvMap.get(this.projectId);
} }
} this.initDataSource(envId);
if (!this.request.environmentId) {
this.request.dataSourceId = undefined;
}
this.initDataSource();
}); });
}, },
openEnvironmentConfig() { openEnvironmentConfig() {
this.$refs.environmentConfig.open(getCurrentProjectID()); this.$refs.environmentConfig.open(getCurrentProjectID());
}, },
initDataSource() { initDataSource(envId) {
let flag = false; let flag = false;
let environment = {}; let environment = {};
if (envId) {
for (let i in this.environments) {
if (this.environments[i].id === envId && this.environments[i].config && this.environments[i].config.databaseConfigs
&& this.environments[i].config.databaseConfigs.length > 0) {
this.request.environmentId = envId;
this.request.dataSourceId = this.environments[i].config.databaseConfigs[0].id;
}
}
}
for (let i in this.environments) { for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) { if (this.environments[i].id === this.request.environmentId) {
environment = this.environments[i]; environment = this.environments[i];