Search in sources :

Example 26 with TrackerImportReport

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

the class EventImportValidationTest method testValidateAndAddNotesToEvent.

@Test
void testValidateAndAddNotesToEvent() throws IOException {
    Date now = new Date();
    // When
    TrackerImportReport trackerImportReport = createEvent("tracker/validations/events-with-notes-data.json");
    // Then
    // Fetch the UID of the newly created event
    final ProgramStageInstance programStageInstance = getEventFromReport(trackerImportReport);
    assertThat(programStageInstance.getComments(), hasSize(3));
    // Validate note content
    Stream.of("first note", "second note", "third note").forEach(t -> {
        TrackedEntityComment comment = getByComment(programStageInstance.getComments(), t);
        assertTrue(CodeGenerator.isValidUid(comment.getUid()));
        assertTrue(comment.getCreated().getTime() > now.getTime());
        assertTrue(comment.getLastUpdated().getTime() > now.getTime());
        assertNotNull(comment.getCreator());
        assertEquals(ADMIN_USER_UID, comment.getLastUpdatedBy().getUid());
    });
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Date(java.util.Date) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test)

Example 27 with TrackerImportReport

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

the class EventImportValidationTest method testCantWriteAccessCatCombo.

@Test
void testCantWriteAccessCatCombo() throws IOException {
    TrackerImportParams trackerImportParams = createBundleFromJson("tracker/validations/events-cat-write-access.json");
    User user = userService.getUser(USER_6);
    trackerImportParams.setUser(user);
    trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(4, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1099))));
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1104))));
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1096))));
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1095))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) User(org.hisp.dhis.user.User) Test(org.junit.jupiter.api.Test)

Example 28 with TrackerImportReport

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

the class EventImportValidationTest method testDeletedEventFails.

@SneakyThrows
private void testDeletedEventFails(TrackerImportStrategy importStrategy) {
    // Given -> Creates an event
    createEvent("tracker/validations/events-with-notes-data.json");
    ProgramStageInstance event = programStageServiceInstance.getProgramStageInstance("uLxFbxfYDQE");
    assertNotNull(event);
    // When -> Soft-delete the event
    programStageServiceInstance.deleteProgramStageInstance(event);
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events-with-notes-data.json");
    trackerBundleParams.setImportStrategy(TrackerImportStrategy.CREATE);
    // When
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), everyItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1082))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) SneakyThrows(lombok.SneakyThrows)

Example 29 with TrackerImportReport

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

the class EventImportValidationTest method testTrackerAndProgramEventUpdateSuccess.

@Test
void testTrackerAndProgramEventUpdateSuccess() throws IOException {
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/program_and_tracker_events.json");
    trackerBundleParams.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    trackerBundleParams.setImportStrategy(UPDATE);
    trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(TrackerStatus.OK, trackerImportReport.getStatus());
    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 30 with TrackerImportReport

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

the class EventImportValidationTest method testCOFoundButAOCNotFound.

@Test
void testCOFoundButAOCNotFound() throws IOException {
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events_cant-find-aoc-but-co-exists.json");
    trackerBundleParams.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1115))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

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