use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class NotesConverterServiceTest method verifyConvertCommentToNoteWithNoStoredByDefined.
@Test
void verifyConvertCommentToNoteWithNoStoredByDefined() {
Note note = rnd.nextObject(Note.class);
note.setStoredBy(null);
final TrackedEntityComment comment = notesConverterService.from(preheat, note);
assertNoteValuesWithCurrentUser(comment, note);
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class NotesConverterServiceTest method verifyConvertCommentToNote.
@Test
void verifyConvertCommentToNote() {
Note note = rnd.nextObject(Note.class);
final TrackedEntityComment comment = notesConverterService.from(preheat, note);
assertNoteValues(comment, note);
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class EnrollmentNoteValidationHookTest method testNoteWithExistingUidAndNoTextIsIgnored.
@Test
void testNoteWithExistingUidAndNoTextIsIgnored() {
// Given
final Note note = rnd.nextObject(Note.class);
note.setValue(null);
TrackerBundle trackerBundle = mock(TrackerBundle.class);
TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
when(ctx.getBundle()).thenReturn(trackerBundle);
when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
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
assertFalse(reporter.hasErrors());
assertThat(enrollment.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class EventNoteValidationHookTest 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);
event.setNotes(Collections.singletonList(note));
// When
this.hook.validateEvent(reporter, event);
// Then
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(r -> TrackerErrorCode.E1119.equals(r.getWarningCode()) && TrackerType.EVENT.equals(r.getTrackerType()) && event.getUid().equals(r.getUid())));
assertThat(event.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class EventNoteValidationHookTest 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);
event.setNotes(notes);
// When
this.hook.validateEvent(reporter, event);
// Then
assertFalse(reporter.hasErrors());
assertThat(event.getNotes(), hasSize(5));
}
Aggregations