Search in sources :

Example 16 with TrackerApiResponse

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));
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 17 with TrackerApiResponse

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);
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 18 with TrackerApiResponse

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);
}
Also used : TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) JsonFileReader(org.hisp.dhis.helpers.file.JsonFileReader) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Example 19 with TrackerApiResponse

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);
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Example 20 with TrackerApiResponse

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));
}
Also used : TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) PotentialDuplicatesApiTest(org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)53 JsonObject (com.google.gson.JsonObject)44 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)32 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)17 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)15 File (java.io.File)14 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)11 ApiResponse (org.hisp.dhis.dto.ApiResponse)9 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)8 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)5 CsvSource (org.junit.jupiter.params.provider.CsvSource)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)3 EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)3 IdGenerator (org.hisp.dhis.actions.IdGenerator)2 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)2 JsonFileReader (org.hisp.dhis.helpers.file.JsonFileReader)1