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());
}
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());
}
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"));
}
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());
}
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());
}
Aggregations