Search in sources :

Example 61 with ValidationErrorReporter

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

Example 62 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class RepeatedEventsValidationHookTest method testTwoEventsInNotRepeatableProgramStageWhenOneIsInvalidArePassingValidation.

@Test
void testTwoEventsInNotRepeatableProgramStageWhenOneIsInvalidArePassingValidation() {
    Event invalidEvent = notRepeatableEvent("A");
    List<Event> events = Lists.newArrayList(invalidEvent, notRepeatableEvent("B"));
    bundle.setEvents(events);
    events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE));
    ValidationErrorReporter errorReporter = ValidationErrorReporter.emptyReporter();
    errorReporter.getInvalidDTOs().put(TrackerType.EVENT, Lists.newArrayList(invalidEvent.getUid()));
    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)

Example 63 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class RepeatedEventsValidationHookTest method testTwoEventInNotRepeatableProgramStageAreNotPassingValidation.

@Test
void testTwoEventInNotRepeatableProgramStageAreNotPassingValidation() {
    List<Event> events = Lists.newArrayList(notRepeatableEvent("A"), notRepeatableEvent("B"));
    bundle.setEvents(events);
    events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE));
    ValidationErrorReporter errorReporter = new ValidationErrorReporter(new TrackerImportValidationContext(bundle));
    validatorToTest.validate(errorReporter, ctx);
    assertEquals(2, errorReporter.getReportList().size());
    assertThat(errorReporter.getReportList().get(0).getErrorCode(), is(TrackerErrorCode.E1039));
    assertThat(errorReporter.getReportList().get(0).getTrackerType(), is(EVENT));
    assertThat(errorReporter.getReportList().get(0).getUid(), is(events.get(0).getUid()));
    assertThat(errorReporter.getReportList().get(0).getErrorMessage(), is("ProgramStage: `" + NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION + "`, is not repeatable and an event already exists."));
    assertThat(errorReporter.getReportList().get(1).getErrorCode(), is(TrackerErrorCode.E1039));
    assertThat(errorReporter.getReportList().get(1).getTrackerType(), is(EVENT));
    assertThat(errorReporter.getReportList().get(1).getUid(), is(events.get(1).getUid()));
    assertThat(errorReporter.getReportList().get(1).getErrorMessage(), is("ProgramStage: `" + NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION + "`, is not repeatable and an event already exists."));
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) 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)

Example 64 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class RepeatedEventsValidationHookTest method testSingleEventIsPassingValidation.

@Test
void testSingleEventIsPassingValidation() {
    List<Event> events = Lists.newArrayList(notRepeatableEvent("A"));
    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)

Example 65 with ValidationErrorReporter

use of org.hisp.dhis.tracker.report.ValidationErrorReporter in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHookTest method verifyEventValidationFailsWhenIsSoftDeleted.

@Test
void verifyEventValidationFailsWhenIsSoftDeleted() {
    // given
    Event event = Event.builder().event(SOFT_DELETED_EVENT_UID).build();
    // when
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    validationHook.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1082, EVENT, event.getUid());
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)206 Test (org.junit.jupiter.api.Test)192 Event (org.hisp.dhis.tracker.domain.Event)89 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)48 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)48 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)43 ProgramStage (org.hisp.dhis.program.ProgramStage)38 DataElement (org.hisp.dhis.dataelement.DataElement)25 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)24 Relationship (org.hisp.dhis.tracker.domain.Relationship)23 DataValue (org.hisp.dhis.tracker.domain.DataValue)21 Program (org.hisp.dhis.program.Program)19 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)17 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)16 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 RelationshipType (org.hisp.dhis.relationship.RelationshipType)12 BeforeEach (org.junit.jupiter.api.BeforeEach)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11