Search in sources :

Example 1 with EnrollmentDataBuilder

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

the class RuleEngineTests method shouldShowErrorOnCompleteInTrackerEvents.

@Test
public void shouldShowErrorOnCompleteInTrackerEvents() throws Exception {
    String tei = importTei();
    JsonObject enrollment = new EnrollmentDataBuilder().setTei(tei).setEnrollmentDate(Instant.now().plus(1, ChronoUnit.DAYS).toString()).array(trackerProgramId, Constants.ORG_UNIT_IDS[0]);
    String enrollmentId = trackerActions.postAndGetJobReport(enrollment).validateSuccessfulImport().extractImportedEnrollments().get(0);
    JsonObject payload = new EventDataBuilder().setEnrollment(enrollmentId).setStatus("COMPLETED").array(Constants.ORG_UNIT_IDS[0], trackerProgramId, "nH8zfPSUSN1");
    trackerActions.postAndGetJobReport(payload, new QueryParamsBuilder().add("async=false")).validateErrorReport().body("trackerType", hasItem("EVENT")).body("message", hasItem(stringContainsInOrder("ERROR ON COMPLETE ")));
}
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) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with EnrollmentDataBuilder

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

the class OwnershipTests method shouldNotValidateOwnershipIfProgramIsOpen.

@Test
public void shouldNotValidateOwnershipIfProgramIsOpen() {
    loginActions.loginAsUser(username, userPassword);
    trackerActions.getTrackedEntity(teiInSearchScope + "?fields=enrollments").validate().statusCode(200).body("enrollments", hasSize(0));
    trackerActions.postAndGetJobReport(new EnrollmentDataBuilder().array(openProgram, captureOu, teiInCaptureScope, "ACTIVE")).validateSuccessfulImport();
}
Also used : EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with EnrollmentDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder 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 4 with EnrollmentDataBuilder

use of org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder 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)

Example 5 with EnrollmentDataBuilder

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

the class EnrollmentAttributeTests method shouldValidateUniquenessWithinThePayload.

@Test
public void shouldValidateUniquenessWithinThePayload() throws Exception {
    String tei = importTei();
    String teiB = importTei();
    String value = DataGenerator.randomString();
    Function<String, JsonObject> singleEnrollment = (teiId) -> {
        return new EnrollmentDataBuilder().setId(new IdGenerator().generateUniqueId()).setTei(teiId).addAttribute(uniqueAttributeId, value).setProgram(programId).setOu(Constants.ORG_UNIT_IDS[1]).single();
    };
    JsonObject payload = new JsonObjectBuilder().addOrAppendToArray("enrollments", singleEnrollment.apply(tei), singleEnrollment.apply(teiB)).build();
    trackerActions.postAndGetJobReport(payload).validateErrorReport();
}
Also used : JsonObject(com.google.gson.JsonObject) DataGenerator(org.hisp.dhis.utils.DataGenerator) BeforeEach(org.junit.jupiter.api.BeforeEach) Constants(org.hisp.dhis.Constants) Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) IdGenerator(org.hisp.dhis.actions.IdGenerator) ProgramActions(org.hisp.dhis.actions.metadata.ProgramActions) Matchers(org.hamcrest.Matchers) Disabled(org.junit.jupiter.api.Disabled) Function(java.util.function.Function) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) TrackedEntityAttributeActions(org.hisp.dhis.actions.metadata.TrackedEntityAttributeActions) JsonObject(com.google.gson.JsonObject) EnrollmentDataBuilder(org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder) IdGenerator(org.hisp.dhis.actions.IdGenerator) JsonObjectBuilder(org.hisp.dhis.helpers.JsonObjectBuilder) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Aggregations

EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)12 JsonObject (com.google.gson.JsonObject)11 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)9 Test (org.junit.jupiter.api.Test)9 IdGenerator (org.hisp.dhis.actions.IdGenerator)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)4 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)3 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)3 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 Arrays (java.util.Arrays)1 Function (java.util.function.Function)1 CoreMatchers.hasItem (org.hamcrest.CoreMatchers.hasItem)1 Matchers (org.hamcrest.Matchers)1 Constants (org.hisp.dhis.Constants)1 ProgramActions (org.hisp.dhis.actions.metadata.ProgramActions)1 TrackedEntityAttributeActions (org.hisp.dhis.actions.metadata.TrackedEntityAttributeActions)1 DataGenerator (org.hisp.dhis.utils.DataGenerator)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1