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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations