use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class EventNoteValidationHookTest 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);
event.setNotes(Collections.singletonList(note));
// When
this.hook.validateEvent(reporter, event);
// Then
assertFalse(reporter.hasErrors());
assertThat(event.getNotes(), hasSize(0));
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEventValidationSuccess.
@Test
void verifyEventValidationSuccess() {
// given
Note note = Note.builder().note(CodeGenerator.generateUid()).build();
Event event = Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyEventWithNoteWithInvalidUidFails.
@Test
void verifyEventWithNoteWithInvalidUidFails() {
// given
Note note = Note.builder().note(INVALID_UID).build();
Event event = Event.builder().event(CodeGenerator.generateUid()).notes(Lists.newArrayList(note)).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateEvent(reporter, event);
// then
hasTrackerError(reporter, E1048, EVENT, event.getUid());
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class NotesConverterServiceTest method verifyConvertNoteToComment.
@Test
void verifyConvertNoteToComment() {
TrackedEntityComment comment = rnd.nextObject(TrackedEntityComment.class);
final Note note = notesConverterService.to(comment);
assertCommentValues(note, comment);
}
use of org.hisp.dhis.tracker.domain.Note in project dhis2-core by dhis2.
the class NotesConverterServiceTest method verifyConvertNotesToComments.
@Test
void verifyConvertNotesToComments() {
List<TrackedEntityComment> comments = rnd.objects(TrackedEntityComment.class, 10).collect(Collectors.toList());
final List<Note> notes = notesConverterService.to(comments);
for (TrackedEntityComment comment : comments) {
assertCommentValues(notes.stream().filter(n -> n.getNote().equals(comment.getUid())).findFirst().get(), comment);
}
}
Aggregations