Skip to content

Commit

Permalink
ISSUE #14851: Error when deleting last test case result (#14868)
Browse files Browse the repository at this point in the history
* fix: error if no testCaseResult exists when updating testSuite summary state

* fix: add return statement on resultsummaries update
  • Loading branch information
TeddyCr authored Jan 28, 2024
1 parent 0332fb9 commit bd09755
Showing 1 changed file with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,26 +401,14 @@ private void setTestSuiteSummary(
}

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()
Expand All @@ -431,6 +419,30 @@ private void setTestSuiteSummary(
}
}

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()
Expand Down

0 comments on commit bd09755

Please sign in to comment.