ISSUE #14851: Error when deleting last test case result (#14868)

* fix: error if no testCaseResult exists when updating testSuite summary state

* fix: add return statement on resultsummaries update
This commit is contained in:
Teddy 2024-01-28 19:27:05 +01:00 committed by GitHub
parent 0332fb9fe5
commit bd09755fc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -401,26 +401,14 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
}
if (storedResultSummary != null) {
// if the state already exists then we'll remove it before adding the new one
resultSummaries.removeIf(
summary -> summary.getTestCaseName().equals(resultSummary.getTestCaseName()));
}
if (!isDeleted) {
resultSummaries.add(resultSummary);
} else {
// Add the latest state when removing a state
String json =
daoCollection
.dataQualityDataTimeSeriesDao()
.getLatestExtension(testCase.getFullyQualifiedName(), TESTCASE_RESULT_EXTENSION);
TestCaseResult testCaseResult = JsonUtils.readValue(json, TestCaseResult.class);
ResultSummary newResultSummary =
getResultSummary(
testCase, testCaseResult.getTimestamp(), testCaseResult.getTestCaseStatus());
resultSummaries.add(newResultSummary);
}
updateResultSummaries(testCase, isDeleted, resultSummaries, resultSummary);
// Update test case result summary for the test suite
// Update test case result summary attribute for the test suite
testSuite.setTestCaseResultSummary(resultSummaries);
daoCollection
.testSuiteDAO()
@ -431,6 +419,30 @@ public class TestCaseRepository extends EntityRepository<TestCase> {
}
}
private void updateResultSummaries(
TestCase testCase,
boolean isDeleted,
List<ResultSummary> resultSummaries,
ResultSummary resultSummary) {
if (!isDeleted) {
resultSummaries.add(resultSummary);
return;
}
// If the result was deleted, we need to update the summary
// with the latest one from the database (if one exists)
String json =
daoCollection
.dataQualityDataTimeSeriesDao()
.getLatestExtension(testCase.getFullyQualifiedName(), TESTCASE_RESULT_EXTENSION);
if (json != null) {
TestCaseResult testCaseResult = JsonUtils.readValue(json, TestCaseResult.class);
ResultSummary newResultSummary =
getResultSummary(
testCase, testCaseResult.getTimestamp(), testCaseResult.getTestCaseStatus());
resultSummaries.add(newResultSummary);
}
}
private ResultSummary findMatchingResultSummary(
List<ResultSummary> resultSummaries, String testCaseNameToMatch) {
return resultSummaries.stream()