use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationFailsWhenEnrollmentIsNotARegistration.
@Test
void verifyValidationFailsWhenEnrollmentIsNotARegistration() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithoutRegistration(PROGRAM_UID, orgUnit));
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
Enrollment enrollment = Enrollment.builder().orgUnit(ORG_UNIT_ID).enrollment(CodeGenerator.generateUid()).program(PROGRAM_UID).build();
hook.validateEnrollment(reporter, enrollment);
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1014));
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForEnrollmentWithoutEventsUsingDeleteStrategy.
@Test
void verifyValidationSuccessForEnrollmentWithoutEventsUsingDeleteStrategy() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.programInstanceHasEvents(enrollment.getEnrollment())).thenReturn(false);
when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(getEnrollment(enrollment.getEnrollment()));
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, program)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyCaptureScopeIsCheckedForEnrollmentCreation.
@Test
void verifyCaptureScopeIsCheckedForEnrollmentCreation() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.CREATE);
when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, program)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForEnrollmentUsingDeleteStrategyAndUserWithCascadeAuthority.
@Test
void verifyValidationSuccessForEnrollmentUsingDeleteStrategyAndUserWithCascadeAuthority() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.programInstanceHasEvents(enrollment.getEnrollment())).thenReturn(true);
when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(getEnrollment(enrollment.getEnrollment()));
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, program)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
bundle.setUser(deleteEnrollmentAuthorisedUser());
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForEnrollmentUsingDeleteStrategyAndUserWithoutCascadeAuthority.
@Test
void verifyValidationFailsForEnrollmentUsingDeleteStrategyAndUserWithoutCascadeAuthority() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.programInstanceHasEvents(enrollment.getEnrollment())).thenReturn(true);
when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(getEnrollment(enrollment.getEnrollment()));
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, program)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEnrollment(reporter, enrollment);
hasTrackerError(reporter, E1103, TrackerType.ENROLLMENT, enrollment.getUid());
}
Aggregations