Search in sources :

Example 21 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testCheckDataValueStrictAttrOptionCombos.

@Test
void testCheckDataValueStrictAttrOptionCombos() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).strictAttrOptionCombos(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7635, "Attribute option combo: `<object1>` must be part of category combo of data sets of data element: `<object2>`", context, dataValue.getAttributeOptionCombo(), dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 22 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testCheckDataValuePeriodType.

@Test
void testCheckDataValuePeriodType() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).strictPeriods(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7632, "Period type of period: `<object1>` not valid for data element: `<object2>`", context, dataValue.getPeriod(), dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 23 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testCheckDataValuePeriodWithinAttrOptionComboRange.

@Test
void testCheckDataValuePeriodWithinAttrOptionComboRange() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    String key = valueContext.getAttrOptionCombo().getUid() + valueContext.getDataElement().getUid();
    context.getAttrOptionComboDateRangeMap().put(key, new DateRange(new Date(), null));
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7638, "Period: `<object1>` is not within date range of attribute option combo: `<object2>`", context, dataValue.getPeriod(), dataValue.getAttributeOptionCombo());
}
Also used : DateRange(org.hisp.dhis.common.DateRange) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 24 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testValidateDataValueCommentIsValid.

@Test
void testValidateDataValueCommentIsValid() {
    DataValue dataValue = createRandomDataValue();
    char[] chars = new char[50001];
    Arrays.fill(chars, 'a');
    dataValue.setComment(new String(chars));
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7620, "Invalid comment: comment_length_greater_than_max_length", context, "comment_length_greater_than_max_length");
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 25 with DataValueContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testCheckDataValueOrgUnitValidForAttrOptionCombo.

@Test
void testCheckDataValueOrgUnitValidForAttrOptionCombo() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    String key = valueContext.getAttrOptionCombo().getUid() + valueContext.getOrgUnit().getUid();
    context.getAttrOptionComboOrgUnitMap().put(key, false);
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7639, "Organisation unit: `<object1>` is not valid for attribute option combo: `<object2>`", context, dataValue.getOrgUnit(), dataValue.getAttributeOptionCombo());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Aggregations

DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)28 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)28 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 Test (org.junit.jupiter.api.Test)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 DataInputPeriod (org.hisp.dhis.dataset.DataInputPeriod)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 Date (java.util.Date)1 CategoryCombo (org.hisp.dhis.category.CategoryCombo)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DateRange (org.hisp.dhis.common.DateRange)1 DataApprovalWorkflow (org.hisp.dhis.dataapproval.DataApprovalWorkflow)1 DataElement (org.hisp.dhis.dataelement.DataElement)1 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)1 OptionSet (org.hisp.dhis.option.OptionSet)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 User (org.hisp.dhis.user.User)1