refactor(接口测试): 优化sql请求校验数据源为空的逻辑

This commit is contained in:
wxg0103 2023-03-29 14:37:04 +08:00 committed by fit2-zhao
parent c726bc2425
commit d63e74b224
12 changed files with 31 additions and 10 deletions

View File

@ -770,6 +770,9 @@ public class ElementUtil {
public static DatabaseConfig dataSource(String projectId, String dataSourceId, EnvironmentConfig envConfig) {
try {
if (StringUtils.isBlank(dataSourceId)) {
return null;
}
BaseEnvironmentService environmentService = CommonBeanFactory.getBean(BaseEnvironmentService.class);
List<ApiTestEnvironmentWithBLOBs> environment = environmentService.list(projectId);
EnvironmentConfig dataConfig = null;

View File

@ -9,9 +9,11 @@ import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.commons.constants.ElementConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.JSONUtil;
import io.metersphere.commons.vo.JDBCProcessorVO;
import io.metersphere.plugin.core.MsParameter;
import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.utils.LoggerUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
@ -67,13 +69,16 @@ public class MsJDBCPostProcessor extends MsTestElement {
this.environmentId = environmentConfig.getEnvironmentId();
}
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
LoggerUtil.info(this.getName() + ":自选数据源结束 查找结果:" + (this.dataSource == null));
} else {
// 取当前环境下默认的一个数据源
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
LoggerUtil.info(this.getName() + ":开始获取当前环境下默认数据源");
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
if (dataSourceOrg != null) {
this.dataSource = dataSourceOrg;
} else {
LoggerUtil.info(this.getName() + ":获取当前环境下默认数据源结束!未查找到默认数据源");
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
}
}
@ -84,6 +89,7 @@ public class MsJDBCPostProcessor extends MsTestElement {
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
}
if (this.dataSource == null) {
LoggerUtil.info(this.getName() + " 当前项目id", this.getProjectId() + " 当前环境配置信息", JSONUtil.toJSONString(config));
String message = "数据源为空请选择数据源";
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "" + message : message);
}

View File

@ -10,9 +10,11 @@ import io.metersphere.commons.constants.ElementConstants;
import io.metersphere.commons.constants.RequestTypeConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.JSONUtil;
import io.metersphere.commons.vo.JDBCProcessorVO;
import io.metersphere.plugin.core.MsParameter;
import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.utils.LoggerUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
@ -67,13 +69,16 @@ public class MsJDBCPreProcessor extends MsTestElement {
this.environmentId = environmentConfig.getEnvironmentId();
}
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
LoggerUtil.info(this.getName() + ":自选数据源结束 查找结果:" + (this.dataSource == null));
} else {
// 取当前环境下默认的一个数据源
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
LoggerUtil.info(this.getName() + ":开始获取当前环境下默认数据源");
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, config.getConfig().get(this.getProjectId()));
if (dataSourceOrg != null) {
this.dataSource = dataSourceOrg;
} else {
LoggerUtil.info(this.getName() + ":获取当前环境下默认数据源结束!未查找到默认数据源");
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
}
}
@ -84,6 +89,7 @@ public class MsJDBCPreProcessor extends MsTestElement {
this.dataSource = ElementUtil.initDataSource(this.environmentId, this.dataSourceId);
}
if (this.dataSource == null) {
LoggerUtil.info(this.getName() + " 当前项目id", this.getProjectId() + " 当前环境配置信息", JSONUtil.toJSONString(config));
String message = "数据源为空请选择数据源";
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "" + message : message);
}

View File

@ -92,16 +92,20 @@ public class MsJDBCSampler extends MsTestElement {
}
this.dataSource = null;
envConfig = this.initDataSource();
LoggerUtil.info(this.getName() + ":自选数据源结束 查找结果:" + (this.dataSource == null));
} else {
// 取当前环境下默认的一个数据源
if (config.isEffective(this.getProjectId())) {
if (config.getConfig().get(this.getProjectId()) != null) {
envConfig = config.getConfig().get(this.getProjectId());
if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) {
LoggerUtil.info(this.getName() + ":开始获取当前环境下默认数据源");
DatabaseConfig dataSourceOrg = ElementUtil.dataSource(getProjectId(), dataSourceId, envConfig);
if (dataSourceOrg != null) {
this.dataSource = dataSourceOrg;
} else {
LoggerUtil.info(this.getName() + ":获取当前环境下默认数据源结束!未查找到默认数据源");
this.dataSource = envConfig.getDatabaseConfigs().get(0);
}
}
@ -110,6 +114,7 @@ public class MsJDBCSampler extends MsTestElement {
}
}
if (this.dataSource == null) {
LoggerUtil.info(this.getName() + " 当前项目id", this.getProjectId() + " 当前环境配置信息", JSONUtil.toJSONString(config));
String message = "数据源为空请选择数据源";
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "" + message : message);
}

View File

@ -417,12 +417,13 @@ public class ApiDefinitionImportUtilService {
//这样的过滤规则下可能存在重复接口如果是覆盖模块需要按照去重规则再次去重否则就加上接口原有的模块
if (fullCoverage) {
removeHttpChooseModuleRepeat(optionData, chooseModulePath);
// optionData = singleOptionData;
// optionMap = optionData.stream().collect(Collectors.toMap(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(chooseModulePath), api -> api));
}
}
getUrlRepeatOptionMap(optionData, optionMap);
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName().concat(t.getMethod()).concat(t.getPath()).concat(t.getModulePath())));
repeatDataMap = repeatApiDefinitionWithBLOBs.stream().collect(Collectors.groupingBy(t -> t.getName()
.concat(t.getMethod())
.concat(t.getPath())
.concat(StringUtils.isNotBlank(t.getModulePath()) ? t.getModulePath() : "/未规划用例")));
Map<String, List<ApiTestCaseWithBLOBs>> oldCaseMap = new HashMap<>();
//重复接口的case
if (CollectionUtils.isNotEmpty(repeatApiDefinitionWithBLOBs)) {

View File

@ -70,7 +70,7 @@ export default {
removeGoBackListener(this.handleClose);
},
confirm() {
let params = this.parameters.split('\n');
let params = this.parameters.split(/[(\r\n)\r\n]+/);
let index = 1;
let isNormal = true;
let msg = '';

View File

@ -15,7 +15,7 @@ export default {
methods: {
batchSave(data) {
if (data) {
let params = data.split('\n');
let params = data.split(/[(\r\n)\r\n]+/);
let keyValues = [];
params.forEach((item) => {
let line = item.split(/:|/);

View File

@ -599,7 +599,7 @@ export default {
},
batchSave(data) {
if (data) {
let params = data.split('\n');
let params = data.split(/[(\r\n)\r\n]+/);
let keyValues = [];
params.forEach((item) => {
let line = item.split(/|,/);

View File

@ -60,7 +60,7 @@ export default {
removeGoBackListener(this.handleClose);
},
confirm() {
let params = this.parameters.split("\n");
let params = this.parameters.split(/[(\r\n)\r\n]+/);
let index = 1;
let isNormal = true;
params.forEach(item => {

View File

@ -265,7 +265,7 @@ export default {
},
batchSave(data) {
if (data) {
let params = data.split("\n");
let params = data.split(/[(\r\n)\r\n]+/);
let keyValues = [];
params.forEach(item => {
if (item) {

View File

@ -60,7 +60,7 @@ export default {
removeGoBackListener(this.handleClose);
},
confirm() {
let params = this.parameters.split("\n");
let params = this.parameters.split(/[(\r\n)\r\n]+/);
let index = 1;
let isNormal = true;
params.forEach(item => {

View File

@ -448,7 +448,7 @@ export default {
this.$refs.batchAdd.open();
},
_handleBatchVars(data) {
let params = data.split("\n");
let params = data.split(/[(\r\n)\r\n]+/);
let keyValues = [];
params.forEach(item => {
if (item) {