use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForTrackedEntityUsingDeleteStrategyAndUserWithoutCascadeAuthority.
@Test
void verifyValidationFailsForTrackedEntityUsingDeleteStrategyAndUserWithoutCascadeAuthority() {
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(getTEIWithProgramInstances());
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateTrackedEntity(reporter, trackedEntity);
hasTrackerError(reporter, E1100, TrackerType.TRACKED_ENTITY, trackedEntity.getUid());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForEnrollment.
@Test
void verifyValidationSuccessForEnrollment() {
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_AND_UPDATE);
when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
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.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForEnrollmentWithoutEventsUsingDeleteStrategyAndUserNotInOrgUnitHierarchy.
@Test
void verifyValidationFailsForEnrollmentWithoutEventsUsingDeleteStrategyAndUserNotInOrgUnitHierarchy() {
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(false);
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, E1000, TrackerType.ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForEnrollmentWhenProgramInstanceHasNoOrgUnitAssigned.
@Test
void verifyValidationSuccessForEnrollmentWhenProgramInstanceHasNoOrgUnitAssigned() {
Enrollment enrollment = Enrollment.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntity(TEI_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.UPDATE);
ProgramInstance programInstance = getEnrollment(enrollment.getEnrollment());
programInstance.setOrganisationUnit(null);
when(ctx.getProgramInstance(enrollment.getEnrollment())).thenReturn(programInstance);
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());
verify(organisationUnitService, times(0)).isInUserHierarchyCached(user, organisationUnit);
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.DELETE);
validatorToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
verify(organisationUnitService, times(0)).isInUserHierarchyCached(user, organisationUnit);
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForTrackerEventCreation.
@Test
void verifyValidationSuccessForTrackerEventCreation() {
Event event = Event.builder().enrollment(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).programStage(PS_ID).program(PROGRAM_ID).build();
when(ctx.getStrategy(event)).thenReturn(TrackerImportStrategy.CREATE);
when(ctx.getProgramStage(event.getProgramStage())).thenReturn(programStage);
when(ctx.getProgramInstance(event.getEnrollment())).thenReturn(getEnrollment(null));
when(ctx.getProgram(PROGRAM_ID)).thenReturn(program);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataRead(user, program.getTrackedEntityType())).thenReturn(true);
when(aclService.canDataRead(user, program)).thenReturn(true);
when(aclService.canDataWrite(user, programStage)).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
Aggregations