refactor(接口测试): 执行排序代码优化

This commit is contained in:
fit2-zhao 2022-03-16 17:04:42 +08:00 committed by 刘瑞斌
parent f3c4cd9578
commit 82b59953ba
2 changed files with 17 additions and 13 deletions

View File

@ -51,7 +51,9 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ElementUtil { public class ElementUtil {
private static final String PRE = "PRE";
private static final String POST = "POST";
private static final String ASSERTIONS = "ASSERTIONS";
private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR;
public static Arguments addArguments(ParameterConfig config, String projectId, String name) { public static Arguments addArguments(ParameterConfig config, String projectId, String name) {
@ -649,26 +651,26 @@ public class ElementUtil {
Map<String, List<MsTestElement>> groupMap = new LinkedHashMap<>(); Map<String, List<MsTestElement>> groupMap = new LinkedHashMap<>();
elements.forEach(item -> { elements.forEach(item -> {
if ("Assertions".equals(item.getType())) { if ("Assertions".equals(item.getType())) {
if (groupMap.containsKey("Assertions")) { if (groupMap.containsKey(ASSERTIONS)) {
groupMap.get("Assertions").add(item); groupMap.get(ASSERTIONS).add(item);
} else { } else {
groupMap.put("Assertions", new LinkedList<MsTestElement>() {{ groupMap.put(ASSERTIONS, new LinkedList<MsTestElement>() {{
this.add(item); this.add(item);
}}); }});
} }
} else if (preOperates.contains(item.getType())) { } else if (preOperates.contains(item.getType())) {
if (groupMap.containsKey("PreOperate")) { if (groupMap.containsKey(PRE)) {
groupMap.get("PreOperate").add(item); groupMap.get(PRE).add(item);
} else { } else {
groupMap.put("PreOperate", new LinkedList<MsTestElement>() {{ groupMap.put(PRE, new LinkedList<MsTestElement>() {{
this.add(item); this.add(item);
}}); }});
} }
} else if (postOperates.contains(item.getType())) { } else if (postOperates.contains(item.getType())) {
if (groupMap.containsKey("PostOperate")) { if (groupMap.containsKey(POST)) {
groupMap.get("PostOperate").add(item); groupMap.get(POST).add(item);
} else { } else {
groupMap.put("PostOperate", new LinkedList<MsTestElement>() {{ groupMap.put(POST, new LinkedList<MsTestElement>() {{
this.add(item); this.add(item);
}}); }});
} }
@ -676,9 +678,9 @@ public class ElementUtil {
elementList.add(item); elementList.add(item);
} }
}); });
elementList.addAll(groupMap.get("PreOperate").stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList())); elementList.addAll(groupMap.get(PRE).stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList()));
elementList.addAll(groupMap.get("PostOperate").stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList())); elementList.addAll(groupMap.get(POST).stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList()));
elementList.addAll(groupMap.get("Assertions").stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList())); elementList.addAll(groupMap.get(ASSERTIONS).stream().sorted(Comparator.comparing(MsTestElement::getIndex)).collect(Collectors.toList()));
} }
return elementList; return elementList;
} }

View File

@ -653,6 +653,8 @@ export default {
} }
if (item.hashTree && item.hashTree.length > 0) { if (item.hashTree && item.hashTree.length > 0) {
this.commandTreeNode(item, item.hashTree); this.commandTreeNode(item, item.hashTree);
} else {
item.isLeaf = true;
} }
}) })
if (node) { if (node) {