Search in sources :

Example 11 with TeiDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.

the class EventExportTests method setupTrackerEvents.

private void setupTrackerEvents() {
    Arrays.asList(captureOu, dataReadOu, searchOu, rootOu).forEach(ou -> {
        JsonObject object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, ou, withRegistrationProgram, withRegistrationProgramStage);
        String eventId = new TrackerActions().postAndGetJobReport(object).validateSuccessfulImport().extractImportedEvents().get(0);
        trackerEvents.put(ou, eventId);
        // closed program events
        object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, ou, closedProgramId, closedProgramProgramStageId);
        eventId = new TrackerActions().postAndGetJobReport(object, new QueryParamsBuilder().add("async", "false")).validateSuccessfulImport().extractImportedEvents().get(0);
        closedProgramEvents.put(ou, eventId);
    });
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) TrackerActions(org.hisp.dhis.actions.tracker.importer.TrackerActions) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 12 with TeiDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.

the class ImportStrategyTests method shouldDeleteReferencingEventsWhenEnrollmentIsDeleted.

@Test
public void shouldDeleteReferencingEventsWhenEnrollmentIsDeleted() {
    // arrange
    JsonObject body = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], Constants.TRACKER_PROGRAM_ID, "PaOOjwLVW23");
    TrackerApiResponse response = trackerActions.postAndGetJobReport(body).validateSuccessfulImport();
    String teiId = response.extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    String eventId1 = response.extractImportedEvents().get(0);
    body = trackerActions.getEnrollment(enrollmentId).validateStatus(200).getBodyAsJsonBuilder().wrapIntoArray("enrollments");
    // act
    response = trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=DELETE")).validateSuccessfulImport();
    // assert
    response.validateSuccessfulImport().validate().body("stats.deleted", Matchers.equalTo(1));
    trackerActions.getTrackedEntity(teiId + "?fields=*").validate().statusCode(200).body("enrollments", hasSize(0));
    trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(404);
    trackerActions.get("/events/" + eventId1).validate().statusCode(404);
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with TeiDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder in project dhis2-core by dhis2.

the class RuleEngineTests method shouldAddErrorForEnrollmentsAndEventsWhenRuleHasNoStage.

@Test
public void shouldAddErrorForEnrollmentsAndEventsWhenRuleHasNoStage() {
    JsonObject object = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], trackerProgramId, "yKg8CY252Yk");
    JsonObjectBuilder.jsonObject(object).addPropertyByJsonPath("trackedEntities[0].enrollments[0].enrolledAt", Instant.now().minus(1, ChronoUnit.DAYS).toString());
    // act
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object);
    response.validateWarningReport().body("", hasSize(greaterThanOrEqualTo(1))).body("trackerType", hasItems("ENROLLMENT")).body("warningCode", everyItem(equalTo("E1300")));
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)13 JsonObject (com.google.gson.JsonObject)11 Test (org.junit.jupiter.api.Test)9 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)8 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)5 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 RestApiActions (org.hisp.dhis.actions.RestApiActions)1 UserActions (org.hisp.dhis.actions.UserActions)1 OrgUnitActions (org.hisp.dhis.actions.metadata.OrgUnitActions)1 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)1 TrackerActions (org.hisp.dhis.actions.tracker.importer.TrackerActions)1 ApiResponse (org.hisp.dhis.dto.ApiResponse)1 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)1 CsvSource (org.junit.jupiter.params.provider.CsvSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1