Search in sources :

Example 66 with TrackerBundle

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

the class ValidationErrorReporterTest method hasErrorReportFound.

@Test
void hasErrorReportFound() {
    ValidationErrorReporter reporter = ValidationErrorReporter.emptyReporter();
    TrackerBundle bundle = mock(TrackerBundle.class);
    TrackerErrorReport error = TrackerErrorReport.builder().errorCode(TrackerErrorCode.E1000).trackerType(TrackerType.EVENT).build(bundle);
    reporter.getReportList().add(error);
    assertTrue(reporter.hasErrorReport(r -> TrackerType.EVENT.equals(r.getTrackerType())));
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Mockito.mock(org.mockito.Mockito.mock) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 67 with TrackerBundle

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

the class ValidationErrorReporterTest method hasWarningReportNotFound.

@Test
void hasWarningReportNotFound() {
    ValidationErrorReporter reporter = ValidationErrorReporter.emptyReporter();
    TrackerBundle bundle = mock(TrackerBundle.class);
    TrackerWarningReport warning = TrackerWarningReport.builder().warningCode(TrackerErrorCode.E1000).trackerType(TrackerType.EVENT).build(bundle);
    reporter.getWarningsReportList().add(warning);
    assertFalse(reporter.hasWarningReport(r -> TrackerType.TRACKED_ENTITY.equals(r.getTrackerType())));
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Mockito.mock(org.mockito.Mockito.mock) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 68 with TrackerBundle

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

the class ValidationErrorReporterTest method hasWarningReportFound.

@Test
void hasWarningReportFound() {
    ValidationErrorReporter reporter = ValidationErrorReporter.emptyReporter();
    TrackerBundle bundle = mock(TrackerBundle.class);
    TrackerWarningReport warning = TrackerWarningReport.builder().warningCode(TrackerErrorCode.E1000).trackerType(TrackerType.EVENT).build(bundle);
    reporter.getWarningsReportList().add(warning);
    assertTrue(reporter.hasWarningReport(r -> TrackerType.EVENT.equals(r.getTrackerType())));
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Mockito.mock(org.mockito.Mockito.mock) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Test(org.junit.jupiter.api.Test)

Example 69 with TrackerBundle

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

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

the class EventDateValidationHookTest method testEventIsValid.

@Test
void testEventIsValid() {
    // given
    Event event = new Event();
    event.setProgram(PROGRAM_WITHOUT_REGISTRATION_ID);
    event.setOccurredAt(now());
    event.setStatus(EventStatus.ACTIVE);
    TrackerBundle bundle = TrackerBundle.builder().user(getEditExpiredUser()).build();
    when(validationContext.getBundle()).thenReturn(bundle);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    this.hookToTest.validateEvent(reporter, event);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

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