use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyCaptureScopeIsCheckedForEnrollmentDeletion.
@Test
void verifyCaptureScopeIsCheckedForEnrollmentDeletion() {
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(true);
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).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 EnrollmentDateValidationHookTest method testDatesCanBeInTheFuture.
@Test
void testDatesCanBeInTheFuture() {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setProgram(CodeGenerator.generateUid());
final Instant dateInTheFuture = Instant.now().plus(Duration.ofDays(2));
enrollment.setOccurredAt(dateInTheFuture);
enrollment.setEnrolledAt(dateInTheFuture);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
Program program = new Program();
program.setSelectEnrollmentDatesInFuture(true);
program.setSelectIncidentDatesInFuture(true);
when(validationContext.getProgram(enrollment.getProgram())).thenReturn(program);
this.hookToTest.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentDateValidationHookTest method testFailOnMissingOccurredAtDate.
@Test
void testFailOnMissingOccurredAtDate() {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setProgram(CodeGenerator.generateUid());
enrollment.setEnrolledAt(Instant.now());
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
Program program = new Program();
program.setDisplayIncidentDate(true);
when(validationContext.getProgram(enrollment.getProgram())).thenReturn(program);
this.hookToTest.validateEnrollment(reporter, enrollment);
hasTrackerError(reporter, E1023, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentGeoValidationHookTest method testProgramWithNullFeatureTypeFailsGeometryValidation.
@Test
void testProgramWithNullFeatureTypeFailsGeometryValidation() {
// given
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setProgram(PROGRAM);
enrollment.setGeometry(new GeometryFactory().createPoint());
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
Program program = new Program();
when(validationContext.getProgram(PROGRAM)).thenReturn(program);
this.hookToTest.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1074, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentGeoValidationHookTest method testProgramWithFeatureTypeDifferentFromGeometryFails.
@Test
void testProgramWithFeatureTypeDifferentFromGeometryFails() {
// given
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setProgram(PROGRAM);
enrollment.setGeometry(new GeometryFactory().createPoint());
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
Program program = new Program();
program.setFeatureType(FeatureType.MULTI_POLYGON);
when(validationContext.getProgram(PROGRAM)).thenReturn(program);
this.hookToTest.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1012, ENROLLMENT, enrollment.getUid());
}
Aggregations