Search in sources :

Example 21 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class TrackerNtiApiTest method importTeiWithEnrollmentAndEvent.

protected TrackerApiResponse importTeiWithEnrollmentAndEvent(String orgUnit, String programId, String programStageId) throws Exception {
    JsonObject teiWithEnrollment = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/teis/teiWithEnrollmentAndEventsNested.json")).replacePropertyValuesRecursivelyWith("orgUnit", orgUnit).replacePropertyValuesRecursivelyWith("program", programId).replacePropertyValuesRecursivelyWith("programStage", programStageId).get(JsonObject.class);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(teiWithEnrollment);
    response.validateSuccessfulImport();
    return response;
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File)

Example 22 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EnrollmentsTests method shouldOnlyEnrollOnce.

@ValueSource(strings = { "true", "false" })
@ParameterizedTest
public void shouldOnlyEnrollOnce(String shouldEnrollOnce) throws Exception {
    // arrange
    String program = programActions.createTrackerProgram(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS).extractUid();
    JsonObject object = programActions.get(program).getBodyAsJsonBuilder().addProperty("onlyEnrollOnce", shouldEnrollOnce).addProperty("publicAccess", "rwrw----").build();
    programActions.update(program, object).validateStatus(200);
    String tei = super.importTei();
    JsonObject enrollment = new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).array(program, Constants.ORG_UNIT_IDS[2], tei, "COMPLETED");
    trackerActions.postAndGetJobReport(enrollment).validateSuccessfulImport();
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(new EnrollmentDataBuilder().array(program, Constants.ORG_UNIT_IDS[2], tei, "ACTIVE"));
    // assert
    if (Boolean.parseBoolean(shouldEnrollOnce)) {
        response.validateErrorReport().body("errorCode", hasItems("E1016"));
        return;
    }
    response.validateSuccessfulImport();
    trackerActions.getTrackedEntity(tei + "?fields=enrollments").validate().body("enrollments", hasSize(2));
}
Also used : JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) IdGenerator(org.hisp.dhis.actions.IdGenerator) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EnrollmentsTests method shouldImportTeisWithEnrollments.

@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teiWithEnrollments.json", "src/test/resources/tracker/importer/teis/teiAndEnrollment.json" })
public void shouldImportTeisWithEnrollments(String file) {
    TrackerApiResponse response = trackerActions.postAndGetJobReport(new File(file));
    response.validateSuccessfulImport().validate().body("status", Matchers.equalTo("OK")).body("stats.created", equalTo(2));
    response.validateTeis().body("stats.created", Matchers.equalTo(1));
    response.validateEnrollments().body("stats.created", Matchers.equalTo(1));
    // assert that the tei was imported
    String teiId = response.extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(200).body("trackedEntity", equalTo(teiId));
}
Also used : TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EnrollmentsTests method shouldImportEnrollmentToExistingTei.

@Test
public void shouldImportEnrollmentToExistingTei() throws Exception {
    String teiId = importTei();
    JsonObject enrollmentPayload = new FileReaderUtils().read(new File("src/test/resources/tracker/importer/enrollments/enrollment.json")).replacePropertyValuesWith("trackedEntity", teiId).get(JsonObject.class);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(enrollmentPayload);
    response.validateSuccessfulImport().validateEnrollments().body("stats.created", equalTo(1)).body("objectReports", notNullValue()).body("objectReports.uid", notNullValue());
    String enrollmentId = response.extractImportedEnrollments().get(0);
    ApiResponse enrollmentResponse = trackerActions.get("/enrollments/" + enrollmentId);
    assertThat(enrollmentResponse.getBody(), matchesJSON(enrollmentPayload.get("enrollments").getAsJsonArray().get(0).getAsJsonObject()));
}
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) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class EnrollmentsTests method shouldAllowFutureEnrollments.

@ParameterizedTest
@ValueSource(strings = { "true", "false " })
public void shouldAllowFutureEnrollments(String shouldAddFutureDays) throws Exception {
    // arrange
    JsonObject object = programActions.get(multipleEnrollmentsProgram).getBodyAsJsonBuilder().addProperty("selectEnrollmentDatesInFuture", shouldAddFutureDays).build();
    programActions.update(multipleEnrollmentsProgram, object).validateStatus(200);
    String teiId = importTei();
    // act
    JsonObject enrollment = new EnrollmentDataBuilder().setTei(teiId).setEnrollmentDate(Instant.now().plus(2, ChronoUnit.DAYS).toString()).addEvent(new EventDataBuilder().setProgram(multipleEnrollmentsProgram).setOu(Constants.ORG_UNIT_IDS[0]).setProgramStage(multipleEnrollmentsProgramStage)).array(multipleEnrollmentsProgram, Constants.ORG_UNIT_IDS[0]);
    // assert
    TrackerApiResponse response = trackerActions.postAndGetJobReport(enrollment, new QueryParamsBuilder().add("async", "false"));
    if (Boolean.parseBoolean(shouldAddFutureDays)) {
        response.validateSuccessfulImport();
        return;
    }
    response.validateErrorReport().body("errorCode", hasSize(1)).body("errorCode", hasItems("E1020"));
}
Also used : EventDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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