use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class AssignedUserValidationHookTest method testEventWithNullEnabledUserAssignment.
@Test
void testEventWithNullEnabledUserAssignment() {
// given
Event event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setAssignedUser(USER_ID);
event.setProgramStage(PROGRAM_STAGE);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
ProgramStage programStage = new ProgramStage();
programStage.setEnableUserAssignment(null);
when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
this.hookToTest.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(r -> E1120.equals(r.getWarningCode()) && TrackerType.EVENT.equals(r.getTrackerType()) && event.getUid().equals(r.getUid())));
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.
the class AssignedUserValidationHookTest method testEventWithUserNotPresentInPreheat.
@Test
void testEventWithUserNotPresentInPreheat() {
// given
Event event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setAssignedUser(USER_ID);
event.setProgramStage(PROGRAM_STAGE);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
TrackerBundle bundle = TrackerBundle.builder().build();
bundle.setPreheat(new TrackerPreheat());
when(validationContext.getBundle()).thenReturn(bundle);
this.hookToTest.validateEvent(reporter, event);
// then
hasTrackerError(reporter, E1118, TrackerType.EVENT, event.getUid());
}
use of org.hisp.dhis.tracker.report.ValidationErrorReporter 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.report.ValidationErrorReporter 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.report.ValidationErrorReporter 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());
}
Aggregations