Search in sources :

Example 6 with ValidationErrorReporter

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

the class EventDataValuesValidationHookTest method succeedsOnSkippedEventWithDataElementValueIsNullAndEventStatusSkippedOrScheduled.

@Test
void succeedsOnSkippedEventWithDataElementValueIsNullAndEventStatusSkippedOrScheduled() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, true);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setValue(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 7 with ValidationErrorReporter

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

the class EventGeoValidationHookTest method testProgramStageWithFeatureTypeNoneFailsGeometryValidation.

@Test
void testProgramStageWithFeatureTypeNoneFailsGeometryValidation() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setProgramStage(PROGRAM_STAGE);
    event.setGeometry(new GeometryFactory().createPoint());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    ProgramStage programStage = new ProgramStage();
    programStage.setFeatureType(NONE);
    when(validationContext.getProgramStage(event.getProgramStage())).thenReturn(programStage);
    this.hookToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1012, EVENT, event.getUid());
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 8 with ValidationErrorReporter

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

the class EventGeoValidationHookTest method testProgramStageWithNullFeatureTypeFailsGeometryValidation.

@Test
void testProgramStageWithNullFeatureTypeFailsGeometryValidation() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setProgramStage(PROGRAM_STAGE);
    event.setGeometry(new GeometryFactory().createPoint());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    when(validationContext.getProgramStage(event.getProgramStage())).thenReturn(new ProgramStage());
    this.hookToTest.validateEvent(reporter, event);
    // then
    hasTrackerError(reporter, E1074, EVENT, event.getUid());
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 9 with ValidationErrorReporter

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

the class EventGeoValidationHookTest method testGeometryIsValid.

@Test
void testGeometryIsValid() {
    // given
    Event event = new Event();
    event.setProgramStage(PROGRAM_STAGE);
    event.setGeometry(new GeometryFactory().createPoint());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    this.hookToTest.validateEvent(reporter, event);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 10 with ValidationErrorReporter

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

the class PreCheckDataRelationsValidationHookTest method setUp.

@BeforeEach
void setUp() {
    hook = new PreCheckDataRelationsValidationHook(categoryService);
    bundle = TrackerBundle.builder().preheat(preheat).build();
    ctx = new TrackerImportValidationContext(bundle);
    reporter = new ValidationErrorReporter(ctx);
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) BeforeEach(org.junit.jupiter.api.BeforeEach)

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