Search in sources :

Example 11 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesCsv.

@Test
public void testImportDataValuesCsv() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.csv").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSetCsv(in, null, null);
    // Header row
    assertEquals(summary.getConflicts().toString(), 1, summary.getConflicts().size());
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    // Header row
    assertEquals(1, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    assertImportDataValues(summary);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesUpdatedAudit.

@Test
public void testImportDataValuesUpdatedAudit() throws Exception {
    mockDataValueBatchHandler.withFindSelf(true);
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    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)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
    assertEquals(3, auditValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesWithStrictOrganisationUnits.

@Test
public void testImportDataValuesWithStrictOrganisationUnits() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setStrictOrganisationUnits(true);
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, options);
    assertEquals(summary.getConflicts().toString(), 1, summary.getConflicts().size());
    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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 14 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesXmlWithAttributeIdSchemeInPayload.

@Test
public void testImportDataValuesXmlWithAttributeIdSchemeInPayload() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBAttributeIdScheme.xml").getInputStream();
    // Identifier schemes specified in XML message
    ImportOptions importOptions = new ImportOptions();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    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);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 15 with DataValueSet

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

the class DataValueSetServiceIntegrationTest method testImportReverseDeletedValuesXml.

/**
     * Import 12 data values where 4 are marked as deleted. Then import 12 data
     * values which reverse deletion of the 4 values and update the other 8 
     * values.
     */
@Test
public void testImportReverseDeletedValuesXml() throws Exception {
    assertEquals(0, dataValueService.getAllDataValues().size());
    in = new ClassPathResource("datavalueset/dataValueSetBDeleted.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(8, dataValueService.getAllDataValues().size());
    // Reverse deletion and update
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(4, summary.getImportCount().getImported());
    assertEquals(8, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(12, dataValueService.getAllDataValues().size());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)45 Test (org.junit.Test)43 ClassPathResource (org.springframework.core.io.ClassPathResource)39 DhisSpringTest (org.hisp.dhis.DhisSpringTest)31 DataValue (org.hisp.dhis.datavalue.DataValue)18 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)17 DhisTest (org.hisp.dhis.DhisTest)10 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)5 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)5 Period (org.hisp.dhis.period.Period)4 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)3 DataSet (org.hisp.dhis.dataset.DataSet)3 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)2 IdScheme (org.hisp.dhis.common.IdScheme)2 IdSchemes (org.hisp.dhis.common.IdSchemes)2 CachingMap (org.hisp.dhis.commons.collection.CachingMap)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)2 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)2 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)2