Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only restrict set of checks when executing them [DHIS2-16256] #15840

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: limit asserts so side effects from other tests don't fail the te…
…st [DHIS2-16256]
  • Loading branch information
jbee committed Dec 6, 2023
commit 4a4db1e0880236818b5a07cacb6605f102b722b8
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.hisp.dhis.web.HttpStatus;
import org.hisp.dhis.webapi.DhisControllerIntegrationTest;
import org.hisp.dhis.webapi.json.domain.JsonDataIntegrityDetails;
import org.hisp.dhis.webapi.json.domain.JsonDataIntegrityDetails.JsonDataIntegrityIssue;
import org.hisp.dhis.webapi.json.domain.JsonDataIntegritySummary;
import org.hisp.dhis.webapi.json.domain.JsonWebMessage;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -95,7 +96,7 @@ void checkDataIntegritySummary(
}
}

private Boolean hasComments(JsonList<JsonDataIntegrityDetails.JsonDataIntegrityIssue> issues) {
private Boolean hasComments(JsonList<JsonDataIntegrityIssue> issues) {
return issues.stream()
.map(issue -> issue.has("comment"))
.reduce(Boolean.FALSE, Boolean::logicalOr);
Expand All @@ -110,7 +111,7 @@ void checkDataIntegrityDetailsIssues(
postDetails(check);

JsonDataIntegrityDetails details = getDetails(check);
JsonList<JsonDataIntegrityDetails.JsonDataIntegrityIssue> issues = details.getIssues();
JsonList<JsonDataIntegrityIssue> issues = details.getIssues();
assertTrue(issues.exists());
assertEquals(1, issues.size());

Expand Down Expand Up @@ -143,13 +144,14 @@ void checkDataIntegrityDetailsIssues(
postDetails(check);

JsonDataIntegrityDetails details = getDetails(check);
JsonList<JsonDataIntegrityDetails.JsonDataIntegrityIssue> issues = details.getIssues();
JsonList<JsonDataIntegrityIssue> issues = details.getIssues();

assertTrue(issues.exists());
assertEquals(expectedDetailsUnits.size(), issues.size());

/* Always check the UIDs */
Set<String> issueUIDs = issues.stream().map(issue -> issue.getId()).collect(Collectors.toSet());
Set<String> issueUIDs =
issues.stream().map(JsonDataIntegrityIssue::getId).collect(Collectors.toSet());
assertEquals(issueUIDs, expectedDetailsUnits);

/*
Expand All @@ -158,7 +160,7 @@ void checkDataIntegrityDetailsIssues(
*/
if (!expectedDetailsNames.isEmpty()) {
Set<String> detailsNames =
issues.stream().map(issue -> issue.getName()).collect(Collectors.toSet());
issues.stream().map(JsonDataIntegrityIssue::getName).collect(Collectors.toSet());
assertEquals(expectedDetailsNames, detailsNames);
}
/* This can be empty if comments do not exist in the JSON response. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,21 @@ void testLegacyChecksHaveSummary() {
JsonDataIntegritySummary summary = getSummary(check);
assertTrue(summary.getCount() >= 0, "summary threw an exception");
}

// check if the summary map returns results for the programmatic checks
JsonMap<JsonDataIntegritySummary> checksByName =
GET("/dataIntegrity/summary?timeout=1000").content().asMap(JsonDataIntegritySummary.class);
assertFalse(checksByName.isEmpty());
checksByName.forEach((name, summary) -> assertTrue(summary.getIsSlow()));
int checked = 0;
for (DataIntegrityCheckType type : DataIntegrityCheckType.values()) {
String name = type.getName().replace("-", "_");
JsonDataIntegritySummary summary = checksByName.get(name);
if (summary.exists()) { // not all checks might be done by now
assertTrue(summary.getIsSlow());
checked++;
}
}
assertTrue(checked > 0, "at least one of the slow test should have been completed");
}

@Test
Expand Down