Search in sources :

Example 96 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue 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");
}
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 97 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue 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());
}
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 98 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue 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());
}
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 99 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue 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());
}
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 100 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue 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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataInputPeriod(org.hisp.dhis.dataset.DataInputPeriod) Period(org.hisp.dhis.period.Period) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)58 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)33 DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)32 DataValue (org.hisp.dhis.datavalue.DataValue)31 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)29 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 DataElement (org.hisp.dhis.dataelement.DataElement)26 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)26 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)21 Event (org.hisp.dhis.dxf2.events.event.Event)20 ClassPathResource (org.springframework.core.io.ClassPathResource)20 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)16 Period (org.hisp.dhis.period.Period)16 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)11 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)11 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)8 User (org.hisp.dhis.user.User)8