Search in sources :

Example 76 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class PreCheckUpdatableFieldsValidationHookTest method verifyEventValidationFailsWhenUpdateEnrollment.

@Test
void verifyEventValidationFailsWhenUpdateEnrollment() {
    // given
    Event event = validEvent();
    event.setEnrollment("NewEnrollmentId");
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1128, EVENT, event.getUid());
    assertThat(reporter.getReportList().get(0).getErrorMessage(), containsString("enrollment"));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 77 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class PreCheckUpdatableFieldsValidationHookTest method verifyEventValidationSuccess.

@Test
void verifyEventValidationSuccess() {
    // given
    Event event = validEvent();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 78 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class PreCheckUpdatableFieldsValidationHookTest method verifyEventValidationFailsWhenUpdateProgramStage.

@Test
void verifyEventValidationFailsWhenUpdateProgramStage() {
    // given
    Event event = validEvent();
    event.setProgramStage("NewProgramStageId");
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1128, EVENT, event.getUid());
    assertThat(reporter.getReportList().get(0).getErrorMessage(), containsString("programStage"));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 79 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class RepeatedEventsValidationHookTest method programEvent.

private Event programEvent(String uid) {
    Event event = new Event();
    event.setEvent(uid);
    event.setProgramStage(NOT_REPEATABLE_PROGRAM_STAGE_WITHOUT_REGISTRATION);
    return event;
}
Also used : Event(org.hisp.dhis.tracker.domain.Event)

Example 80 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class RepeatedEventsValidationHookTest method testTwoEventInRepeatableProgramStageArePassingValidation.

@Test
void testTwoEventInRepeatableProgramStageArePassingValidation() {
    List<Event> events = Lists.newArrayList(repeatableEvent("A"), repeatableEvent("B"));
    bundle.setEvents(events);
    events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE));
    ValidationErrorReporter errorReporter = ValidationErrorReporter.emptyReporter();
    validatorToTest.validate(errorReporter, ctx);
    assertTrue(errorReporter.getReportList().isEmpty());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

Event (org.hisp.dhis.tracker.domain.Event)192 Test (org.junit.jupiter.api.Test)153 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)114 ProgramStage (org.hisp.dhis.program.ProgramStage)68 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)64 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)53 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)43 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)41 Mockito.when (org.mockito.Mockito.when)38 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)37 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)36 DataElement (org.hisp.dhis.dataelement.DataElement)35 Program (org.hisp.dhis.program.Program)35 ProgramInstance (org.hisp.dhis.program.ProgramInstance)35 DataValue (org.hisp.dhis.tracker.domain.DataValue)35 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)35 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)34 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)33 CodeGenerator (org.hisp.dhis.common.CodeGenerator)32 BeforeEach (org.junit.jupiter.api.BeforeEach)32