use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesWithInvalidAttributeOptionCombo.
@Test
void testImportDataValuesWithInvalidAttributeOptionCombo() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetF.xml").getInputStream();
ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
assertEquals(0, summary.getImportCount().getImported());
assertEquals(ImportStatus.ERROR, summary.getStatus());
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(0, dataValues.size());
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesWithStrictCategoryOptionCombos.
@Test
void testImportDataValuesWithStrictCategoryOptionCombos() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
ImportOptions options = new ImportOptions().setStrictCategoryOptionCombos(true);
ImportSummary summary = dataValueSetService.importDataValueSetXml(in, options);
assertEquals(1, summary.getConflictCount(), summary.getConflictsDescription());
assertEquals(2, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(1, summary.getImportCount().getIgnored());
assertEquals(ImportStatus.WARNING, summary.getStatus());
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportNullDataValues.
@Test
void testImportNullDataValues() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetANull.xml").getInputStream();
ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
assertEquals(ImportStatus.WARNING, summary.getStatus());
assertEquals(2, summary.getImportCount().getIgnored());
assertEquals(1, summary.getImportCount().getImported());
assertEquals(2, summary.getConflictCount(), summary.getConflictsDescription());
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(1, dataValues.size());
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesXmlWithAttribute.
@Test
void testImportDataValuesXmlWithAttribute() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetBAttribute.xml").getInputStream();
ImportOptions importOptions = new ImportOptions().setIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID).setDataElementIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID).setOrgUnitIdScheme(IdScheme.ATTR_ID_SCHEME_PREFIX + ATTRIBUTE_UID);
ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
assertHasNoConflicts(summary);
assertEquals(12, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(0, summary.getImportCount().getIgnored());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertImportDataValues(summary);
}
use of org.hisp.dhis.dxf2.datavalueset.DataValueSet in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesWithDataSetAllowsPeriods.
@Test
void testImportDataValuesWithDataSetAllowsPeriods() {
clearSecurityContext();
Date thisMonth = DateUtils.truncate(new Date(), Calendar.MONTH);
dsA.setExpiryDays(62);
dsA.setOpenFuturePeriods(2);
dataSetService.updateDataSet(dsA);
Period tooEarly = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 4));
Period okBefore = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 1));
Period okAfter = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -1));
Period tooLate = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -4));
Period outOfRange = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 6));
periodService.addPeriod(tooEarly);
periodService.addPeriod(okBefore);
periodService.addPeriod(okAfter);
periodService.addPeriod(tooLate);
String importData = "<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0\" idScheme=\"code\" dataSet=\"DS_A\" orgUnit=\"OU_A\">\n" + " <dataValue dataElement=\"DE_A\" period=\"" + tooEarly.getIsoDate() + "\" value=\"10001\" />\n" + " <dataValue dataElement=\"DE_B\" period=\"" + okBefore.getIsoDate() + "\" value=\"10002\" />\n" + " <dataValue dataElement=\"DE_C\" period=\"" + okAfter.getIsoDate() + "\" value=\"10003\" />\n" + " <dataValue dataElement=\"DE_D\" period=\"" + tooLate.getIsoDate() + "\" value=\"10004\" />\n" + " <dataValue dataElement=\"DE_D\" period=\"" + outOfRange.getIsoDate() + "\" value=\"10005\" />\n" + "</dataValueSet>\n";
in = new ByteArrayInputStream(importData.getBytes(StandardCharsets.UTF_8));
ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
assertEquals(3, summary.getConflictCount(), summary.getConflictsDescription());
assertEquals(2, summary.getImportCount().getImported());
assertEquals(0, summary.getImportCount().getUpdated());
assertEquals(0, summary.getImportCount().getDeleted());
assertEquals(3, summary.getImportCount().getIgnored());
assertEquals(ImportStatus.WARNING, summary.getStatus());
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(2, dataValues.size());
assertTrue(dataValues.contains(new DataValue(deB, okBefore, ouA, ocDef, ocDef)));
assertTrue(dataValues.contains(new DataValue(deC, okAfter, ouA, ocDef, ocDef)));
}
Aggregations