Skip to content

Commit

Permalink
test: tracker import and input include [DHIS2-15276]
Browse files Browse the repository at this point in the history
  • Loading branch information
jbee committed Nov 20, 2023
1 parent 13cee5a commit 6d3a0d1
Showing 1 changed file with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,55 @@ void testGetJobRunErrors_ObjectProgressErrors() {
assertEquals(1, errors.size());
}

@Test
void testGetJobRunErrors_ListIncludeInput() throws InterruptedException {
// language=JSON
String json =
"""
{
"trackedEntities": [
{
"trackedEntity":"sHH8mh1Fn0z",
"trackedEntityType": "nEenWmSyUEp",
"orgUnit": "DiszpKrYNg7"
}
]
}
""";
JsonWebMessage msg =
POST("/tracker?async=true", json).content(HttpStatus.OK).as(JsonWebMessage.class);
String jobId = msg.getString("response.id").string();
waitUntilJobIsComplete(jobId);

JsonArray errors = GET("/jobConfigurations/errors?includeInput=true").content();
assertEquals(2, errors.size());
JsonObject trackerImportError =
errors.asList(JsonObject.class).stream()
.filter(obj -> obj.getString("id").string().equals(jobId))
.findFirst()
.orElseThrow();

// language=JSON
String expected =
"""
{"trackedEntities":[{"trackedEntity":"sHH8mh1Fn0z","trackedEntityType":{"idScheme":"UID","identifier":"nEenWmSyUEp"},"orgUnit":{"idScheme":"UID","identifier":"DiszpKrYNg7"},"inactive":false,"deleted":false,"potentialDuplicate":false,"relationships":[],"attributes":[],"enrollments":[]}],"enrollments":[],"events":[],"relationships":[]}""";
assertEquals(expected, trackerImportError.getObject("input").node().getDeclaration());
}

private String createAndRunImportWithErrors() throws InterruptedException {
JsonWebMessage message =
POST(
"/metadata?async=true",
"{'organisationUnits':[{'name':'My Unit', 'shortName':'OU1'}]}")
.content(HttpStatus.OK)
.as(JsonWebMessage.class);
String jobId = message.getString("response.id").string();
String json = "{'organisationUnits':[{'name':'My Unit', 'shortName':'OU1'}]}";
JsonWebMessage msg =
POST("/metadata?async=true", json).content(HttpStatus.OK).as(JsonWebMessage.class);
String jobId = msg.getString("response.id").string();

waitUntilJobIsComplete(jobId);
return jobId;
}

private void waitUntilJobIsComplete(String jobId) throws InterruptedException {
BooleanSupplier jobCompleted =
() -> isDone(GET("/jobConfigurations/{id}/gist?fields=id,jobStatus", jobId).content());
assertTrue(await(ofSeconds(10), jobCompleted), "import did not run");
return jobId;
}

private static boolean isDone(JsonMixed config) {
Expand Down

0 comments on commit 6d3a0d1

Please sign in to comment.