Search in sources :

Example 16 with ImportSummary

use of org.hisp.dhis.dxf2.common.ImportSummary 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)

Example 17 with ImportSummary

use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceIntegrationTest method testDeleteValuesXml.

/**
     * Import 12 data values. Then import 12 values where 4 are marked as
     * deleted.
     */
@Test
public void testDeleteValuesXml() throws Exception {
    assertEquals(0, dataValueService.getAllDataValues().size());
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(12, dataValueService.getAllDataValues().size());
    // Delete 4 values
    in = new ClassPathResource("datavalueset/dataValueSetBDeleted.xml").getInputStream();
    summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(8, summary.getImportCount().getUpdated());
    assertEquals(4, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(8, 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)

Example 18 with ImportSummary

use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceIntegrationTest method testImportValuesDeleteStrategyXml.

/**
     * Import 12 data values. Then import the same 12 data values with import
     * strategy delete.
     */
@Test
public void testImportValuesDeleteStrategyXml() throws Exception {
    assertEquals(0, dataValueService.getAllDataValues().size());
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(12, dataValueService.getAllDataValues().size());
    // Import with delete strategy
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportOptions options = new ImportOptions().setStrategy(ImportStrategy.DELETE);
    summary = dataValueSetService.saveDataValueSet(in, options);
    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(12, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(0, dataValueService.getAllDataValues().size());
}
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) DhisTest(org.hisp.dhis.DhisTest)

Example 19 with ImportSummary

use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceIntegrationTest method testImportUpdateValuesXml.

/**
     * Import 12 data values. Then import 6 data values, where 4 are updates.
     */
@Test
public void testImportUpdateValuesXml() throws Exception {
    assertEquals(0, dataValueService.getAllDataValues().size());
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(12, dataValueService.getAllDataValues().size());
    // Update
    in = new ClassPathResource("datavalueset/dataValueSetBUpdate.xml").getInputStream();
    summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(4, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(14, 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)

Example 20 with ImportSummary

use of org.hisp.dhis.dxf2.common.ImportSummary in project dhis2-core by dhis2.

the class DataValueSetServiceIntegrationTest method testImportDeletedValuesXml.

/**
     * Import 12 data values where 4 are marked as deleted. Deleted values should
     * count as imports when there are no existing non-deleted matching values.
     */
@Test
public void testImportDeletedValuesXml() 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(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(8, 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)102 Test (org.junit.Test)58 DhisSpringTest (org.hisp.dhis.DhisSpringTest)49 ClassPathResource (org.springframework.core.io.ClassPathResource)39 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)25 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)22 DataValue (org.hisp.dhis.datavalue.DataValue)18 Event (org.hisp.dhis.dxf2.events.event.Event)17 InputStream (java.io.InputStream)14 Date (java.util.Date)11 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)11 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)11 IOException (java.io.IOException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)10 DhisTest (org.hisp.dhis.DhisTest)9 DhisApiVersion (org.hisp.dhis.common.DhisApiVersion)7 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportStatus (org.hisp.dhis.dxf2.importsummary.ImportStatus)7 ApiVersion (org.hisp.dhis.webapi.mvc.annotation.ApiVersion)7