Search in sources :

Example 86 with TrackerImportReport

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

the class EnrollmentImportValidationTest method initTest.

@Override
protected void initTest() throws IOException {
    setUpMetadata("tracker/tracker_basic_metadata.json");
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/enrollments_te_te-data.json");
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    manager.flush();
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport)

Example 87 with TrackerImportReport

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

the class EnrollmentImportValidationTest method testDeleteCascadeProgramInstances.

@Test
void testDeleteCascadeProgramInstances() throws IOException {
    TrackerImportParams params = renderService.fromJson(new ClassPathResource("tracker/validations/enrollments_te_attr-data.json").getInputStream(), TrackerImportParams.class);
    params.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(params);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    manager.flush();
    importProgramStageInstances();
    manager.flush();
    params = renderService.fromJson(new ClassPathResource("tracker/validations/enrollments_te_attr-data.json").getInputStream(), TrackerImportParams.class);
    User user2 = userService.getUser(USER_4);
    params.setUser(user2);
    params.setImportStrategy(TrackerImportStrategy.DELETE);
    TrackerImportReport trackerImportDeleteReport = trackerImportService.importTracker(params);
    assertEquals(2, trackerImportDeleteReport.getValidationReport().getErrors().size());
    assertThat(trackerImportDeleteReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1103))));
    assertThat(trackerImportDeleteReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1091))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 88 with TrackerImportReport

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

the class EventImportValidationTest method failValidationWhenTrackedEntityAttributeHasWrongOptionValue.

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

Example 89 with TrackerImportReport

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

the class EventImportValidationTest method testWrongDatesInCatCombo.

@Test
void testWrongDatesInCatCombo() throws IOException {
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events_combo-date-wrong.json");
    trackerBundleParams.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(2, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1056))));
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1057))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Example 90 with TrackerImportReport

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

the class EventImportValidationTest method createEvent.

private TrackerImportReport createEvent(String jsonPayload) throws IOException {
    // Given
    TrackerImportParams trackerBundleParams = createBundleFromJson(jsonPayload);
    trackerBundleParams.setImportStrategy(CREATE_AND_UPDATE);
    // When
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    // Then
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    return trackerImportReport;
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport)

Aggregations

TrackerImportReport (org.hisp.dhis.tracker.report.TrackerImportReport)114 TrackerImportParams (org.hisp.dhis.tracker.TrackerImportParams)105 Test (org.junit.jupiter.api.Test)99 User (org.hisp.dhis.user.User)23 TrackerTest (org.hisp.dhis.tracker.TrackerTest)21 ClassPathResource (org.springframework.core.io.ClassPathResource)20 InputStream (java.io.InputStream)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)15 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 Date (java.util.Date)4 List (java.util.List)4 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Program (org.hisp.dhis.program.Program)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 TrackerValidationReport (org.hisp.dhis.tracker.report.TrackerValidationReport)3 TrackerImportReportRequest (org.hisp.dhis.webapi.controller.tracker.TrackerImportReportRequest)3 ResponseEntity (org.springframework.http.ResponseEntity)3