use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class TeiImportTests method shouldImportTeisWithEnrollmentsEventsAndRelationship.
@Test
public void shouldImportTeisWithEnrollmentsEventsAndRelationship() throws Exception {
// the file contains 2 teis with 1 enrollment and 1 event each
JsonObject teiPayload = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/teisWithEnrollmentsAndEvents.json"));
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(teiPayload);
response.validateSuccessfulImport().validate().body("stats.created", equalTo(7)).rootPath("bundleReport.typeReportMap").body("TRACKED_ENTITY.objectReports", hasSize(2)).body("ENROLLMENT.objectReports", hasSize(2)).body("EVENT.objectReports", hasSize(2)).body("RELATIONSHIP.objectReports", hasSize(1));
JsonObject teiBody = teiPayload.get("trackedEntities").getAsJsonArray().get(0).getAsJsonObject();
ApiResponse trackedEntityResponse = trackerActions.getTrackedEntity(teiBody.get("trackedEntity").getAsString() + "?fields=*").validateStatus(200);
assertThat(trackedEntityResponse.getBody(), matchesJSON(teiBody));
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class TeiImportTests method shouldImportTeiAndEnrollmentWithAttributes.
@Test
public void shouldImportTeiAndEnrollmentWithAttributes() throws Exception {
JsonObject teiBody = new FileReaderUtils().readJsonAndGenerateData(new File("src/test/resources/tracker/importer/teis/teiWithEnrollmentAndAttributes.json"));
// act
TrackerApiResponse response = trackerActions.postAndGetJobReport(teiBody);
// assert
response.validateSuccessfulImport().validate().body("stats.created", equalTo(2)).rootPath("bundleReport.typeReportMap").body("TRACKED_ENTITY.objectReports", hasSize(1)).body("ENROLLMENT.objectReports", hasSize(1));
// assert that the TEI was imported
String teiId = response.extractImportedTeis().get(0);
ApiResponse teiResponse = trackerActions.getTrackedEntity(teiId);
teiResponse.validate().statusCode(200);
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class PotentialDuplicatesEnrollmentsTests method shouldAutoMergeWithEnrollmentsAndEvents.
@Test
public void shouldAutoMergeWithEnrollmentsAndEvents() throws IOException {
// arrange
TrackerApiResponse originalTeiResponse = createTeiWithEnrollmentsAndEvents(Constants.ANOTHER_TRACKER_PROGRAM_ID, "PaOOjwLVW2X");
String teiA = originalTeiResponse.extractImportedTeis().get(0);
String enrollmentA = originalTeiResponse.extractImportedEnrollments().get(0);
TrackerApiResponse duplicateTeiResponse = trackerActions.postAndGetJobReport(new JsonFileReader(new File("src/test/resources/tracker/importer/teis/teiWithEnrollmentAndEventsNested.json")).get());
String teiB = duplicateTeiResponse.extractImportedTeis().get(0);
String enrollmentB = duplicateTeiResponse.extractImportedEnrollments().get(0);
String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
// act
potentialDuplicatesActions.autoMergePotentialDuplicate(potentialDuplicate).validate().statusCode(200);
// assert
potentialDuplicatesActions.get(potentialDuplicate).validate().statusCode(200).body("status", equalTo("MERGED"));
trackerActions.getTrackedEntity(teiA + "?fields=*").validate().statusCode(200).body("enrollments", hasSize(2)).body("enrollments.enrollment", hasItems(enrollmentA, enrollmentB)).rootPath(String.format("enrollments.find{it.enrollment=='%s'}", enrollmentA)).body("events", hasSize(greaterThanOrEqualTo(1))).body("events.dataValues", hasSize(greaterThanOrEqualTo(1))).noRootPath().rootPath(String.format("enrollments.find{it.enrollment=='%s'}", enrollmentB)).body("events", hasSize(greaterThanOrEqualTo(1))).body("events.dataValues", hasSize(greaterThanOrEqualTo(1)));
trackerActions.getTrackedEntity(teiB).validate().statusCode(404);
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class PotentialDuplicatesEnrollmentsTests method shouldMergeWithNonSuperUser.
@Test
public void shouldMergeWithNonSuperUser() {
// arrange
String teiB = createTeiWithoutEnrollment(Constants.ORG_UNIT_IDS[0]);
TrackerApiResponse imported = trackerActions.postAndGetJobReport(new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], TRACKER_PROGRAM_ID, TRACKER_PROGRAM_STAGE_ID)).validateSuccessfulImport();
String teiA = imported.extractImportedTeis().get(0);
String enrollment = imported.extractImportedEnrollments().get(0);
assertThat(enrollment, notNullValue());
String potentialDuplicate = potentialDuplicatesActions.createAndValidatePotentialDuplicate(teiA, teiB, "OPEN");
String username = createUserWithAccessToMerge();
loginActions.loginAsUser(username, USER_PASSWORD);
// act
potentialDuplicatesActions.autoMergePotentialDuplicate(potentialDuplicate).validate().statusCode(200);
// assert
potentialDuplicatesActions.get(potentialDuplicate).validate().statusCode(200).body("status", equalTo("MERGED"));
trackerActions.getTrackedEntity(teiA + "?fields=*").validate().statusCode(200).body("enrollments", hasSize(1)).body("enrollments.enrollment", hasItems(enrollment)).body(String.format("enrollments.find{it.enrollment=='%s'}.events", enrollment), hasSize(1));
trackerActions.getTrackedEntity(teiB).validate().statusCode(404);
}
use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.
the class PotentialDuplicatesEnrollmentsTests method shouldBeManuallyMerged.
@Test
public void shouldBeManuallyMerged() {
String teiA = createTeiWithEnrollmentsAndEvents(TRACKER_PROGRAM_ID, TRACKER_PROGRAM_STAGE_ID).extractImportedTeis().get(0);
TrackerApiResponse teiBResponse = createTeiWithEnrollmentsAndEvents(Constants.ANOTHER_TRACKER_PROGRAM_ID, "PaOOjwLVW2X");
String teiB = teiBResponse.extractImportedTeis().get(0);
String enrollmentToMerge = teiBResponse.extractImportedEnrollments().get(0);
String potentialDuplicate = potentialDuplicatesActions.createPotentialDuplicate(teiA, teiB, "OPEN").validateStatus(200).extractString("id");
potentialDuplicatesActions.manualMergePotentialDuplicate(potentialDuplicate, new JsonObjectBuilder().addArray("enrollments", Arrays.asList(enrollmentToMerge)).build()).validate().statusCode(200);
trackerActions.getTrackedEntity(teiA + "?fields=enrollments").validate().statusCode(200).body("enrollments", hasSize(2));
}
Aggregations