use of org.hisp.dhis.tracker.TrackerType.ENROLLMENT in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNoteWithExistingUidWarnings.
@Test
void testNoteWithExistingUidWarnings() {
// Given
final Note note = rnd.nextObject(Note.class);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
TrackerPreheat preheat = mock(TrackerPreheat.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
when(trackerBundle.getPreheat()).thenReturn(preheat);
when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
enrollment.setNotes(Collections.singletonList(note));
// When
this.hook.validateEnrollment(reporter, enrollment);
// Then
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(warn -> E1119.equals(warn.getWarningCode()) && ENROLLMENT.equals(warn.getTrackerType()) && enrollment.getUid().equals(warn.getUid())));
assertThat(enrollment.getNotes(), hasSize(0));
}
Aggregations