Search in sources :

Example 61 with DataValueSet

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

the class DataValueSetServiceTest method testImportValueDefaultCatComboOk.

/**
 * User has data write access for DataSet DataValue use default category
 * combo Expect success
 *
 * @throws IOException
 */
@Test
void testImportValueDefaultCatComboOk() throws IOException {
    clearSecurityContext();
    enableDataSharing(user, dsA, AccessStringHelper.DATA_READ_WRITE);
    dataSetService.updateDataSet(dsA);
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 62 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesWithRequiredCategoryOptionCombo.

@Test
void testImportDataValuesWithRequiredCategoryOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setRequireCategoryOptionCombo(true);
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in, options);
    String description = summary.getConflictsDescription();
    assertEquals(2, summary.getTotalConflictOccurrenceCount(), description);
    assertEquals(1, summary.getConflictCount(), description);
    assertArrayEquals(new int[] { 1, 2 }, summary.getConflicts().iterator().next().getIndexes());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(2, 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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 63 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesWithRequiredAttributeOptionCombo.

@Test
void testImportDataValuesWithRequiredAttributeOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setRequireAttributeOptionCombo(true);
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in, options);
    String description = summary.getConflictsDescription();
    assertEquals(2, summary.getTotalConflictOccurrenceCount(), description);
    assertEquals(1, summary.getConflictCount(), description);
    assertArrayEquals(new int[] { 0, 2 }, summary.getConflicts().iterator().next().getIndexes());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(2, 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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 64 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesXmlWithCodeB.

@Test
void testImportDataValuesXmlWithCodeB() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBCode.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setIdScheme("CODE").setDataElementIdScheme("CODE").setOrgUnitIdScheme("CODE");
    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);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 65 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesWithStrictAttributeOptionCombos.

@Test
void testImportDataValuesWithStrictAttributeOptionCombos() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetNonStrict.xml").getInputStream();
    ImportOptions options = new ImportOptions().setStrictAttributeOptionCombos(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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)63 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)56 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)41 ClassPathResource (org.springframework.core.io.ClassPathResource)39 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)24 DataValue (org.hisp.dhis.datavalue.DataValue)21 DhisTest (org.hisp.dhis.DhisTest)12 DataValueSet (org.hisp.dhis.dxf2.datavalueset.DataValueSet)9 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)8 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)8 DataSet (org.hisp.dhis.dataset.DataSet)6 Period (org.hisp.dhis.period.Period)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 ImportCount (org.hisp.dhis.dxf2.importsummary.ImportCount)5 ListGrid (org.hisp.dhis.system.grid.ListGrid)5 IdScheme (org.hisp.dhis.common.IdScheme)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 IdentifiableObjectCallable (org.hisp.dhis.system.callable.IdentifiableObjectCallable)4 Date (java.util.Date)3 List (java.util.List)3