use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesWithAttributeOptionCombo.
@Test
void testImportDataValuesWithAttributeOptionCombo() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetD.xml").getInputStream();
ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertHasNoConflicts(summary);
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(3, dataValues.size());
assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocA)));
assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocA)));
assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocA)));
}
use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesWithNewPeriod.
@Test
void testImportDataValuesWithNewPeriod() throws Exception {
ImportSummary summary = dataValueSetService.importDataValueSetXml(new ClassPathResource("datavalueset/dataValueSetC.xml").getInputStream());
assertHasNoConflicts(summary);
assertEquals(3, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(0, summary.getImportCount().getIgnored());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(3, dataValues.size());
}
use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesUpdatedSkipAudit.
@Test
void testImportDataValuesUpdatedSkipAudit() throws Exception {
// as existing we return the imported DataValue with changed comment
// to prevent the update from being skipped
mockDataValueBatchHandler.withFindObject(dataValue -> dataValue.toBuilder().comment(dataValue.getComment() + "42").build());
in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
ImportOptions importOptions = new ImportOptions();
importOptions.setSkipAudit(true);
ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
assertNotNull(summary);
assertNotNull(summary.getImportCount());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertHasNoConflicts(summary);
Collection<DataValue> dataValues = mockDataValueBatchHandler.getUpdates();
Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(3, dataValues.size());
assertEquals(0, auditValues.size());
}
use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testCheckDataValueStrictCategoryOptionCombos.
@Test
void testCheckDataValueStrictCategoryOptionCombos() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = createDataValueContext(dataValue).build();
valueContext.getDataElement().setCategoryCombo(new CategoryCombo());
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).strictCategoryOptionCombos(true).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7634, "Category option combo: `<object1>` must be part of category combo of data element: `<object2>`", context, dataValue.getCategoryOptionCombo(), dataValue.getDataElement());
}
use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetImportValidatorTest method testValidateDataValueDataElementExists.
/*
* Data Value validation (should the entry be skipped)
*/
@Test
void testValidateDataValueDataElementExists() {
DataValue dataValue = createRandomDataValue();
DataValueContext valueContext = DataValueContext.builder().build();
DataSetContext dataSetContext = createMinimalDataSetContext().build();
ImportContext context = createMinimalImportContext(valueContext).build();
assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
assertConflict(ErrorCode.E7610, "Data element not found or not accessible: `<object1>`", context, dataValue.getDataElement());
}
Aggregations