fix(接口测试): 修复接口测试批量赋值版本数据时Mock数据复制错读的问题

--bug=1021663 --user=宋天阳
【接口测试】接口定义-左上角筛选版本为v1.8,批量复制版本数据v1.0到v1.8版本后Mock错误
https://www.tapd.cn/55049933/s/1323686
This commit is contained in:
song-tianyang 2023-01-06 17:44:50 +08:00 committed by 建国
parent 5bbf45baab
commit 2133419ca0
3 changed files with 46 additions and 35 deletions

View File

@ -187,6 +187,13 @@ public class MockConfigService {
}
}
public void sendMockNotice(String mockExpectId, String defaultContext, String event) {
MockExpectConfigWithBLOBs mockExpectConfigWithBLOBs = mockExpectConfigMapper.selectByPrimaryKey(mockExpectId);
if (mockExpectConfigWithBLOBs != null) {
this.sendMockNotice(mockExpectConfigWithBLOBs, defaultContext, event);
}
}
private void getParamMap(Map<String, Object> paramMap, String userId, MockExpectConfigWithBLOBs mockExpectConfigWithBLOBs, MockConfig mockConfig) {
paramMap.put("operator", userId);
paramMap.put("id", mockExpectConfigWithBLOBs.getId());
@ -213,7 +220,7 @@ public class MockConfigService {
model.setUpdateTime(timestamp);
model.setStatus(request.getStatus());
mockExpectConfigMapper.updateByPrimaryKeySelective(model);
sendMockNotice(model, "更新了mock", NoticeConstants.Event.MOCK_UPDATE);
sendMockNotice(request.getId(), "更新了mock", NoticeConstants.Event.MOCK_UPDATE);
return model;
} else {
return null;

View File

@ -1463,7 +1463,15 @@ public class ApiDefinitionService {
}
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String baseUrlSuffix, String mockApiResourceId) {
if (StringUtils.isEmpty(baseUrlSuffix)) {
if (StringUtils.isNotBlank(mockApiResourceId)) {
//如果请求头中指定了API 则返回当前API
List<ApiDefinitionWithBLOBs> returnList = new ArrayList<>();
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionMapper.selectByPrimaryKey(mockApiResourceId);
if (apiDefinition != null) {
returnList.add(apiDefinition);
}
return returnList;
} else if (StringUtils.isEmpty(baseUrlSuffix)) {
return new ArrayList<>();
} else {
String apiId = this.getApiIdFromMockApiResourceId(mockApiResourceId, projectId);
@ -2206,70 +2214,70 @@ public class ApiDefinitionService {
long timeStamp = System.currentTimeMillis();
MockConfigExample mockConfigExample = new MockConfigExample();
mockConfigExample.createCriteria().andApiIdIn(new ArrayList<>(sourceApiIdRefIdMap.keySet()));
List<MockConfig> mockConfigList = mockConfigMapper.selectByExample(mockConfigExample);
if (CollectionUtils.isNotEmpty(mockConfigList)) {
List<String> mockIdList = mockConfigList.stream().map(MockConfig::getId).collect(Collectors.toList());
List<MockConfig> sourceMockConfigList = mockConfigMapper.selectByExample(mockConfigExample);
if (CollectionUtils.isNotEmpty(sourceMockConfigList)) {
List<String> sourceMockConfigIdList = sourceMockConfigList.stream().map(MockConfig::getId).collect(Collectors.toList());
MockExpectConfigExample mockExpectConfigExample = new MockExpectConfigExample();
mockExpectConfigExample.createCriteria().andMockConfigIdIn(mockIdList);
mockExpectConfigExample.createCriteria().andMockConfigIdIn(sourceMockConfigIdList);
List<MockExpectConfigWithBLOBs> mockExpectConfigWithBLOBsList = mockExpectConfigMapper.selectByExampleWithBLOBs(mockExpectConfigExample);
Map<String, List<MockExpectConfigWithBLOBs>> mockConfigIdExpectMap = mockExpectConfigWithBLOBsList.stream().collect(Collectors.groupingBy(MockExpectConfigWithBLOBs::getMockConfigId));
Map<String, List<MockExpectConfigWithBLOBs>> sourceMockConfigIdMap = mockExpectConfigWithBLOBsList.stream().collect(Collectors.groupingBy(MockExpectConfigWithBLOBs::getMockConfigId));
List<MockConfig> saveMockList = new ArrayList<>();
List<MockExpectConfigWithBLOBs> saveMockExpectList = new ArrayList<>();
List<MockExpectConfigWithBLOBs> updateMockExpectList = new ArrayList<>();
mockConfigList.forEach(item -> {
String oldApiId = item.getApiId();
String refId = sourceApiIdRefIdMap.get(oldApiId);
sourceMockConfigList.forEach(item -> {
String sourceApiId = item.getApiId();
String refId = sourceApiIdRefIdMap.get(sourceApiId);
if (StringUtils.isNotBlank(refId)) {
ApiDefinition api = refIdMap.get(refId);
if (api != null) {
MockConfig baseMockConfig = mockConfigService.selectMockConfigByApiId(api.getId());
String mockConfigId = UUID.randomUUID().toString();
ApiDefinition goalApi = refIdMap.get(refId);
if (goalApi != null) {
MockConfig goalApiMockConfig = mockConfigService.selectMockConfigByApiId(goalApi.getId());
String goalApiMockConfigId = UUID.randomUUID().toString();
Map<String, MockExpectConfig> oldMockExpectConfig = new HashMap<>();
//已经存储的mock期望编号
List<String> saveExpectNumList = new ArrayList<>();
if (baseMockConfig == null) {
if (goalApiMockConfig == null) {
MockConfig mockConfig = new MockConfig();
BeanUtils.copyBean(mockConfig, item);
mockConfig.setApiId(api.getId());
mockConfig.setId(mockConfigId);
mockConfig.setApiId(goalApi.getId());
mockConfig.setId(goalApiMockConfigId);
mockConfig.setCreateTime(timeStamp);
mockConfig.setUpdateTime(timeStamp);
saveMockList.add(mockConfig);
} else {
mockConfigId = baseMockConfig.getId();
saveExpectNumList = mockConfigService.selectExpectNumberByConfigId(mockConfigId);
List<MockExpectConfig> oldMockExpectList = mockConfigService.selectSimpleMockExpectConfigByMockConfigId(mockConfigId);
oldMockExpectList.forEach(mockExpectConfig -> {
goalApiMockConfigId = goalApiMockConfig.getId();
saveExpectNumList = mockConfigService.selectExpectNumberByConfigId(goalApiMockConfigId);
List<MockExpectConfig> goalMockExpectList = mockConfigService.selectSimpleMockExpectConfigByMockConfigId(goalApiMockConfigId);
goalMockExpectList.forEach(mockExpectConfig -> {
oldMockExpectConfig.put(StringUtils.trim(mockExpectConfig.getName()), mockExpectConfig);
});
}
List<MockExpectConfigWithBLOBs> mockExpectConfigList = mockConfigIdExpectMap.get(item.getId());
List<MockExpectConfigWithBLOBs> mockExpectConfigList = sourceMockConfigIdMap.get(item.getId());
if (CollectionUtils.isNotEmpty(mockExpectConfigList)) {
String finalMockConfigId = mockConfigId;
String finalMockConfigId = goalApiMockConfigId;
List<String> finalSaveExpectNumList = saveExpectNumList;
mockExpectConfigList.forEach(mockExpectConfigWithBLOBs -> {
MockExpectConfig oldExpect = oldMockExpectConfig.get(StringUtils.trim(mockExpectConfigWithBLOBs.getName()));
MockExpectConfigWithBLOBs expectConfigWithBLOBs = new MockExpectConfigWithBLOBs();
BeanUtils.copyBean(expectConfigWithBLOBs, mockExpectConfigWithBLOBs);
expectConfigWithBLOBs.setMockConfigId(finalMockConfigId);
expectConfigWithBLOBs.setUpdateTime(timeStamp);
if (oldExpect == null) {
String newMockExpectNum = mockConfigService.getMockExpectId(String.valueOf(api.getNum()), finalSaveExpectNumList);
String newMockExpectNum = mockConfigService.getMockExpectId(String.valueOf(goalApi.getNum()), finalSaveExpectNumList);
finalSaveExpectNumList.add(newMockExpectNum);
expectConfigWithBLOBs.setId(UUID.randomUUID().toString());
expectConfigWithBLOBs.setExpectNum(newMockExpectNum);
expectConfigWithBLOBs.setCreateTime(timeStamp);
expectConfigWithBLOBs.setUpdateTime(timeStamp);
expectConfigWithBLOBs.setMockConfigId(finalMockConfigId);
saveMockExpectList.add(expectConfigWithBLOBs);
} else {
expectConfigWithBLOBs.setId(oldExpect.getId());
expectConfigWithBLOBs.setCreateTime(oldExpect.getCreateTime());
expectConfigWithBLOBs.setUpdateTime(timeStamp);
updateMockExpectList.add(expectConfigWithBLOBs);
}
});

View File

@ -1,7 +1,7 @@
<template>
<ms-edit-dialog
:visible.sync="visible"
width="300px"
width="400px"
:title="$t('commons.delete_all_version')"
:with-footer="false"
:close-on-click-modal="false"
@ -12,13 +12,9 @@
<el-select v-model="versionId" size="small" :placeholder="$t('project.version.please_input_version')">
<el-option v-for="v in versionData" :key="v.id" :label="v.name" :value="v.id" />
</el-select>
<el-popover
placement="top-start"
width="200"
trigger="hover"
:content="$t('api_definition.copy_data_from_other_version_tips')">
<i class="el-icon-warning" slot="reference" style="color: #f56c6c; margin: 0 0 0 5px" />
</el-popover>
</el-row>
<el-row style="margin: 0">
<p style="color: #939496">{{ $t('api_definition.copy_data_from_other_version_tips') }}</p>
</el-row>
<el-row style="margin-top: 10px">
<el-checkbox v-model="selectCase" v-permission="['PROJECT_API_DEFINITION:READ+CREATE_CASE']">{{