use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class PreCheckExistenceValidationHookTest method verifyEnrollmentValidationFailsWhenIsCreateAndEnrollmentIsAlreadyPresent.
@Test
void verifyEnrollmentValidationFailsWhenIsCreateAndEnrollmentIsAlreadyPresent() {
// given
Enrollment enrollment = Enrollment.builder().enrollment(ENROLLMENT_UID).build();
// when
when(ctx.getStrategy(enrollment)).thenReturn(TrackerImportStrategy.CREATE);
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEnrollment(reporter, enrollment);
// then
hasTrackerError(reporter, E1080, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentDateValidationHookTest method testDatesShouldBeAllowedOnSameDayIfFutureDatesAreNotAllowed.
@Test
void testDatesShouldBeAllowedOnSameDayIfFutureDatesAreNotAllowed() {
Enrollment enrollment = new Enrollment();
enrollment.setProgram(CodeGenerator.generateUid());
final Instant today = Instant.now().plus(Duration.ofMinutes(1));
enrollment.setOccurredAt(today);
enrollment.setEnrolledAt(today);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
when(validationContext.getProgram(enrollment.getProgram())).thenReturn(new 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 testDatesMustNotBeInTheFuture.
@Test
void testDatesMustNotBeInTheFuture() {
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);
when(validationContext.getProgram(enrollment.getProgram())).thenReturn(new Program());
this.hookToTest.validateEnrollment(reporter, enrollment);
hasTrackerError(reporter, E1020, ENROLLMENT, enrollment.getUid());
hasTrackerError(reporter, E1021, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentDateValidationHookTest method testMandatoryDatesMustBePresent.
@Test
void testMandatoryDatesMustBePresent() {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(CodeGenerator.generateUid());
enrollment.setProgram(CodeGenerator.generateUid());
enrollment.setOccurredAt(Instant.now());
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
when(validationContext.getProgram(enrollment.getProgram())).thenReturn(new Program());
this.hookToTest.validateEnrollment(reporter, enrollment);
hasTrackerError(reporter, E1025, ENROLLMENT, enrollment.getUid());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class EnrollmentGeoValidationHookTest method testEnrollmentWithNoProgramThrowsAnError.
@Test
void testEnrollmentWithNoProgramThrowsAnError() {
// given
Enrollment enrollment = new Enrollment();
enrollment.setProgram(null);
enrollment.setGeometry(new GeometryFactory().createPoint());
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
assertThrows(NullPointerException.class, () -> this.hookToTest.validateEnrollment(reporter, enrollment));
}
Aggregations