fix(接口自动化): 修复场景引用步骤导出再导入缺陷
This commit is contained in:
parent
1298a61a42
commit
f6bc6f6e0d
|
@ -306,7 +306,7 @@ public class ApiAutomationService {
|
||||||
.andIdNotEqualTo(request.getId());
|
.andIdNotEqualTo(request.getId());
|
||||||
List<ApiScenario> list = apiScenarioMapper.selectByExample(example);
|
List<ApiScenario> list = apiScenarioMapper.selectByExample(example);
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
MSException.throwException("自定义ID "+ request.getCustomNum() +" 已存在!");
|
MSException.throwException("自定义ID " + request.getCustomNum() + " 已存在!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1755,12 +1755,64 @@ public class ApiAutomationService {
|
||||||
return apiImport;
|
return apiImport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setHashTree(JSONArray hashTree) {
|
||||||
|
// 将引用转成复制
|
||||||
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
|
for (int i = 0; i < hashTree.size(); i++) {
|
||||||
|
JSONObject object = (JSONObject) hashTree.get(i);
|
||||||
|
String referenced = object.getString("referenced");
|
||||||
|
if (StringUtils.isNotBlank(referenced) && StringUtils.equals(referenced, "REF")) {
|
||||||
|
// 检测引用对象是否存在,若果不存在则改成复制对象
|
||||||
|
String refType = object.getString("refType");
|
||||||
|
if (StringUtils.isNotEmpty(refType)) {
|
||||||
|
if (refType.equals("CASE")) {
|
||||||
|
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(object.getString("id"));
|
||||||
|
if (bloBs != null) {
|
||||||
|
object = JSON.parseObject(bloBs.getRequest());
|
||||||
|
object.put("id", bloBs.getId());
|
||||||
|
object.put("name", bloBs.getName());
|
||||||
|
hashTree.set(i, object);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ApiScenarioWithBLOBs bloBs = this.getDto(object.getString("id"));
|
||||||
|
if (bloBs != null) {
|
||||||
|
object = JSON.parseObject(bloBs.getScenarioDefinition());
|
||||||
|
hashTree.set(i, object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ("scenario".equals(object.getString("type"))) {
|
||||||
|
ApiScenarioWithBLOBs bloBs = this.getDto(object.getString("id"));
|
||||||
|
if (bloBs != null) {
|
||||||
|
object = JSON.parseObject(bloBs.getScenarioDefinition());
|
||||||
|
hashTree.set(i, object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(object.getJSONArray("hashTree"))) {
|
||||||
|
setHashTree(object.getJSONArray("hashTree"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<ApiScenarioWithBLOBs> getExportResult(ApiScenarioBatchRequest request) {
|
private List<ApiScenarioWithBLOBs> getExportResult(ApiScenarioBatchRequest request) {
|
||||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||||
(query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query));
|
(query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query));
|
||||||
ApiScenarioExample example = new ApiScenarioExample();
|
ApiScenarioExample example = new ApiScenarioExample();
|
||||||
example.createCriteria().andIdIn(request.getIds());
|
example.createCriteria().andIdIn(request.getIds());
|
||||||
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = apiScenarioMapper.selectByExampleWithBLOBs(example);
|
List<ApiScenarioWithBLOBs> apiScenarioWithBLOBs = apiScenarioMapper.selectByExampleWithBLOBs(example);
|
||||||
|
// 处理引用数据
|
||||||
|
if (CollectionUtils.isNotEmpty(apiScenarioWithBLOBs)) {
|
||||||
|
apiScenarioWithBLOBs.forEach(item -> {
|
||||||
|
if (StringUtils.isNotEmpty(item.getScenarioDefinition())) {
|
||||||
|
JSONObject scenario = JSONObject.parseObject(item.getScenarioDefinition());
|
||||||
|
JSONArray hashTree = scenario.getJSONArray("hashTree");
|
||||||
|
setHashTree(hashTree);
|
||||||
|
scenario.put("hashTree", hashTree);
|
||||||
|
item.setScenarioDefinition(JSON.toJSONString(scenario));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
return apiScenarioWithBLOBs;
|
return apiScenarioWithBLOBs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<el-tag size="mini" class="ms-tag" v-if="request.referenced==='Deleted'" type="danger">{{ $t('api_test.automation.reference_deleted') }}</el-tag>
|
<el-tag size="mini" class="ms-tag" v-if="request.referenced==='Deleted'" type="danger">{{ $t('api_test.automation.reference_deleted') }}</el-tag>
|
||||||
<el-tag size="mini" class="ms-tag" v-if="request.referenced==='Copy'">{{ $t('commons.copy') }}</el-tag>
|
<el-tag size="mini" class="ms-tag" v-if="request.referenced==='Copy'">{{ $t('commons.copy') }}</el-tag>
|
||||||
<el-tag size="mini" class="ms-tag" v-if="request.referenced ==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag>
|
<el-tag size="mini" class="ms-tag" v-if="request.referenced ==='REF'">{{ $t('api_test.scenario.reference') }}</el-tag>
|
||||||
<span class="ms-tag">{{ getProjectName(request.projectId) }}</span>
|
<span class="ms-tag ms-step-name-api">{{ getProjectName(request.projectId) }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-slot:button>
|
<template v-slot:button>
|
||||||
|
@ -447,7 +447,16 @@ export default {
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
.ms-step-name-api {
|
||||||
|
display: inline-block;
|
||||||
|
margin: 0 5px;
|
||||||
|
overflow-x: hidden;
|
||||||
|
padding-bottom: 0;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
vertical-align: middle;
|
||||||
|
white-space: nowrap;
|
||||||
|
width: 60px;
|
||||||
|
}
|
||||||
.ms-tag {
|
.ms-tag {
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue