Search in sources :

Example 71 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle 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 72 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle 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)

Example 73 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class AssignedUserValidationHookTest method setUp.

@BeforeEach
public void setUp() {
    hookToTest = new AssignedUserValidationHook();
    TrackerBundle bundle = TrackerBundle.builder().build();
    TrackerPreheat preheat = new TrackerPreheat();
    User user = new User();
    user.setUid(USER_ID);
    preheat.put(TrackerIdentifier.UID, user);
    bundle.setPreheat(preheat);
    when(validationContext.getBundle()).thenReturn(bundle);
    ProgramStage programStage = new ProgramStage();
    programStage.setEnableUserAssignment(true);
    when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
}
Also used : User(org.hisp.dhis.user.User) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 74 with TrackerBundle

use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.

the class EnrollmentGeoValidationHookTest method setUp.

@BeforeEach
public void setUp() {
    hookToTest = new EnrollmentGeoValidationHook();
    TrackerBundle bundle = TrackerBundle.builder().build();
    when(validationContext.getBundle()).thenReturn(bundle);
    Program program = new Program();
    program.setFeatureType(FeatureType.POINT);
    when(validationContext.getProgram(PROGRAM)).thenReturn(program);
}
Also used : Program(org.hisp.dhis.program.Program) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)74 Test (org.junit.jupiter.api.Test)43 Event (org.hisp.dhis.tracker.domain.Event)29 User (org.hisp.dhis.user.User)21 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)19 List (java.util.List)17 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)15 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 Mockito.mock (org.mockito.Mockito.mock)14 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)13 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)12 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)12 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)12 Collections (java.util.Collections)11 ProgramStage (org.hisp.dhis.program.ProgramStage)11 Objects (java.util.Objects)10 Program (org.hisp.dhis.program.Program)10 ValidationMode (org.hisp.dhis.tracker.ValidationMode)10 Relationship (org.hisp.dhis.tracker.domain.Relationship)10