use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method successValidationWhenDataElementIsNullAndDataElementIsNotCompulsory.
@Test
void successValidationWhenDataElementIsNullAndDataElementIsNotCompulsory() {
setUpIdentifiers();
DataElement validDataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
ProgramStage programStage = programStage(validDataElement, false);
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);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method successValidationWhenFileResourceValueIsNullAndDataElementIsNotCompulsory.
@Test
void successValidationWhenFileResourceValueIsNullAndDataElementIsNotCompulsory() {
setUpIdentifiers();
DataElement validDataElement = dataElement(ValueType.FILE_RESOURCE);
when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
ProgramStage programStage = programStage(validDataElement, false);
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);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class AssignedUserValidationHookTest method testEventWithNullEnabledUserAssignment.
@Test
void testEventWithNullEnabledUserAssignment() {
// given
Event event = new Event();
event.setEvent(CodeGenerator.generateUid());
event.setAssignedUser(USER_ID);
event.setProgramStage(PROGRAM_STAGE);
ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
// when
ProgramStage programStage = new ProgramStage();
programStage.setEnableUserAssignment(null);
when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
this.hookToTest.validateEvent(reporter, event);
// then
assertFalse(reporter.hasErrors());
assertTrue(reporter.hasWarnings());
assertTrue(reporter.hasWarningReport(r -> E1120.equals(r.getWarningCode()) && TrackerType.EVENT.equals(r.getTrackerType()) && event.getUid().equals(r.getUid())));
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class DataValueFilteringTestSupport method getProgramStages.
public static Set<ProgramStage> getProgramStages() {
ProgramStage programStage = new ProgramStage();
programStage.setProgramStageDataElements(getProgramStageDataElements(DATA_ELEMENT_1, DATA_ELEMENT_3));
programStage.setUid(PROGRAMSTAGE);
return Sets.newHashSet(programStage);
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class DataValueCheckTest method verifyValidationFailOnJsonSerializationError.
@Test
void verifyValidationFailOnJsonSerializationError() throws JsonProcessingException {
ObjectMapper localObjectMapper = mock(ObjectMapper.class);
when(serviceDelegator.getJsonMapper()).thenReturn(localObjectMapper);
when(localObjectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonProcessingException("Error") {
});
event.setProgramStage("prgstg1");
DataElement de1 = addToDataElementMap(createDataElement('A'));
final Program programA = createProgram('A');
final ProgramStage programStageA = createProgramStage('A', programA);
programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true)));
when(workContext.getProgramStage(IdScheme.UID, "prgstg1")).thenReturn(programStageA);
addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"));
DataValue dv1 = createDataValue(de1.getUid(), "1");
event.setDataValues(Sets.newHashSet(dv1));
final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
assertHasError(summary, event, null);
assertHasConflict(summary, "Invalid data value found.", de1.getUid());
}
Aggregations