Search in sources :

Example 51 with DataValueSet

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

the class DataValueSetImportValidatorTest method createMinimalDataSetContext.

private DataSetContextBuilder createMinimalDataSetContext(DataValueSet dataValueSet) {
    DataSetContextBuilder builder = DataSetContext.builder();
    if (dataValueSet != null) {
        String dsId = dataValueSet.getDataSet();
        if (dsId != null) {
            DataSet ds = new DataSet();
            ds.setUid(dsId);
            builder.dataSet(ds);
        }
    }
    return builder;
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) DataSetContextBuilder(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext.DataSetContextBuilder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 52 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesInvalidAttributeOptionComboDates.

@Test
void testImportDataValuesInvalidAttributeOptionComboDates() throws Exception {
    clearSecurityContext();
    categoryOptionA.setStartDate(peB.getStartDate());
    categoryOptionA.setEndDate(peB.getEndDate());
    categoryService.updateCategoryOption(categoryOptionA);
    in = new ClassPathResource("datavalueset/dataValueSetH.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(2, summary.getConflictCount(), summary.getConflictsDescription());
    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());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deB, peB, ouB, ocDef, ocA)));
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) 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 53 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesCsvWithoutHeader.

@Test
void testImportDataValuesCsvWithoutHeader() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBNoHeader.csv").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetCsv(in, new ImportOptions().setFirstRowIsHeader(false), null);
    assertEquals(12, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    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 54 with DataValueSet

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

the class DataValueSetServiceTest method testImportValueCategoryOptionWriteOk.

/**
 * User has data write access for DataSet and CategoryOption
 *
 * @throws IOException
 */
@Test
void testImportValueCategoryOptionWriteOk() throws IOException {
    enableDataSharing(user, dsA, AccessStringHelper.DATA_READ_WRITE);
    enableDataSharing(user, categoryOptionA, AccessStringHelper.DATA_READ_WRITE);
    enableDataSharing(user, categoryOptionB, AccessStringHelper.DATA_READ_WRITE);
    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 55 with DataValueSet

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

the class DataValueSetServiceTest method testImportValueCatComboOk.

/**
 * User has data write access for DataSet and also categoryOptions Expect
 * success
 *
 * @throws IOException
 */
@Test
void testImportValueCatComboOk() throws IOException {
    enableDataSharing(user, dsA, AccessStringHelper.DATA_READ_WRITE);
    enableDataSharing(user, categoryOptionA, AccessStringHelper.DATA_WRITE);
    enableDataSharing(user, categoryOptionB, AccessStringHelper.DATA_WRITE);
    in = new ClassPathResource("datavalueset/dataValueSetACatCombo.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)

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