Search in sources :

Example 36 with Enrollment

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

the class PreCheckMetaValidationHookTest method verifyEnrollmentValidationFailsWhenProgramIsNotPresentInDb.

@Test
void verifyEnrollmentValidationFailsWhenProgramIsNotPresentInDb() {
    // given
    Enrollment enrollment = validEnrollment();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    // when
    when(ctx.getOrganisationUnit(ORG_UNIT_UID)).thenReturn(new OrganisationUnit());
    when(ctx.getTrackedEntityInstance(TRACKED_ENTITY_UID)).thenReturn(new TrackedEntityInstance());
    validatorToTest.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1069, ENROLLMENT, enrollment.getUid());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 37 with Enrollment

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

the class PreCheckMetaValidationHookTest method verifyEnrollmentValidationFailsWhenTrackedEntityIsNotPresentInDbOrPayload.

@Test
void verifyEnrollmentValidationFailsWhenTrackedEntityIsNotPresentInDbOrPayload() {
    // given
    Enrollment enrollment = validEnrollment();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    // when
    when(ctx.getOrganisationUnit(ORG_UNIT_UID)).thenReturn(new OrganisationUnit());
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(new Program());
    validatorToTest.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1068, ENROLLMENT, enrollment.getUid());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 38 with Enrollment

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

the class PreCheckMetaValidationHookTest method verifyEnrollmentValidationFailsWhenOrgUnitIsNotPresentInDb.

@Test
void verifyEnrollmentValidationFailsWhenOrgUnitIsNotPresentInDb() {
    // given
    Enrollment enrollment = validEnrollment();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    // when
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(new Program());
    when(ctx.getTrackedEntityInstance(TRACKED_ENTITY_UID)).thenReturn(new TrackedEntityInstance());
    validatorToTest.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1070, ENROLLMENT, enrollment.getUid());
}
Also used : Program(org.hisp.dhis.program.Program) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Test(org.junit.jupiter.api.Test)

Example 39 with Enrollment

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

the class PreCheckUidValidationHookTest method verifyEnrollmentWithInvalidUidFails.

@Test
void verifyEnrollmentWithInvalidUidFails() {
    // given
    Enrollment enrollment = Enrollment.builder().enrollment(INVALID_UID).build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1048, ENROLLMENT, enrollment.getUid());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 40 with Enrollment

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

the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationFailsWhenIsUpdateAndEnrollmentIsNotPresent.

@Test
void verifyEnrollmentValidationFailsWhenIsUpdateAndEnrollmentIsNotPresent() {
    // given
    Enrollment enrollment = Enrollment.builder().enrollment(NOT_PRESENT_ENROLLMENT_UID).build();
    // when
    when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.UPDATE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1081, ENROLLMENT, enrollment.getUid());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

Enrollment (org.hisp.dhis.tracker.domain.Enrollment)88 Test (org.junit.jupiter.api.Test)67 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)53 Event (org.hisp.dhis.tracker.domain.Event)25 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)24 Program (org.hisp.dhis.program.Program)21 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)17 List (java.util.List)16 Optional (java.util.Optional)15 ProgramInstance (org.hisp.dhis.program.ProgramInstance)15 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)15 Sets (com.google.common.collect.Sets)14 Collectors (java.util.stream.Collectors)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Mockito.when (org.mockito.Mockito.when)14