Search in sources :

Example 91 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesWithOrgUnitOutsideHierarchy.

@Test
public void testImportDataValuesWithOrgUnitOutsideHierarchy() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetE.xml").getInputStream();
    ImportSummary summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    assertEquals(summary.getConflicts().toString(), 2, summary.getConflicts().size());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocA)));
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 92 with ImportSummary

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

the class DataValueSetServiceTest method testImportDataValuesWithStrictAttributeOptionCombos.

@Test
public void testImportDataValuesWithStrictAttributeOptionCombos() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setStrictAttributeOptionCombos(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 93 with ImportSummary

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

the class RegistrationMultiEventsServiceTest method testSaveWithoutProgramStageShouldFail.

@Test
@Category(IntegrationTest.class)
public void testSaveWithoutProgramStageShouldFail() {
    Event event = createEvent(programA.getUid(), null, organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, null);
    assertEquals(ImportStatus.ERROR, importSummary.getStatus());
    assertThat(importSummary.getDescription(), CoreMatchers.containsString("Event.programStage does not point to a valid programStage"));
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 94 with ImportSummary

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

the class DataValueSetServiceIntegrationTest method testImportAddAndReverseDeletedValuesXml.

/**
     * Import 12 data values where 4 are marked as deleted. Then import 12 data
     * values which reverse deletion of the 4 values, update 4 values and add 4 
     * values.
     */
@Test
public void testImportAddAndReverseDeletedValuesXml() 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/dataValueSetBNew.xml").getInputStream();
    summary = dataValueSetService.saveDataValueSet(in);
    assertEquals(8, 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(16, 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 95 with ImportSummary

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

the class DataValueSetServiceIntegrationTest method testImportValuesXml.

/**
     * Import 12 data values.
     */
@Test
public void testImportValuesXml() 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(0, 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)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