fix(测试跟踪): 功能用例保存重复检验失效

--bug=1027457 --user=陈建星 【测试跟踪】功能用例创建-同一模块下保存了内容一样的多个用例 https://www.tapd.cn/55049933/s/1388171
This commit is contained in:
jianxing 2023-06-29 18:28:55 +08:00 committed by fit2-zhao
parent 17238af777
commit 475fda0d79
5 changed files with 12 additions and 15 deletions

View File

@ -303,6 +303,8 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
} }
private void validateDbExist(TestCaseExcelData data, StringBuilder stringBuilder) { private void validateDbExist(TestCaseExcelData data, StringBuilder stringBuilder) {
// 校验模块是否存在没有存在则新建一个模块
testCaseNodeService.createNodeByNodePath(data.getNodePath(), request.getProjectId(), nodeTrees, pathMap);
if (this.isUpdateModel()) { if (this.isUpdateModel()) {
return; return;
} }
@ -313,10 +315,7 @@ public class TestCaseNoModelDataListener extends AnalysisEventListener<Map<Integ
String steps = getSteps(data); String steps = getSteps(data);
testCase.setSteps(steps); testCase.setSteps(steps);
// 校验模块是否存在没有存在则新建一个模块
testCaseNodeService.createNodeByNodePath(testCase.getNodePath(), request.getProjectId(), nodeTrees, pathMap);
testCase.setNodeId(pathMap.get(testCase.getNodePath())); testCase.setNodeId(pathMap.get(testCase.getNodePath()));
boolean dbExist = testCaseService.exist(testCase); boolean dbExist = testCaseService.exist(testCase);
boolean excelExist = false; boolean excelExist = false;

View File

@ -211,7 +211,7 @@ public class TestCaseService {
public TestCaseWithBLOBs addTestCase(EditTestCaseRequest request) { public TestCaseWithBLOBs addTestCase(EditTestCaseRequest request) {
request.setName(request.getName()); request.setName(request.getName());
checkTestCaseExist(request); checkTestCaseExist(request, false);
request.setId(request.getId()); request.setId(request.getId());
request.setCreateTime(System.currentTimeMillis()); request.setCreateTime(System.currentTimeMillis());
request.setUpdateTime(System.currentTimeMillis()); request.setUpdateTime(System.currentTimeMillis());
@ -455,6 +455,7 @@ public class TestCaseService {
// latest 字段 createNewVersionOrNot 已经设置过了不更新 // latest 字段 createNewVersionOrNot 已经设置过了不更新
testCase.setLatest(null); testCase.setLatest(null);
checkTestCaseExist(testCase, true);
testCaseMapper.updateByPrimaryKeySelective(testCase); testCaseMapper.updateByPrimaryKeySelective(testCase);
TestCaseWithBLOBs testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCase.getId()); TestCaseWithBLOBs testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(testCase.getId());
@ -614,7 +615,7 @@ public class TestCaseService {
} }
} }
public TestCaseWithBLOBs checkTestCaseExist(TestCaseWithBLOBs testCase) { public void checkTestCaseExist(TestCaseWithBLOBs testCase, boolean isEdit) {
// 全部字段值相同才判断为用例存在 // 全部字段值相同才判断为用例存在
if (testCase != null) { if (testCase != null) {
@ -634,7 +635,7 @@ public class TestCaseService {
if (StringUtils.isNotBlank(testCase.getTestId())) { if (StringUtils.isNotBlank(testCase.getTestId())) {
criteria.andTestIdEqualTo(testCase.getTestId()); criteria.andTestIdEqualTo(testCase.getTestId());
} }
if (StringUtils.isNotBlank(testCase.getId())) { if (isEdit && StringUtils.isNotBlank(testCase.getId())) {
criteria.andIdNotEqualTo(testCase.getId()); criteria.andIdNotEqualTo(testCase.getId());
} }
List<TestCaseWithBLOBs> caseList = testCaseMapper.selectByExampleWithBLOBs(example); List<TestCaseWithBLOBs> caseList = testCaseMapper.selectByExampleWithBLOBs(example);
@ -649,13 +650,11 @@ public class TestCaseService {
String remark = tc.getRemark() == null ? StringUtils.EMPTY : tc.getRemark(); String remark = tc.getRemark() == null ? StringUtils.EMPTY : tc.getRemark();
String prerequisite = tc.getPrerequisite() == null ? StringUtils.EMPTY : tc.getPrerequisite(); String prerequisite = tc.getPrerequisite() == null ? StringUtils.EMPTY : tc.getPrerequisite();
if (StringUtils.equals(steps, caseSteps) && StringUtils.equals(remark, caseRemark) && StringUtils.equals(prerequisite, casePrerequisite)) { if (StringUtils.equals(steps, caseSteps) && StringUtils.equals(remark, caseRemark) && StringUtils.equals(prerequisite, casePrerequisite)) {
//MSException.throwException(Translator.get("test_case_already_exists")); MSException.throwException(Translator.get("test_case_already_exists_in_module"));
return tc;
} }
} }
} }
} }
return null;
} }
/** /**
@ -2176,7 +2175,7 @@ public class TestCaseService {
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
TestCaseWithBLOBs batchCopy = new TestCaseWithBLOBs(); TestCaseWithBLOBs batchCopy = new TestCaseWithBLOBs();
BeanUtils.copyBean(batchCopy, list.get(i)); BeanUtils.copyBean(batchCopy, list.get(i));
checkTestCaseExist(batchCopy); checkTestCaseExist(batchCopy, false);
String oldTestCaseId = batchCopy.getId(); String oldTestCaseId = batchCopy.getId();
String id = UUID.randomUUID().toString(); String id = UUID.randomUUID().toString();
batchCopy.setId(id); batchCopy.setId(id);
@ -2307,15 +2306,11 @@ public class TestCaseService {
* @return * @return
*/ */
public boolean exist(TestCaseWithBLOBs testCaseWithBLOBs) { public boolean exist(TestCaseWithBLOBs testCaseWithBLOBs) {
try { try {
TestCaseWithBLOBs caseWithBLOBs = checkTestCaseExist(testCaseWithBLOBs); checkTestCaseExist(testCaseWithBLOBs, testCaseWithBLOBs.getId() == null ? true : false);
if (caseWithBLOBs != null)
return true;
} catch (MSException e) { } catch (MSException e) {
return true; return true;
} }
return false; return false;
} }

View File

@ -98,6 +98,7 @@ test_case_import_template_sheet=Template
module_not_null=The module must not be blank module_not_null=The module must not be blank
user_not_exists=The user in this project is not exists user_not_exists=The user in this project is not exists
test_case_already_exists=The test case in this project is exists test_case_already_exists=The test case in this project is exists
test_case_already_exists_in_module=The test case in this module is exists
parse_data_error=Parse data error parse_data_error=Parse data error
missing_header_information=Missing header information missing_header_information=Missing header information
test_case_exist=A test case already exists under this project: test_case_exist=A test case already exists under this project:

View File

@ -70,6 +70,7 @@ test_case_import_template_sheet=模版
module_not_null=所属模块不能为空格 module_not_null=所属模块不能为空格
user_not_exists=该项目下无该用户 user_not_exists=该项目下无该用户
test_case_already_exists=该项目下已存在该测试用例 test_case_already_exists=该项目下已存在该测试用例
test_case_already_exists_in_module=该模块下已存在该测试用例
parse_data_error=解析数据出错 parse_data_error=解析数据出错
missing_header_information=缺少头部信息 missing_header_information=缺少头部信息
test_case_exist=该项目下已存在用例: test_case_exist=该项目下已存在用例:

View File

@ -70,6 +70,7 @@ test_case_import_template_sheet=模版
module_not_null=所屬模塊不能為空格 module_not_null=所屬模塊不能為空格
user_not_exists=該項目下無該用戶 user_not_exists=該項目下無該用戶
test_case_already_exists=該項目下已存在該測試用例 test_case_already_exists=該項目下已存在該測試用例
test_case_already_exists_in_module=該模塊下已存在該測試用例
parse_data_error=解析數據出錯 parse_data_error=解析數據出錯
missing_header_information=缺少頭部信息 missing_header_information=缺少頭部信息
test_case_exist=該項目下已存在用例: test_case_exist=該項目下已存在用例: