Search in sources :

Example 11 with Note

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);
}
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 12 with 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);
}
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 13 with 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));
}
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 14 with Note

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));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) BeanRandomizer(org.hisp.dhis.random.BeanRandomizer) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Note(org.hisp.dhis.tracker.domain.Note) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Event(org.hisp.dhis.tracker.domain.Event) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mockito.when(org.mockito.Mockito.when) TrackerType(org.hisp.dhis.tracker.TrackerType) ValidationMode(org.hisp.dhis.tracker.ValidationMode) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Collectors(java.util.stream.Collectors) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) Test(org.junit.jupiter.api.Test) List(java.util.List) TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Collections(java.util.Collections) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Mockito.mock(org.mockito.Mockito.mock) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 15 with Note

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));
}
Also used : 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)

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