Search in sources :

Example 26 with DataSetContext

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

the class DataValueSetImportValidatorTest method testValidateDataSetExists.

/*
     * Data Set validation (should the set be aborted)
     */
@Test
void testValidateDataSetExists() {
    DataValueSet dataValueSet = createEmptyDataValueSet();
    ImportContext context = createMinimalImportContext(null).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    assertTrue(validator.abortDataSetImport(dataValueSet, context, dataSetContext));
    assertConflict(ErrorCode.E7600, "Data set not found or not accessible: `<object1>`", context, dataValueSet.getDataSet());
}
Also used : DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) Test(org.junit.jupiter.api.Test)

Example 27 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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 28 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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 29 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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 30 with DataSetContext

use of org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext 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

DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)34 Test (org.junit.jupiter.api.Test)33 DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)28 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Date (java.util.Date)2 DataInputPeriod (org.hisp.dhis.dataset.DataInputPeriod)2 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 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)1 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)1 OptionSet (org.hisp.dhis.option.OptionSet)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Period (org.hisp.dhis.period.Period)1 NotificationLevel (org.hisp.dhis.system.notification.NotificationLevel)1 Clock (org.hisp.dhis.system.util.Clock)1 DateUtils.parseDate (org.hisp.dhis.util.DateUtils.parseDate)1