use of org.hisp.dhis.tracker.bundle.TrackerBundle 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));
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNotesAreValidWhenUidDoesNotExist.
@Test
void testNotesAreValidWhenUidDoesNotExist() {
// Given
final List<Note> notes = rnd.objects(Note.class, 5).collect(Collectors.toList());
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
enrollment.setNotes(notes);
// When
this.hook.validateEnrollment(reporter, enrollment);
// Then
assertFalse(reporter.hasErrors());
assertThat(enrollment.getNotes(), hasSize(5));
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle 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.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EnrollmentDateValidationHookTest method setUp.
@BeforeEach
public void setUp() {
hookToTest = new EnrollmentDateValidationHook();
TrackerBundle bundle = TrackerBundle.builder().build();
when(validationContext.getBundle()).thenReturn(bundle);
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerValidationServiceTest method needsToRunExecutesHookIfReturnsTrue.
@Test
void needsToRunExecutesHookIfReturnsTrue() {
Event invalidEvent = event();
TrackerBundle bundle = newBundle().events(events(invalidEvent)).build();
ValidationHook hook1 = ValidationHook.builder().needsToRun(true).validateEvent((reporter, event) -> reporter.addErrorIf(() -> invalidEvent.equals(event), event, TrackerErrorCode.E1032)).build();
service = new DefaultTrackerValidationService(List.of(hook1), Collections.emptyList());
TrackerValidationReport report = service.validate(bundle);
assertTrue(report.hasErrors());
assertHasError(report, TrackerErrorCode.E1032, invalidEvent);
}
Aggregations