Search in sources :

Example 91 with TrackerImportReport

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

the class EventImportValidationTest method testNoCategoryOptionCombo.

@Test
void testNoCategoryOptionCombo() throws IOException {
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events_cant-find-cat-opt-combo.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)

Example 92 with TrackerImportReport

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

the class EventImportValidationTest method testNonRepeatableProgramStage.

@Test
void testNonRepeatableProgramStage() throws IOException {
    TrackerImportParams trackerImportParams = fromJson("tracker/validations/events_non-repeatable-programstage_part1.json", userService.getUser(ADMIN_USER_UID));
    trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(0, trackerImportReport.getValidationReport().getErrors().size());
    trackerImportParams = fromJson("tracker/validations/events_non-repeatable-programstage_part2.json", userService.getUser(ADMIN_USER_UID));
    trackerImportParams.setImportStrategy(TrackerImportStrategy.CREATE);
    trackerImportReport = trackerImportService.importTracker(trackerImportParams);
    assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1039))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Example 93 with TrackerImportReport

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

the class EventImportValidationTest method testNonDefaultCategoryCombo.

@Test
void testNonDefaultCategoryCombo() throws IOException {
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events_non-default-combo.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.E1055))));
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackerImportReport(org.hisp.dhis.tracker.report.TrackerImportReport) Test(org.junit.jupiter.api.Test)

Example 94 with TrackerImportReport

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

the class EventImportValidationTest method testNoWriteAccessToOrg.

@Test
void testNoWriteAccessToOrg() throws IOException {
    TrackerImportParams trackerBundleParams = createBundleFromJson("tracker/validations/events-data.json");
    User user = userService.getUser(USER_2);
    trackerBundleParams.setUser(user);
    trackerBundleParams.setImportStrategy(TrackerImportStrategy.CREATE);
    TrackerImportReport trackerImportReport = trackerImportService.importTracker(trackerBundleParams);
    assertEquals(1, trackerImportReport.getValidationReport().getErrors().size());
    assertThat(trackerImportReport.getValidationReport().getErrors(), hasItem(hasProperty("errorCode", equalTo(TrackerErrorCode.E1000))));
}
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 95 with TrackerImportReport

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

the class EventImportValidationTest method testValidateAndAddNotesToUpdatedEvent.

@Test
void testValidateAndAddNotesToUpdatedEvent() throws IOException {
    Date now = new Date();
    // Given -> Creates an event with 3 notes
    createEvent("tracker/validations/events-with-notes-data.json");
    // When -> Update the event and adds 3 more notes
    TrackerImportReport trackerImportReport = createEvent("tracker/validations/events-with-notes-update-data.json");
    // Then
    final ProgramStageInstance programStageInstance = getEventFromReport(trackerImportReport);
    assertThat(programStageInstance.getComments(), hasSize(6));
    // validate note content
    Stream.of("first note", "second note", "third note", "4th note", "5th note", "6th 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)

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