Search in sources :

Example 36 with OptionSet

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());
}
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) Option(org.hisp.dhis.option.Option) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) OptionSet(org.hisp.dhis.option.OptionSet) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 37 with OptionSet

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());
}
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) Option(org.hisp.dhis.option.Option) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) OptionSet(org.hisp.dhis.option.OptionSet) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 38 with OptionSet

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;
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet)

Example 39 with 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) {
    OptionSet optionSet = new OptionSet();
    optionSet.setAutoFields();
    optionSet.setName("OptionSet" + uniqueCharacter);
    optionSet.setCode("OptionSetCode" + uniqueCharacter);
    return optionSet;
}
Also used : OptionSet(org.hisp.dhis.option.OptionSet)

Example 40 with 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;
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet)

Aggregations

OptionSet (org.hisp.dhis.option.OptionSet)40 Option (org.hisp.dhis.option.Option)24 Test (org.junit.jupiter.api.Test)20 DataElement (org.hisp.dhis.dataelement.DataElement)12 List (java.util.List)10 ArrayList (java.util.ArrayList)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 OptionGroup (org.hisp.dhis.option.OptionGroup)6 OptionGroupSet (org.hisp.dhis.option.OptionGroupSet)6 HashSet (java.util.HashSet)5 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)5 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 User (org.hisp.dhis.user.User)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 Map (java.util.Map)4 CategoryOption (org.hisp.dhis.category.CategoryOption)4