Search in sources :

Example 36 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class EnrollmentImportValidationTest method testPreheatOwnershipForSubsequentEnrollment.

@Test
void testPreheatOwnershipForSubsequentEnrollment() throws IOException {
    TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    TrackerImportParams secondParams = createBundleFromJson("tracker/validations/enrollments_te_enrollments-data.json");
    TrackerPreheat preheat = trackerPreheatService.preheat(secondParams);
    secondParams.getEnrollments().forEach(e -> {
        assertEquals(e.getOrgUnit(), preheat.getProgramOwner().get(e.getTrackedEntity()).get(e.getProgram()).getOrganisationUnit().getUid());
    });
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Test(org.junit.jupiter.api.Test)

Example 37 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class EnrollmentImportValidationTest method testOnlyProgramAttributesAllowedOnEnrollments.

@Test
void testOnlyProgramAttributesAllowedOnEnrollments() throws IOException {
    TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_error_non_program_attr.json");
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(3, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), everyItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1019))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Example 38 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class EnrollmentImportValidationTest method importProgramStageInstances.

protected void importProgramStageInstances() throws IOException {
    TrackerImportParams params = createBundleFromJson("tracker/validations/events-data.json");
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport)

Example 39 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class EnrollmentImportValidationTest method testBadEnrollmentNoteNoValue.

/**
 * Notes with no value are ignored
 */
@Test
void testBadEnrollmentNoteNoValue() throws IOException {
    TrackerImportParams params = createBundleFromJson("tracker/validations/enrollments_bad-note-no-value.json");
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Example 40 with TrackerImportParams

use of org.hisp.dhis.tracker.TrackerImportParams in project dhis2-core by dhis2.

the class EnrollmentImportValidationTest method testActiveEnrollmentAlreadyExists.

@Test
void testActiveEnrollmentAlreadyExists() throws IOException {
    TrackerImportParams trackerImportParams = createBundleFromJson("tracker/validations/enrollments_double-tei-enrollment_part1.json");
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    TrackerValidationReport validationReport = trackerImportReport.getValidationReport();
    assertEquals(0, validationReport.getErrors().size());
    TrackerImportParams trackerImportParams1 = createBundleFromJson("tracker/validations/enrollments_double-tei-enrollment_part2.json");
    trackerImportReport = trackerImportService.importTracker(trackerImportParams1);
    validationReport = trackerImportReport.getValidationReport();
    assertEquals(1, validationReport.getErrors().size());
    assertThat(validationReport.getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1015))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) TrackerValidationReport(org.hisp.dhis.tracker.report.TrackerValidationReport) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)163 Test (org.junit.jupiter.api.Test)142 TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)105 TrackerTest (org.hisp.dhis.tracker.TrackerTest)46 User (org.hisp.dhis.user.User)26 ClassPathResource (org.springframework.core.io.ClassPathResource)23 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 InputStream (java.io.InputStream)16 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 List (java.util.List)9 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 Event (org.hisp.dhis.tracker.domain.Event)7 Pair (org.apache.commons.lang3.tuple.Pair)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 Program (org.hisp.dhis.program.Program)5