fix(接口测试): 修复JDBC请求步骤所属环境未随公共环境变动问题

--bug=1011789 --user=赵勇 【接口测试】场景-引用场景为sql接口-更换运行环境-调试-返回结果后查看数据源名称-仍显示之前的数据源源名称 https://www.tapd.cn/55049933/s/1128715
This commit is contained in:
fit2-zhao 2022-04-01 14:25:05 +08:00 committed by fit2-zhao
parent f3e7897915
commit d71bf052ce
6 changed files with 257 additions and 373 deletions

View File

@ -178,6 +178,7 @@ public class ApiCaseExecuteService {
}
}
}
/**
* 接口定义case执行
*
@ -199,6 +200,8 @@ public class ApiCaseExecuteService {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiTestCaseMapper.selectIdsByQuery((ApiTestCaseRequest) query));
List<MsExecResponseDTO> responseDTOS = new LinkedList<>();
ApiTestCaseExample example = new ApiTestCaseExample();
example.createCriteria().andIdIn(request.getIds());
List<ApiTestCaseWithBLOBs> caseList = apiTestCaseMapper.selectByExampleWithBLOBs(example);
@ -222,6 +225,7 @@ public class ApiCaseExecuteService {
apiScenarioReportStructureService.save(serialReportId, new ArrayList<>());
apiCaseResultService.batchSave(executeQueue);
responseDTOS.add(new MsExecResponseDTO(JSON.toJSONString(request.getIds()), report.getId(), request.getTriggerMode()));
}
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
@ -238,7 +242,6 @@ public class ApiCaseExecuteService {
request.setTriggerMode(ApiRunMode.DEFINITION.name());
}
List<MsExecResponseDTO> responseDTOS = new LinkedList<>();
Map<String, ApiDefinitionExecResult> executeQueue = new LinkedHashMap<>();
String status = request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString()) ? APITestStatus.Waiting.name() : APITestStatus.Running.name();
@ -254,8 +257,10 @@ public class ApiCaseExecuteService {
report.setIntegratedReportId(serialReportId);
}
executeQueue.put(caseWithBLOBs.getId(), report);
if (!StringUtils.equals(request.getConfig().getReportType(), RunModeConstants.SET_REPORT.toString())) {
responseDTOS.add(new MsExecResponseDTO(caseWithBLOBs.getId(), report.getId(), request.getTriggerMode()));
}
}
apiCaseResultService.batchSave(executeQueue);

View File

@ -349,6 +349,7 @@ public class ApiScenarioReportService {
execResultExample.createCriteria().andIntegratedReportIdEqualTo(reportId).andStatusEqualTo("Error");
long size = definitionExecResultMapper.countByExample(execResultExample);
result.setStatus(size > 0 ? ScenarioStatus.Error.name() : ScenarioStatus.Success.name());
result.setEndTime(System.currentTimeMillis());
definitionExecResultMapper.updateByPrimaryKeySelective(result);
} else {
ApiScenarioReport report = apiScenarioReportMapper.selectByPrimaryKey(reportId);

View File

@ -58,6 +58,8 @@ public class MsHashTreeService {
private static final String BODY = "body";
private static final String ARGUMENTS = "arguments";
private static final String AUTH_MANAGER = "authManager";
private static final String PROJECT_ID = "projectId";
private static final String ACTIVE = "active";
public void setHashTree(JSONArray hashTree) {
// 将引用转成复制
@ -187,11 +189,12 @@ public class MsHashTreeService {
element.put(REST, refElement.get(REST));
element.put(PATH, refElement.get(PATH));
element.put(BODY, refElement.get(BODY));
element.put("active", false);
element.put(ACTIVE, false);
element.put(AUTH_MANAGER, refElement.get(AUTH_MANAGER));
element.put(ARGUMENTS, refElement.get(ARGUMENTS));
element.put(PROJECT_ID, apiTestCase.getProjectId());
if (array != null) {
JSONArray sourceHashTree = element.getJSONArray("hashTree");
JSONArray sourceHashTree = element.getJSONArray(HASH_TREE);
Map<String, List<JSONObject>> groupMap = ElementUtil.group(sourceHashTree);
Map<String, List<JSONObject>> targetGroupMap = ElementUtil.group(refElement.getJSONArray(HASH_TREE));
@ -208,7 +211,7 @@ public class MsHashTreeService {
if (CollectionUtils.isNotEmpty(rules)) {
step.addAll(rules);
}
element.put("hashTree", step);
element.put(HASH_TREE, step);
}
element.put(REFERENCED, REF);
element.put(DISABLED, true);

View File

@ -734,11 +734,6 @@ export default {
this.getEnvDomain(data.hashTree, domainMap);
this.margeDomain(this.scenarioDefinition, domainMap);
this.cancelBatchProcessing();
if (this.$store.state.currentApiCase) {
this.$store.state.currentApiCase.resetDataSource = getUUID();
} else {
this.$store.state.currentApiCase = {resetDataSource: getUUID()};
}
}
}
})

View File

@ -270,32 +270,16 @@ export default {
if (requireComponent != null && JSON.stringify(esbDefinition) != '{}' && JSON.stringify(esbDefinitionResponse) != '{}') {
this.showXpackCompnent = true;
}
this.getEnvironments(this.environmentGroupId);
},
watch: {
envMap(val) {
this.getEnvironments();
this.environmentMap = val;
},
message() {
this.forStatus();
this.reload();
},
environmentGroupId(val) {
this.getEnvironments(val);
},
environmentType(val) {
this.envType = val;
},
'$store.state.currentApiCase.debugLoop'() {
this.forStatus();
this.reload();
},
'$store.state.currentApiCase.resetDataSource'() {
if (this.request.id && this.request.referenced !== 'REF') {
this.initDataSource();
}
},
},
computed: {
displayColor() {
@ -391,50 +375,7 @@ export default {
this.response = this.request.requestResult[0];
}
},
initDataSource() {
let databaseConfigsOptions = [];
if (this.request.protocol === 'SQL' || this.request.type === 'JDBCSampler') {
if (this.environment && this.environment.config) {
let config = JSON.parse(this.environment.config);
if (config && config.databaseConfigs) {
config.databaseConfigs.forEach(item => {
databaseConfigsOptions.push(item);
});
}
}
}
if (databaseConfigsOptions.length > 0 && this.request.environmentId !== this.environment.id) {
this.request.dataSourceId = databaseConfigsOptions[0].id;
this.request.environmentId = this.environment.id;
}
},
getEnvironments(groupId) {
this.environment = {};
let id = undefined;
if (groupId) {
this.$get("/environment/group/project/map/" + groupId, res => {
let data = res.data;
if (data) {
this.environmentMap = new Map(Object.entries(data));
id = new Map(Object.entries(data)).get(this.request.projectId);
if (id) {
this.$get('/api/environment/get/' + id, response => {
this.environment = response.data;
this.initDataSource();
});
}
}
})
} else {
id = this.envMap.get(this.request.projectId);
if (id) {
this.$get('/api/environment/get/' + id, response => {
this.environment = response.data;
this.initDataSource();
});
}
}
},
remove() {
this.$emit('remove', this.request, this.node);
},
@ -454,78 +395,6 @@ export default {
}
}
},
getApiInfo() {
if (this.request.id && this.request.referenced === 'REF') {
let requestResult = this.request.requestResult;
let enable = this.request.enable;
this.$get("/api/testcase/get/" + this.request.id, response => {
if (response.data) {
let hashTree = [];
if (this.request.hashTree) {
hashTree = JSON.parse(JSON.stringify(this.request.hashTree));
}
Object.assign(this.request, JSON.parse(response.data.request));
this.request.name = response.data.name;
this.request.referenced = "REF";
this.request.enable = enable;
if (response.data.path && response.data.path != null) {
this.request.path = response.data.path;
this.request.url = response.data.url;
}
if (response.data.method && response.data.method != null) {
this.request.method = response.data.method;
}
if (requestResult && Object.prototype.toString.call(requestResult) !== '[object Array]') {
this.request.requestResult = [requestResult];
} else {
this.request.requestResult = requestResult;
}
if (response.data.num) {
this.request.num = response.data.num;
}
this.request.id = response.data.id;
this.request.disabled = true;
this.request.root = true;
this.request.projectId = response.data.projectId;
this.request.versionName = response.data.versionName;
this.request.versionEnable = response.data.versionEnable;
let req = JSON.parse(response.data.request);
if (req && this.request) {
this.request.hashTree = hashTree;
this.mergeHashTree(req.hashTree);
}
this.initDataSource();
this.forStatus();
this.sort();
this.reload();
}
})
} else if (this.request.id && this.request.referenced === 'Copy') {
if (this.request.refType === 'CASE') {
this.$get("/api/testcase/get/" + this.request.id, response => {
if (response.data) {
if (response.data.num) {
this.request.num = response.data.num;
}
this.request.id = response.data.id;
this.request.versionName = response.data.versionName;
this.request.versionEnable = response.data.versionEnable;
}
})
} else if (this.request.refType === 'API') {
this.$get("/api/definition/get/" + this.request.id, response => {
if (response.data) {
if (response.data.num) {
this.request.num = response.data.num;
}
this.request.id = response.data.id;
this.request.versionName = response.data.versionName;
this.request.versionEnable = response.data.versionEnable;
}
})
}
}
},
mergeHashTree(targetHashTree) {
let sourceHashTree = this.request.hashTree;
//

View File

@ -161,14 +161,17 @@
}
},
watch: {
'request.dataSourceId'() {
this.setDataSource();
},
'request.hashTree': {
handler(v) {
this.initStepSize(this.request.hashTree);
},
deep: true
},
'$store.state.scenarioEnvMap': {
handler(v) {
this.getEnvironments();
},
deep: true
}
},
created() {
@ -248,18 +251,25 @@
this.environments.forEach(environment => {
parseEnvironment(environment);
});
if (!this.request.environmentId) {
this.request.environmentId = this.$store.state.useEnvironment;
}
let hasEnvironment = false;
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) {
this.request.environmentId = undefined;
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
&& this.$store.state.scenarioEnvMap.has(this.projectId)) {
this.request.environmentId = this.$store.state.scenarioEnvMap.get(this.projectId);
}
}
if (!this.request.environmentId) {
this.request.dataSourceId = undefined;
@ -272,16 +282,25 @@
},
initDataSource() {
let flag = false;
let environment = {};
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
environment = this.environments[i];
break;
}
}
this.databaseConfigsOptions = [];
this.environments[i].config.databaseConfigs.forEach(item => {
if (environment.config && environment.config.databaseConfigs) {
environment.config.databaseConfigs.forEach(item => {
if (item.id === this.request.dataSourceId) {
flag = true;
}
this.databaseConfigsOptions.push(item);
});
break;
if (!flag && environment.config.databaseConfigs.length > 0) {
this.request.dataSourceId = environment.config.databaseConfigs[0].id;
flag = true;
}
}
if (!flag) {
@ -332,10 +351,6 @@
margin-left: 60px;
}
.ms-left-cell {
margin-top: 40px;
}
.ms-header {
background: #783887;
color: white;
@ -349,10 +364,6 @@
padding: 7px;
}
.ms-left-buttion {
margin: 6px 0px 8px 30px;
}
/deep/ .el-form-item {
margin-bottom: 15px;
}