fix(测试跟踪): 修复未能导入没有用例的空模块问题
This commit is contained in:
parent
977182a193
commit
7bccd9f502
|
@ -355,50 +355,45 @@ public class TestCaseNodeService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> createNodeByTestCases(List<TestCaseWithBLOBs> testCases, String projectId) {
|
public Map<String, String> createNodeByTestCases(List<TestCaseWithBLOBs> testCases, String projectId) {
|
||||||
|
|
||||||
List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
|
|
||||||
|
|
||||||
Map<String, String> pathMap = new HashMap<>();
|
|
||||||
|
|
||||||
List<String> nodePaths = testCases.stream()
|
List<String> nodePaths = testCases.stream()
|
||||||
.map(TestCase::getNodePath)
|
.map(TestCase::getNodePath)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
nodePaths.forEach(path -> {
|
return this.createNodes(nodePaths, projectId);
|
||||||
|
}
|
||||||
|
|
||||||
if (path == null) {
|
public Map<String, String> createNodes(List<String> nodePaths, String projectId) {
|
||||||
|
List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
|
||||||
|
Map<String, String> pathMap = new HashMap<>();
|
||||||
|
for(String item : nodePaths){
|
||||||
|
if (item == null) {
|
||||||
throw new ExcelException(Translator.get("test_case_module_not_null"));
|
throw new ExcelException(Translator.get("test_case_module_not_null"));
|
||||||
}
|
}
|
||||||
List<String> nodeNameList = new ArrayList<>(Arrays.asList(path.split("/")));
|
List<String> nodeNameList = new ArrayList<>(Arrays.asList(item.split("/")));
|
||||||
Iterator<String> pathIterator = nodeNameList.iterator();
|
Iterator<String> itemIterator = nodeNameList.iterator();
|
||||||
|
|
||||||
Boolean hasNode = false;
|
Boolean hasNode = false;
|
||||||
String rootNodeName = null;
|
String rootNodeName = null;
|
||||||
|
|
||||||
if (nodeNameList.size() <= 1) {
|
if (nodeNameList.size() <= 1) {
|
||||||
throw new ExcelException(Translator.get("test_case_create_module_fail") + ":" + path);
|
throw new ExcelException(Translator.get("test_case_create_module_fail") + ":" + item);
|
||||||
} else {
|
} else {
|
||||||
pathIterator.next();
|
itemIterator.next();
|
||||||
pathIterator.remove();
|
itemIterator.remove();
|
||||||
|
rootNodeName = itemIterator.next().trim();
|
||||||
rootNodeName = pathIterator.next().trim();
|
|
||||||
//原来没有,新建的树nodeTrees也不包含
|
//原来没有,新建的树nodeTrees也不包含
|
||||||
for (TestCaseNodeDTO nodeTree : nodeTrees) {
|
for (TestCaseNodeDTO nodeTree : nodeTrees) {
|
||||||
if (StringUtils.equals(rootNodeName, nodeTree.getName())) {
|
if (StringUtils.equals(rootNodeName, nodeTree.getName())) {
|
||||||
hasNode = true;
|
hasNode = true;
|
||||||
createNodeByPathIterator(pathIterator, "/" + rootNodeName, nodeTree,
|
createNodeByPathIterator(itemIterator, "/" + rootNodeName, nodeTree,
|
||||||
pathMap, projectId, 2);
|
pathMap, projectId, 2);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!hasNode) {
|
if (!hasNode) {
|
||||||
createNodeByPath(pathIterator, rootNodeName, null, projectId, 1, "", pathMap);
|
createNodeByPath(itemIterator, rootNodeName, null, projectId, 1, "", pathMap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return pathMap;
|
return pathMap;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,6 +284,9 @@ public class TestCaseService {
|
||||||
errList.add(excelErrData);
|
errList.add(excelErrData);
|
||||||
excelResponse.setErrList(errList);
|
excelResponse.setErrList(errList);
|
||||||
} else {
|
} else {
|
||||||
|
if (!xmindParser.getNodePaths().isEmpty()) {
|
||||||
|
testCaseNodeService.createNodes(xmindParser.getNodePaths(), projectId);
|
||||||
|
}
|
||||||
if (!xmindParser.getTestCase().isEmpty()) {
|
if (!xmindParser.getTestCase().isEmpty()) {
|
||||||
this.saveImportData(xmindParser.getTestCase(), projectId);
|
this.saveImportData(xmindParser.getTestCase(), projectId);
|
||||||
xmindParser.clear();
|
xmindParser.clear();
|
||||||
|
|
|
@ -40,6 +40,9 @@ public class XmindCaseParser {
|
||||||
// 案例详情重写了hashCode方法去重用
|
// 案例详情重写了hashCode方法去重用
|
||||||
private List<TestCaseExcelData> compartDatas;
|
private List<TestCaseExcelData> compartDatas;
|
||||||
|
|
||||||
|
// 记录没有用例的目录
|
||||||
|
private List<String> nodePaths;
|
||||||
|
|
||||||
public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
|
public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
|
||||||
this.testCaseService = testCaseService;
|
this.testCaseService = testCaseService;
|
||||||
this.maintainer = userId;
|
this.maintainer = userId;
|
||||||
|
@ -48,6 +51,7 @@ public class XmindCaseParser {
|
||||||
testCases = new LinkedList<>();
|
testCases = new LinkedList<>();
|
||||||
compartDatas = new ArrayList<>();
|
compartDatas = new ArrayList<>();
|
||||||
process = new StringBuffer();
|
process = new StringBuffer();
|
||||||
|
nodePaths = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 这里清理是为了 加快jvm 回收
|
// 这里清理是为了 加快jvm 回收
|
||||||
|
@ -55,26 +59,55 @@ public class XmindCaseParser {
|
||||||
compartDatas.clear();
|
compartDatas.clear();
|
||||||
testCases.clear();
|
testCases.clear();
|
||||||
testCaseNames.clear();
|
testCaseNames.clear();
|
||||||
|
nodePaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TestCaseWithBLOBs> getTestCase() {
|
public List<TestCaseWithBLOBs> getTestCase() {
|
||||||
return this.testCases;
|
return this.testCases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getNodePaths() {
|
||||||
|
return this.nodePaths;
|
||||||
|
}
|
||||||
|
|
||||||
private final Map<String, String> caseTypeMap = ImmutableMap.of("功能测试", "functional", "性能测试", "performance", "接口测试", "api");
|
private final Map<String, String> caseTypeMap = ImmutableMap.of("功能测试", "functional", "性能测试", "performance", "接口测试", "api");
|
||||||
|
|
||||||
|
public void validate() {
|
||||||
|
nodePaths.forEach(nodePath -> {
|
||||||
|
String[] nodes = nodePath.split("/");
|
||||||
|
if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) {
|
||||||
|
process.append(Translator.get("test_case_node_level_tip") +
|
||||||
|
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level") + "; ");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < nodes.length; i++) {
|
||||||
|
if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) {
|
||||||
|
process.append(Translator.get("module_not_null") + "; ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 递归处理案例数据
|
// 递归处理案例数据
|
||||||
private void recursion(StringBuffer processBuffer, Attached parent, int level, String nodePath, List<Attached> attacheds) {
|
private void recursion(StringBuffer processBuffer, Attached parent, int level, List<Attached> attacheds) {
|
||||||
for (Attached item : attacheds) {
|
for (Attached item : attacheds) {
|
||||||
if (isAvailable(item.getTitle(), "(?:tc:|tc:|tc)")) { // 用例
|
if (isAvailable(item.getTitle(), "(?:tc:|tc:|tc)")) { // 用例
|
||||||
item.setParent(parent);
|
item.setParent(parent);
|
||||||
this.newTestCase(item.getTitle(), parent.getPath(), item.getChildren() != null ? item.getChildren().getAttached() : null);
|
this.newTestCase(item.getTitle(), parent.getPath(), item.getChildren() != null ? item.getChildren().getAttached() : null);
|
||||||
} else {
|
} else {
|
||||||
nodePath = parent.getPath() + "/" + item.getTitle();
|
String nodePath = parent.getPath() + "/" + item.getTitle();
|
||||||
item.setPath(nodePath);
|
item.setPath(nodePath);
|
||||||
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
|
|
||||||
item.setParent(parent);
|
item.setParent(parent);
|
||||||
recursion(processBuffer, item, level + 1, nodePath, item.getChildren().getAttached());
|
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
|
||||||
|
recursion(processBuffer, item, level + 1, item.getChildren().getAttached());
|
||||||
|
} else {
|
||||||
|
if (!nodePath.startsWith("/")) {
|
||||||
|
nodePath = "/" + nodePath;
|
||||||
|
}
|
||||||
|
if (nodePath.endsWith("/")) {
|
||||||
|
nodePath = nodePath.substring(0, nodePath.length() - 1);
|
||||||
|
}
|
||||||
|
nodePaths.add(nodePath); // 没有用例的路径
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,11 +276,12 @@ public class XmindCaseParser {
|
||||||
item.setPath(item.getTitle());
|
item.setPath(item.getTitle());
|
||||||
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
|
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
|
||||||
item.setPath(item.getTitle());
|
item.setPath(item.getTitle());
|
||||||
recursion(processBuffer, item, 1, item.getPath(), item.getChildren().getAttached());
|
recursion(processBuffer, item, 1, item.getChildren().getAttached());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.validate();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
processBuffer.append(Translator.get("incorrect_format"));
|
processBuffer.append(Translator.get("incorrect_format"));
|
||||||
LogUtil.error(ex.getMessage());
|
LogUtil.error(ex.getMessage());
|
||||||
|
|
Loading…
Reference in New Issue