use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationWhenDataElementIsInvalid.
@Test
void failValidationWhenDataElementIsInvalid() {
setUpIdentifiers();
DataElement dataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(null);
ProgramStage programStage = programStage(dataElement);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(dataValue())).build();
hook.validateEvent(reporter, event);
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(TrackerErrorCode.E1304, reporter.getReportList().get(0).getErrorCode());
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationWhenFileResourceIsNull.
@Test
void failValidationWhenFileResourceIsNull() {
setUpIdentifiers();
DataElement validDataElement = dataElement(ValueType.FILE_RESOURCE);
when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
DataValue validDataValue = dataValue("QX4LpiTZmUH");
when(context.getFileResource(validDataValue.getValue())).thenReturn(null);
ProgramStage programStage = programStage(validDataElement);
when(context.getProgramStage(programStageUid)).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue)).build();
hook.validateEvent(reporter, event);
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(TrackerErrorCode.E1084, reporter.getReportList().get(0).getErrorCode());
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method programStage.
private ProgramStage programStage(DataElement dataElement, boolean compulsory) {
ProgramStage programStage = new ProgramStage();
programStage.setUid(programStageUid);
programStage.setProgramStageDataElements(getProgramStageDataElements(dataElement, programStage, compulsory));
return programStage;
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationWhenFileResourceValueIsNullAndDataElementIsCompulsory.
@Test
void failValidationWhenFileResourceValueIsNullAndDataElementIsCompulsory() {
setUpIdentifiers();
DataElement validDataElement = dataElement(ValueType.FILE_RESOURCE);
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.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 failsOnCompletedEventWithDataElementValueNullAndValidationStrategyOnUpdate.
@Test
void failsOnCompletedEventWithDataElementValueNullAndValidationStrategyOnUpdate() {
setUpIdentifiers();
DataElement validDataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
ProgramStage programStage = programStage(validDataElement, true);
programStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
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());
}
Aggregations