use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataSetIsAccessibleByUser.
@Test
void testValidateDataSetIsAccessibleByUser() {
// simulate that user does not have access:
when(aclService.canDataRead(any(), any())).thenReturn(false);
DataValueSet dataValueSet = createEmptyDataValueSet();
ImportContext context = createMinimalImportContext(null).build();
DataSetContext dataSetContext = createMinimalDataSetContext(dataValueSet).build();
assertTrue(validator.abortDataSetImport(dataValueSet, context, dataSetContext));
assertConflict(ErrorCode.E7601, "User does not have write access for DataSet: `<object1>`", context, dataValueSet.getDataSet());
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueAttrOptionComboAccess.
@Test
void testValidateDataValueAttrOptionComboAccess() {
DataValue dataValue = createRandomDataValue();
// so that we got to later validation
dataValue.setCategoryOptionCombo(null);
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.E7616, "Attribute option combo: `<object1>` option not accessible: `<object2>`", context, dataValue.getAttributeOptionCombo(), valueContext.getAttrOptionCombo().getCategoryOptions().iterator().next().getUid());
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueOptionsExist.
@Test
void testValidateDataValueOptionsExist() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
valueContext.getDataElement().setOptionSet(new OptionSet());
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7621, "Data value is not a valid option of the data element option set: `<object1>`", context, dataValue.getDataElement());
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueOrgUnitExists.
@Test
void testValidateDataValueOrgUnitExists() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).orgUnit(null).build();
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7612, "Organisation unit not found or not accessible: `<object1>`", context, dataValue.getOrgUnit());
}
use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testCheckDataValueTodayNotPastPeriodExpiry.
@Test
void testCheckDataValueTodayNotPastPeriodExpiry() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
DataSetContext dataSetContext = createMinimalDataSetContext(createEmptyDataValueSet()).build();
ImportContext context = createMinimalImportContext(valueContext).forceDataInput(false).build();
String key = dataSetContext.getDataSet().getUid() + valueContext.getPeriod().getUid() + valueContext.getOrgUnit().getUid();
context.getDataSetLockedMap().put(key, true);
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7640, "Current date is past expiry days for period: `<object1>` and data set: `<object2>`", context, dataValue.getPeriod(), dataSetContext.getDataSet().getUid());
}
Aggregations