fix(测试跟踪): 功能用例xmind导入,没有设置自定义系统字段的默认值

--bug=1028087 --user=陈建星 【测试跟踪】github#25753,导入用例如果xmind中没有设置优先级导入后默认固定为P0,导入也应从默认模板中获取默认值 https://www.tapd.cn/55049933/s/1396651
This commit is contained in:
jianxing 2023-07-25 11:06:30 +08:00 committed by fit2-zhao
parent 908b32f7b1
commit d68c257267
2 changed files with 41 additions and 9 deletions

View File

@ -1127,6 +1127,7 @@ public class TestCaseService {
try {
request.setTestCaseNames(testCaseNames);
request.setUseCustomId(useCunstomId);
request.setCustomFields(getProjectCustomFields(projectId));
XmindCaseParser xmindParser = new XmindCaseParser(request);
errList = xmindParser.parse(multipartFile);
List<TestCaseWithBLOBs> testCase = xmindParser.getTestCase();
@ -1234,17 +1235,9 @@ public class TestCaseService {
try {
//根据本地语言环境选择用哪种数据对象进行存放读取的数据
Class clazz = new TestCaseExcelDataFactory().getExcelDataByLocal();
TrackTestCaseTemplateService trackTestCaseTemplateService = CommonBeanFactory.getBean(TrackTestCaseTemplateService.class);
TestCaseTemplateDao testCaseTemplate = trackTestCaseTemplateService.getTemplate(projectId);
List<CustomFieldDao> customFields = null;
if (testCaseTemplate == null) {
customFields = new ArrayList<>();
} else {
customFields = testCaseTemplate.getCustomFields();
}
request.setUserIds(userIds);
request.setTestCaseNames(testCaseNames);
request.setCustomFields(customFields);
request.setCustomFields(getProjectCustomFields(projectId));
request.setSavedCustomIds(savedIds);
request.setUseCustomId(useCustomId);
Set<ExcelMergeInfo> mergeInfoSet = new TreeSet<>();
@ -1269,6 +1262,18 @@ public class TestCaseService {
return getImportResponse(errList, isUpdated);
}
private static List<CustomFieldDao> getProjectCustomFields(String projectId) {
TrackTestCaseTemplateService trackTestCaseTemplateService = CommonBeanFactory.getBean(TrackTestCaseTemplateService.class);
TestCaseTemplateDao testCaseTemplate = trackTestCaseTemplateService.getTemplate(projectId);
List<CustomFieldDao> customFields = null;
if (testCaseTemplate == null) {
customFields = new ArrayList<>();
} else {
customFields = testCaseTemplate.getCustomFields();
}
return customFields;
}
public void saveImportData(List<TestCaseWithBLOBs> testCases, TestCaseImportRequest request,
Map<String, List<CustomFieldResourceDTO>> testCaseCustomFieldMap) {
saveImportData( testCases, request, testCaseCustomFieldMap, null);

View File

@ -5,6 +5,8 @@ import io.metersphere.commons.constants.TestCaseConstants;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.CustomFieldDao;
import io.metersphere.excel.domain.ExcelErrData;
import io.metersphere.excel.domain.TestCaseExcelData;
import io.metersphere.excel.utils.ExcelImportType;
@ -344,6 +346,8 @@ public class XmindCaseParser {
testCase.setMaintainer(request.getUserId());
testCase.setPriority(priorityList.get(0));
setDefaultCustomFieldVal(testCase);
String tc = title.replace("", ":");
String[] tcArrs = tc.split(":");
if (tcArrs.length < 1) {
@ -409,6 +413,29 @@ public class XmindCaseParser {
}
}
private void setDefaultCustomFieldVal(TestCaseWithBLOBs testCase) {
try {
for (CustomFieldDao customField : request.getCustomFields()) {
if (StringUtils.isBlank(customField.getDefaultValue())) {
continue;
}
String defaultVal = JSON.parseObject(customField.getDefaultValue()).toString();
if (StringUtils.isBlank(defaultVal)) {
continue;
}
if (StringUtils.equals(customField.getName(), "用例等级")) {
testCase.setPriority(defaultVal);
} else if (StringUtils.equals(customField.getName(), "用例状态")) {
testCase.setStatus(defaultVal);
} else if (StringUtils.equals(customField.getName(), "责任人")) {
testCase.setMaintainer(defaultVal);
}
}
} catch (Exception e) {
LogUtil.error(e);
}
}
/**
* 导入思维导图处理
*/