use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValueSetXmlPreheatCache.
@Test
void testImportDataValueSetXmlPreheatCache() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
ImportOptions importOptions = new ImportOptions().setPreheatCache(true);
ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
assertNotNull(summary);
assertNotNull(summary.getImportCount());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertHasNoConflicts(summary);
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(3, dataValues.size());
assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
assertEquals("10002", ((List<DataValue>) dataValues).get(1).getValue());
assertEquals("10003", ((List<DataValue>) dataValues).get(2).getValue());
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
assertNotNull(registration);
assertEquals(dsA, registration.getDataSet());
assertEquals(peA, registration.getPeriod());
assertEquals(ouA, registration.getSource());
assertEquals(getDate(2012, 1, 9), registration.getDate());
assertEquals(0, auditValues.size());
}
use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesWithCategoryOptionComboIdScheme.
@Test
void testImportDataValuesWithCategoryOptionComboIdScheme() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetCCode.xml").getInputStream();
ImportOptions options = new ImportOptions().setCategoryOptionComboIdScheme("CODE");
ImportSummary summary = dataValueSetService.importDataValueSetXml(in, options);
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 testImportDataValuesUpdatedAudit.
@Test
void testImportDataValuesUpdatedAudit() throws Exception {
// as existing we return the imported DataValue with changed value
// to prevent the update from being skipped
mockDataValueBatchHandler.withFindObject(dataValue -> dataValue.toBuilder().value(dataValue.getValue() + "42").build());
in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
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());
assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
assertEquals("10002", ((List<DataValue>) dataValues).get(1).getValue());
assertEquals("10003", ((List<DataValue>) dataValues).get(2).getValue());
assertEquals(3, auditValues.size());
}
use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesUpdatedSkipNoChange.
@Test
void testImportDataValuesUpdatedSkipNoChange() throws Exception {
mockDataValueBatchHandler.withFindSelf(true);
in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
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, summary.getImportCount().getUpdated());
assertEquals(0, dataValues.size(), "Updates to unchanged data values were not skipped");
assertEquals(0, auditValues.size(), "Updates to unchanged data value did not skip audit");
}
use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesXmlWithCodeA.
@Test
void testImportDataValuesXmlWithCodeA() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetACode.xml").getInputStream();
ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
assertNotNull(summary);
assertNotNull(summary.getImportCount());
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertHasNoConflicts(summary);
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(3, dataValues.size());
assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
assertNotNull(registration);
assertEquals(dsA, registration.getDataSet());
assertEquals(peA, registration.getPeriod());
assertEquals(ouA, registration.getSource());
assertEquals(getDate(2012, 1, 9), registration.getDate());
assertEquals(0, auditValues.size());
}
Aggregations