Search in sources :

Example 76 with Enrollment

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForEnrollmentDeletionAndUserWithoutTrackedEntityTypeReadAccess.

@Test
void verifyValidationFailsForEnrollmentDeletionAndUserWithoutTrackedEntityTypeReadAccess() {
    String enrollmentUid = CodeGenerator.generateUid();
    Enrollment enrollment = Enrollment.builder().enrollment(enrollmentUid).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
    when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
    when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(getEnrollment(enrollment.getEnrollment()));
    when(aclService.canDataWrite(user, program)).thenReturn(true);
    when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(false);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateEnrollment(reporter, enrollment);
    hasTrackerError(reporter, E1104, TrackerType.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) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 77 with Enrollment

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

the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForEnrollmentDeletionAndUserWithoutProgramWriteAccess.

@Test
void verifyValidationFailsForEnrollmentDeletionAndUserWithoutProgramWriteAccess() {
    String enrollmentUid = CodeGenerator.generateUid();
    Enrollment enrollment = Enrollment.builder().enrollment(enrollmentUid).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
    when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
    when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(getEnrollment(enrollment.getEnrollment()));
    when(aclService.canDataWrite(user, program)).thenReturn(false);
    when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
    when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
    reporter = new ValidationErrorReporter(ctx);
    validatorToTest.validateEnrollment(reporter, enrollment);
    hasTrackerError(reporter, E1091, TrackerType.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) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 78 with Enrollment

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

the class PreCheckUpdatableFieldsValidationHookTest method verifyEnrollmentValidationFailsWhenUpdateProgram.

@Test
void verifyEnrollmentValidationFailsWhenUpdateProgram() {
    // given
    Enrollment enrollment = validEnrollment();
    enrollment.setProgram("NewProgramId");
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    hasTrackerError(reporter, E1127, ENROLLMENT, enrollment.getUid());
    assertThat(reporter.getReportList().get(0).getErrorMessage(), containsString("program"));
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 79 with Enrollment

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

the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationSuccessWhenIsUpdate.

@Test
void verifyEnrollmentValidationSuccessWhenIsUpdate() {
    // given
    Enrollment enrollment = Enrollment.builder().enrollment(ENROLLMENT_UID).build();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEnrollment(reporter, enrollment);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 80 with Enrollment

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

the class PreCheckMetaValidationHookTest method verifyEnrollmentValidationSuccess.

@Test
void verifyEnrollmentValidationSuccess() {
    // 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());
    when(ctx.getProgram(PROGRAM_UID)).thenReturn(new Program());
    validatorToTest.validateEnrollment(reporter, enrollment);
    // then
    assertFalse(reporter.hasErrors());
}
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) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) 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