refactor(测试跟踪): 修复无法正确解析V1版本使用fastJson生成的测试计划报告问题

修复无法正确解析V1版本使用fastJson生成的测试计划报告问题
This commit is contained in:
song-tianyang 2023-04-06 20:43:08 +08:00 committed by 建国
parent 3c954f9ee6
commit 4f096f958e
3 changed files with 200 additions and 19 deletions

View File

@ -15,7 +15,7 @@ import java.util.function.Function;
*/ */
public class BatchProcessingUtil { public class BatchProcessingUtil {
private static final int BATCH_PROCESS_QUANTITY = 1000; private static final int BATCH_PROCESS_QUANTITY = 100;
public static ScenarioProjectDTO getProjectIdsByScenarioIdList(List<String> scenarioIdList, Function<List<String>, ScenarioProjectDTO> func) { public static ScenarioProjectDTO getProjectIdsByScenarioIdList(List<String> scenarioIdList, Function<List<String>, ScenarioProjectDTO> func) {
ScenarioProjectDTO returnDTO = new ScenarioProjectDTO(); ScenarioProjectDTO returnDTO = new ScenarioProjectDTO();

View File

@ -1475,9 +1475,10 @@ public class TestPlanService {
config, config,
testPlanReport, testPlanReport,
testPlan, testPlanExecuteReportDTO); testPlan, testPlanExecuteReportDTO);
} else {
//针对已经保存过的数据结构增加对旧版本数据的支持
this.dealOldVersionData(testPlanReportStruct);
} }
//处理旧数据
this.dealOldVersionData(testPlanReportStruct);
//查找运行环境 //查找运行环境
testPlanReportService.initRunInformation(testPlanReportStruct, testPlanReport); testPlanReportService.initRunInformation(testPlanReportStruct, testPlanReport);
} }
@ -1485,29 +1486,209 @@ public class TestPlanService {
} }
/** /**
* 处理旧版本数据例如版本升级过程中由于统一了状态字段的数据 * 处理旧版本数据例如版本升级过程中由于统一了状态字段的数据 或者是由旧版本fastJson解析的无法被Jackson解析出来的数据
*/ */
private void dealOldVersionData(TestPlanReportDataStruct testPlanReportStruct) { private void dealOldVersionData(TestPlanReportDataStruct testPlanReportStruct) {
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getScenarioAllCases())) { List<TestPlanScenarioDTO> validScenarioList = this.getValidScenarioList(testPlanReportStruct);
//使用LinkedHashMap是为了确保reportId的一致性同时保证顺序 testPlanReportStruct.setScenarioAllCases(validScenarioList);
Map<String, TestPlanScenarioDTO> errorScenarioDTOMap = new LinkedHashMap<>(); List<TestPlanScenarioDTO> errorScenarioList = this.getScenarioListByStatus(testPlanReportStruct, "error");
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getScenarioFailureCases())) { List<TestPlanScenarioDTO> fakeErrorScenarioList = this.getScenarioListByStatus(testPlanReportStruct, "fakeError");
testPlanReportStruct.getScenarioFailureCases().forEach(item -> { List<TestPlanScenarioDTO> unExecuteScenarioList = this.getScenarioListByStatus(testPlanReportStruct, "unExecute");
if (StringUtils.isNotBlank(item.getReportId())) { testPlanReportStruct.setScenarioFailureCases(errorScenarioList);
errorScenarioDTOMap.put(item.getReportId(), item); testPlanReportStruct.setErrorReportScenarios(fakeErrorScenarioList);
testPlanReportStruct.setUnExecuteScenarios(unExecuteScenarioList);
List<TestPlanApiDTO> validApiList = this.getValidApiList(testPlanReportStruct);
testPlanReportStruct.setApiAllCases(validApiList);
List<TestPlanApiDTO> errorApiList = this.getApiListByStatus(testPlanReportStruct, "error");
List<TestPlanApiDTO> fakeErrorApiList = this.getApiListByStatus(testPlanReportStruct, "fakeError");
List<TestPlanApiDTO> unExecuteApiList = this.getApiListByStatus(testPlanReportStruct, "unExecute");
testPlanReportStruct.setApiFailureCases(errorApiList);
testPlanReportStruct.setErrorReportCases(fakeErrorApiList);
testPlanReportStruct.setUnExecuteCases(unExecuteApiList);
}
private List<TestPlanApiDTO> getValidApiList(TestPlanReportDataStruct testPlanReportStruct) {
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getApiAllCases())) {
List<TestPlanApiDTO> allApiList = new ArrayList<>(testPlanReportStruct.getApiAllCases().stream().filter(item -> item.getReportId() != null).toList());
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getApiFailureCases())) {
for (TestPlanApiDTO item : testPlanReportStruct.getApiFailureCases()) {
if (StringUtils.isNotEmpty(item.getReportId()) && !this.isApiListContainsByReportId(allApiList, item)) {
allApiList.add(item);
}
}
}
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getErrorReportCases())) {
testPlanReportStruct.getErrorReportCases().forEach(item -> {
if (StringUtils.isNotEmpty(item.getReportId()) && !this.isApiListContainsByReportId(allApiList, item)) {
allApiList.add(item);
} }
}); });
} }
testPlanReportStruct.getScenarioAllCases().forEach(item -> { if (CollectionUtils.isNotEmpty(testPlanReportStruct.getUnExecuteScenarios())) {
if (StringUtils.equalsIgnoreCase(item.getLastResult(), "Fail")) { testPlanReportStruct.getUnExecuteCases().forEach(item -> {
errorScenarioDTOMap.put(item.getReportId(), item); if (StringUtils.isNotEmpty(item.getReportId()) && !this.isApiListContainsByReportId(allApiList, item)) {
} allApiList.add(item);
}); }
testPlanReportStruct.setScenarioFailureCases(new ArrayList<>(errorScenarioDTOMap.values())); });
}
return allApiList;
} else {
return new ArrayList<>(0);
} }
} }
private List<TestPlanScenarioDTO> getValidScenarioList(TestPlanReportDataStruct testPlanReportStruct) {
//旧版本fastJson解析的数据结构不会保存所有的数据内存地址相同的数据它会做一个引用这里要补全数据结构
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getScenarioAllCases())) {
List<TestPlanScenarioDTO> allTestPlanScenariODTOList = new ArrayList<>(testPlanReportStruct.getScenarioAllCases().stream().filter(item -> item.getReportId() != null).toList());
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getScenarioFailureCases())) {
testPlanReportStruct.getScenarioFailureCases().forEach(item -> {
if (StringUtils.isNotEmpty(item.getReportId()) && !this.isScenarioListContainsByReportId(allTestPlanScenariODTOList, item)) {
allTestPlanScenariODTOList.add(item);
}
});
}
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getErrorReportScenarios())) {
testPlanReportStruct.getErrorReportScenarios().forEach(item -> {
if (StringUtils.isNotEmpty(item.getReportId()) && !this.isScenarioListContainsByReportId(allTestPlanScenariODTOList, item)) {
allTestPlanScenariODTOList.add(item);
}
});
}
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getUnExecuteScenarios())) {
testPlanReportStruct.getUnExecuteScenarios().forEach(item -> {
if (StringUtils.isNotEmpty(item.getReportId()) && !this.isScenarioListContainsByReportId(allTestPlanScenariODTOList, item)) {
allTestPlanScenariODTOList.add(item);
}
});
}
return allTestPlanScenariODTOList;
} else {
return new ArrayList<>(0);
}
}
private List<TestPlanApiDTO> getApiListByStatus(TestPlanReportDataStruct testPlanReportStruct, String status) {
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getApiAllCases())) {
//使用LinkedHashMap是为了确保reportId的一致性同时保证顺序
Map<String, TestPlanApiDTO> errorApiDTOMap = new LinkedHashMap<>();
List<String> checkStatusList;
List<TestPlanApiDTO> statusApiList = null;
if (StringUtils.equalsIgnoreCase(status, "fakeError")) {
checkStatusList = new ArrayList<>() {{
this.add("errorReport".toLowerCase());
this.add("errorReportResult".toLowerCase());
}};
statusApiList = testPlanReportStruct.getErrorReportCases().stream().filter(item -> item.getReportId() != null).toList();
} else if (StringUtils.equalsIgnoreCase(status, "unExecute")) {
checkStatusList = new ArrayList<>() {{
this.add("stop".toLowerCase());
this.add("unExecute".toLowerCase());
}};
statusApiList = testPlanReportStruct.getUnExecuteCases().stream().filter(item -> item.getReportId() != null).toList();
} else if (StringUtils.equalsIgnoreCase(status, "error")) {
checkStatusList = new ArrayList<>() {{
this.add("Error".toLowerCase());
}};
statusApiList = testPlanReportStruct.getApiFailureCases().stream().filter(item -> item.getReportId() != null).toList();
} else {
checkStatusList = null;
statusApiList = new ArrayList<>();
}
if (CollectionUtils.isNotEmpty(statusApiList)) {
statusApiList.forEach(item -> {
if (StringUtils.isNotBlank(item.getReportId())) {
errorApiDTOMap.put(item.getReportId(), item);
}
});
}
if (CollectionUtils.isNotEmpty(checkStatusList)) {
testPlanReportStruct.getApiAllCases().forEach(item -> {
if (checkStatusList.contains(item.getExecResult().toLowerCase())) {
errorApiDTOMap.put(item.getReportId(), item);
}
});
}
return new ArrayList<>(errorApiDTOMap.values());
} else {
return new ArrayList<>(0);
}
}
private List<TestPlanScenarioDTO> getScenarioListByStatus(TestPlanReportDataStruct testPlanReportStruct, String status) {
if (CollectionUtils.isNotEmpty(testPlanReportStruct.getScenarioAllCases())) {
//使用LinkedHashMap是为了确保reportId的一致性同时保证顺序
Map<String, TestPlanScenarioDTO> statusScenarioDTOMap = new LinkedHashMap<>();
List<String> checkStatusList;
List<TestPlanScenarioDTO> statusScenarioList = null;
if (StringUtils.equalsIgnoreCase(status, "fakeError")) {
checkStatusList = new ArrayList<>() {{
this.add("errorReport".toLowerCase());
this.add("errorReportResult".toLowerCase());
}};
statusScenarioList = testPlanReportStruct.getErrorReportScenarios().stream().filter(item -> item.getReportId() != null).toList();
} else if (StringUtils.equalsIgnoreCase(status, "unExecute")) {
checkStatusList = new ArrayList<>() {{
this.add("unExecute".toLowerCase());
this.add("stop".toLowerCase());
}};
statusScenarioList = testPlanReportStruct.getUnExecuteScenarios().stream().filter(item -> item.getReportId() != null).toList();
} else if (StringUtils.equalsIgnoreCase(status, "error")) {
checkStatusList = new ArrayList<>() {{
this.add("Fail".toLowerCase());
this.add("Error".toLowerCase());
}};
statusScenarioList = testPlanReportStruct.getScenarioFailureCases().stream().filter(item -> item.getReportId() != null).toList();
} else {
checkStatusList = null;
statusScenarioList = new ArrayList<>();
}
if (CollectionUtils.isNotEmpty(statusScenarioList)) {
statusScenarioList.forEach(item -> {
if (StringUtils.isNotBlank(item.getReportId())) {
statusScenarioDTOMap.put(item.getReportId(), item);
}
});
}
if (CollectionUtils.isNotEmpty(checkStatusList)) {
testPlanReportStruct.getScenarioAllCases().forEach(item -> {
if (checkStatusList.contains(item.getLastResult().toLowerCase())) {
statusScenarioDTOMap.put(item.getReportId(), item);
}
});
}
return new ArrayList<>(statusScenarioDTOMap.values());
} else {
return new ArrayList<>(0);
}
}
private boolean isApiListContainsByReportId(List<TestPlanApiDTO> list, TestPlanApiDTO checkItem) {
if (CollectionUtils.isNotEmpty(list)) {
for (TestPlanApiDTO item : list) {
if (StringUtils.equals(item.getReportId(), checkItem.getReportId())) {
return true;
}
}
}
return false;
}
private boolean isScenarioListContainsByReportId(List<TestPlanScenarioDTO> list, TestPlanScenarioDTO checkItem) {
if (CollectionUtils.isNotEmpty(list)) {
for (TestPlanScenarioDTO item : list) {
if (StringUtils.equals(item.getReportId(), checkItem.getReportId())) {
return true;
}
}
}
return false;
}
//获取已生成过的测试计划报告内容 //获取已生成过的测试计划报告内容
private TestPlanReportDataStruct getTestPlanReportStructByCreated(TestPlanReportContentWithBLOBs private TestPlanReportDataStruct getTestPlanReportStructByCreated(TestPlanReportContentWithBLOBs
testPlanReportContentWithBLOBs) { testPlanReportContentWithBLOBs) {

View File

@ -13,7 +13,7 @@ import java.util.function.Function;
*/ */
public class BatchProcessingUtil { public class BatchProcessingUtil {
private static final int BATCH_PROCESS_QUANTITY = 2000; private static final int BATCH_PROCESS_QUANTITY = 100;
public static List<TestCaseTest> selectTestCaseTestByPrimaryKey(List<String> primaryKeyList, Function<TestCaseTestExample, List<TestCaseTest>> func) { public static List<TestCaseTest> selectTestCaseTestByPrimaryKey(List<String> primaryKeyList, Function<TestCaseTestExample, List<TestCaseTest>> func) {
List<TestCaseTest> returnList = new ArrayList<>(); List<TestCaseTest> returnList = new ArrayList<>();