use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method successValidationDataElementOptionValueIsValid.
@Test
void successValidationDataElementOptionValueIsValid() {
setUpIdentifiers();
DataValue validDataValue = dataValue("code");
DataValue nullDataValue = dataValue(null);
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(option, option1));
DataElement dataElement = dataElement();
dataElement.setOptionSet(optionSet);
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
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(validDataValue, nullDataValue)).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationDataElementOptionValueIsInValid.
@Test
void failValidationDataElementOptionValueIsInValid() {
setUpIdentifiers();
DataValue validDataValue = dataValue("value");
validDataValue.setDataElement(dataElementUid);
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(option, option1));
DataElement dataElement = dataElement();
dataElement.setOptionSet(optionSet);
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
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(validDataValue)).build();
hook.validateEvent(reporter, event);
assertTrue(reporter.hasErrors());
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(1, reporter.getReportList().stream().filter(e -> e.getErrorCode() == TrackerErrorCode.E1125).count());
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class TrackedEntityAttributeValidationHookTest method getTrackedEntityAttributeWithOptionSet.
private TrackedEntityAttribute getTrackedEntityAttributeWithOptionSet() {
TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
trackedEntityAttribute.setUid("uid");
trackedEntityAttribute.setValueType(ValueType.TEXT);
OptionSet optionSet = new OptionSet();
Option option = new Option();
option.setCode("CODE");
Option option1 = new Option();
option1.setCode("CODE1");
optionSet.setOptions(Arrays.asList(option, option1));
trackedEntityAttribute.setOptionSet(optionSet);
return trackedEntityAttribute;
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class DhisConvenienceTest method createOptionSet.
public static OptionSet createOptionSet(char uniqueCharacter) {
OptionSet optionSet = new OptionSet();
optionSet.setAutoFields();
optionSet.setName("OptionSet" + uniqueCharacter);
optionSet.setCode("OptionSetCode" + uniqueCharacter);
return optionSet;
}
use of org.hisp.dhis.option.OptionSet in project dhis2-core by dhis2.
the class DhisConvenienceTest method createOptionSet.
public static OptionSet createOptionSet(char uniqueCharacter, Option... options) {
OptionSet optionSet = createOptionSet(uniqueCharacter);
for (Option option : options) {
optionSet.getOptions().add(option);
option.setOptionSet(optionSet);
}
return optionSet;
}
Aggregations