use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class TEIimportTest method teisShouldBeUpdatedAndDeletedInBulk.
@Test
public void teisShouldBeUpdatedAndDeletedInBulk() {
// arrange
JsonArray teis = object.getAsJsonArray("trackedEntityInstances");
JsonObject tei1event = teis.get(0).getAsJsonObject().getAsJsonArray("enrollments").get(0).getAsJsonObject().getAsJsonArray("events").get(0).getAsJsonObject();
JsonObject tei2enrollment = teis.get(1).getAsJsonObject().getAsJsonArray("enrollments").get(0).getAsJsonObject();
tei1event.addProperty("deleted", true);
tei2enrollment.addProperty("status", "COMPLETED");
// act
ApiResponse response = teiActions.post(object, new QueryParamsBuilder().addAll("strategy=SYNC"));
// assert
String eventId = response.validate().statusCode(200).body("response", notNullValue()).rootPath("response").body("updated", Matchers.greaterThanOrEqualTo(2)).appendRootPath("importSummaries[0]").body("importCount.updated", greaterThanOrEqualTo(1)).appendRootPath("enrollments.importSummaries[0].events.importSummaries[0]").body("status", Matchers.equalTo("SUCCESS"), "reference", notNullValue(), "importCount.deleted", Matchers.equalTo(1), "description", Matchers.stringContainsInOrder("Deletion of event", "was successful")).extract().path("response.importSummaries[0].enrollments.importSummaries[0].events.importSummaries[0].reference");
String enrollmentId = response.validate().rootPath("response.importSummaries[1].enrollments.importSummaries[0]").body("status", Matchers.equalTo("SUCCESS"), "reference", notNullValue(), "importCount.updated", Matchers.equalTo(1)).extract().path("response.importSummaries[1].enrollments.importSummaries[0].reference");
// check if updates on event and enrollment were done.
response = enrollmentActions.get(enrollmentId);
response.validate().statusCode(200).body("status", Matchers.equalTo("COMPLETED"));
response = eventActions.get(eventId);
response.validate().statusCode(404);
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class EnrollmentsUpdateTests method shouldNotUpdateImmutableProperties.
@Test
public void shouldNotUpdateImmutableProperties() throws Exception {
String enrollmentId = importEnrollment();
String program = new ProgramActions().createProgram("WITH_REGISTRATION").extractUid();
JsonObject body = trackerActions.get("/enrollments/" + enrollmentId).getBody();
body = JsonObjectBuilder.jsonObject(body).addProperty("enrollment", enrollmentId).addProperty("trackedEntity", importTei()).addProperty("program", program).wrapIntoArray("enrollments");
trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=UPDATE")).validateErrorReport().body("", hasSize(Matchers.greaterThanOrEqualTo(2))).body("errorCode", hasItems("E1127", "E1127")).body("message", Matchers.hasItem(Matchers.containsString("trackedEntity"))).body("message", Matchers.hasItem(Matchers.containsString("program")));
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class EventsTests method eventsImportNewEventsFromFile.
@ParameterizedTest
@MethodSource("provideEventFilesTestArguments")
public void eventsImportNewEventsFromFile(String fileName, String contentType) throws Exception {
Object obj = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/events/" + fileName)).replacePropertyValuesWithIds("event").get();
ApiResponse response = trackerActions.post("", contentType, obj, new QueryParamsBuilder().addAll("dryRun=false", "eventIdScheme=UID", "orgUnitIdScheme=UID"));
response.validate().statusCode(200);
String jobId = response.extractString("response.id");
trackerActions.waitUntilJobIsCompleted(jobId);
response = trackerActions.getJobReport(jobId, "FULL");
response.validate().statusCode(200).body("status", equalTo("OK"));
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class RelationshipsTests method shouldNotImportDuplicateRelationships.
@MethodSource("provideDuplicateRelationshipData")
@ParameterizedTest(name = "{index} {6}")
public void shouldNotImportDuplicateRelationships(String fromTei1, String toTei1, String fromTei2, String toTei2, boolean bidirectional, int expectedCount, String representation) {
// arrange
String relationshipTypeId = relationshipTypeActions.get("", new QueryParamsBuilder().addAll("filter=fromConstraint.relationshipEntity:eq:TRACKED_ENTITY_INSTANCE", "filter=toConstraint.relationshipEntity:eq:TRACKED_ENTITY_INSTANCE", "filter=bidirectional:eq:" + bidirectional, "filter=name:like:TA")).extractString("relationshipTypes.id[0]");
JsonObject relationship1 = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relationshipTypeId).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", fromTei1)).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", toTei1)).build();
JsonObject relationship2 = JsonObjectBuilder.jsonObject().addProperty("relationshipType", relationshipTypeId).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", fromTei2)).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", toTei2)).build();
JsonObject payload = JsonObjectBuilder.jsonObject().addArray("relationships", relationship1, relationship2).build();
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(payload);
// assert
response.validateSuccessfulImport().validate().body("stats.created", equalTo(expectedCount));
createdRelationships = response.extractImportedRelationships();
}
use of org.hisp.dhis.helpers.QueryParamsBuilder in project dhis2-core by dhis2.
the class RelationshipsTests method shouldNotUpdateRelationship.
@Test
public void shouldNotUpdateRelationship() {
// arrange
String relationshipId = new IdGenerator().generateUniqueId();
JsonObject relationship = JsonObjectBuilder.jsonObject().addProperty("relationship", relationshipId).addProperty("relationshipType", relationshipType).addObject("from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0))).addObject("to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1))).wrapIntoArray("relationships");
trackerActions.postAndGetJobReport(relationship).validate().statusCode(200);
JsonObject relationshipBody = trackerActions.get("/relationships/" + relationshipId).getBody();
JsonObjectBuilder.jsonObject(relationship).addObjectByJsonPath("relationships[0]", "from", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(1)).build()).addObjectByJsonPath("relationships[0]", "to", JsonObjectBuilder.jsonObject().addProperty("trackedEntity", teis.get(0)).build()).build();
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(relationship, new QueryParamsBuilder().add("importStrategy=UPDATE"));
// assert
response.validateErrorReport();
assertThat(trackerActions.get("/relationships/" + relationshipId).getBody(), matchesJSON(relationshipBody));
}
Aggregations