Search in sources :

Example 6 with Note

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));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 7 with Note

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());
}
Also used : Note(org.hisp.dhis.tracker.domain.Note) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 8 with Note

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());
}
Also used : Note(org.hisp.dhis.tracker.domain.Note) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 9 with Note

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);
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.tracker.domain.Note) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 10 with Note

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);
    }
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) Collectors(java.util.stream.Collectors) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Test(org.junit.jupiter.api.Test) List(java.util.List) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Note(org.hisp.dhis.tracker.domain.Note) Matchers.hasSize(org.hamcrest.Matchers.hasSize) User(org.hisp.dhis.user.User) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) DateUtils(org.hisp.dhis.util.DateUtils) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest) Note(org.hisp.dhis.tracker.domain.Note) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

Note (org.hisp.dhis.tracker.domain.Note)18 Test (org.junit.jupiter.api.Test)15 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)10 TrackedEntityComment (org.hisp.dhis.trackedentitycomment.TrackedEntityComment)9 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)7 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)4 Matchers.hasSize (org.hamcrest.Matchers.hasSize)4 BeanRandomizer (org.hisp.dhis.random.BeanRandomizer)4 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)4 Event (org.hisp.dhis.tracker.domain.Event)4 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2