Search in sources :

Example 66 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method failsOnCompletedEventWithDataElementValueIsNullAndValidationStrategyOnComplete.

@Test
void failsOnCompletedEventWithDataElementValueIsNullAndValidationStrategyOnComplete() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, true);
    programStage.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
    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.COMPLETED).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertThat(reporter.getReportList(), hasSize(1));
    assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
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 67 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method failValidationWhenUpdatedAtIsNull.

@Test
void failValidationWhenUpdatedAtIsNull() {
    setUpIdentifiers();
    DataElement dataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
    ProgramStage programStage = programStage(dataElement);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setUpdatedAt(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 68 with ProgramStage

use of org.hisp.dhis.program.ProgramStage 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 69 with ProgramStage

use of org.hisp.dhis.program.ProgramStage 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 70 with ProgramStage

use of org.hisp.dhis.program.ProgramStage 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)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)209 Test (org.junit.jupiter.api.Test)86 Program (org.hisp.dhis.program.Program)82 DataElement (org.hisp.dhis.dataelement.DataElement)67 Event (org.hisp.dhis.tracker.domain.Event)47 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)40 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)39 ProgramInstance (org.hisp.dhis.program.ProgramInstance)38 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)26 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)22 DataValue (org.hisp.dhis.tracker.domain.DataValue)22 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 User (org.hisp.dhis.user.User)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)17 ArrayList (java.util.ArrayList)16 Date (java.util.Date)16 List (java.util.List)16 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)16 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)16