use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueIsValid.
@Test
void testValidateDataValueIsValid() {
DataValue dataValue = createRandomDataValue();
dataValue.setValue("not-a-bool");
DataValueContext valueContext = createDataValueContext(dataValue).build();
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7619, "Value must match data element's `<object1>` type constraints: value_not_bool", context, dataValue.getDataElement(), "value_not_bool");
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueIsDefined.
@Test
void testValidateDataValueIsDefined() {
DataValue dataValue = createRandomDataValue();
dataValue.setComment(null);
dataValue.setValue(null);
DataValueContext valueContext = createDataValueContext(dataValue).build();
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7618, "Data value or comment not specified for data element: `" + dataValue.getDataElement() + "`", context, dataValue.getDataElement());
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testCheckDataValueConformsToOpenPeriodsOfAssociatedDataSets.
@Test
void testCheckDataValueConformsToOpenPeriodsOfAssociatedDataSets() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).build();
String key = valueContext.getDataElement().getUid() + valueContext.getPeriod().getIsoDate();
context.getPeriodOpenForDataElement().put(key, false);
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7644, "Period: `<object1>` does not conform to the open periods of associated data sets", context, dataValue.getPeriod());
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueCategoryOptionComboAccess.
@Test
void testValidateDataValueCategoryOptionComboAccess() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
setupUserCanWriteCategoryOptions(false);
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7614, "Category option combo: `<object1>` option not accessible: `<object2>`", context, dataValue.getCategoryOptionCombo(), valueContext.getCategoryOptionCombo().getCategoryOptions().iterator().next().getUid());
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testCheckDataValueFileResourceExists.
@Test
void testCheckDataValueFileResourceExists() {
DataValue dataValue = createRandomDataValue();
dataValue.setValue(CodeGenerator.generateUid());
DataValueContext valueContext = createDataValueContext(dataValue).build();
valueContext.getDataElement().setValueType(ValueType.FILE_RESOURCE);
DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).strategy(ImportStrategy.DELETE).build();
when(dataValueService.getDataValue(any(DataElement.class), any(Period.class), any(OrganisationUnit.class), any(CategoryOptionCombo.class), any(CategoryOptionCombo.class))).thenReturn(null);
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7645, "No data value for file resource exist for the given combination for data element: `<object1>`", context, dataValue.getDataElement());
}
Aggregations