Search in sources :

Example 56 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesWithOrgUnitOutsideHierarchy.

@Test
void testImportDataValuesWithOrgUnitOutsideHierarchy() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetE.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    assertEquals(2, summary.getConflictCount(), summary.getConflictsDescription());
    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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 57 with DataValueSet

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

the class DataValueSetServiceTest method testImportValueDataSetWriteFail.

/**
 * User does not have data write access for DataSet Expect fail on data
 * sharing check
 *
 * @throws IOException
 */
@Test
void testImportValueDataSetWriteFail() throws IOException {
    clearSecurityContext();
    List<User> allUsers = userService.getAllUsers();
    enableDataSharing(user, dsA, AccessStringHelper.READ);
    dataSetService.updateDataSet(dsB);
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.ERROR, summary.getStatus());
}
Also used : User(org.hisp.dhis.user.User) 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 58 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValueWithNewPeriods.

@Test
void testImportDataValueWithNewPeriods() {
    Period period200006 = periodService.getPeriod("200006");
    Period period200007 = periodService.getPeriod("200007");
    Period period200008 = periodService.getPeriod("200008");
    assertNull(period200006);
    assertNull(period200007);
    assertNull(period200008);
    String importData = "<dataValueSet xmlns=\"http://dhis2.org/schema/dxf/2.0\" idScheme=\"code\" dataSet=\"DS_A\" orgUnit=\"OU_A\">\n" + "  <dataValue dataElement=\"DE_A\" period=\"200006\" value=\"10001\" />\n" + "  <dataValue dataElement=\"DE_B\" period=\"200006\" value=\"10002\" />\n" + "  <dataValue dataElement=\"DE_C\" period=\"200007\" value=\"10003\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"200007\" value=\"10004\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"200008\" value=\"10005\" />\n" + "</dataValueSet>\n";
    in = new ByteArrayInputStream(importData.getBytes(StandardCharsets.UTF_8));
    ImportSummary summary = dataValueSetServiceNoMocks.importDataValueSetXml(in);
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertEquals(5, summary.getImportCount().getImported());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Period(org.hisp.dhis.period.Period) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 59 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesXmlUpdatesOnly.

@Test
void testImportDataValuesXmlUpdatesOnly() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setImportStrategy(ImportStrategy.UPDATES);
    IdSchemes idSchemes = new IdSchemes();
    idSchemes.setIdScheme("UID");
    idSchemes.setDataElementIdScheme("UID");
    idSchemes.setOrgUnitIdScheme("UID");
    importOptions.setIdSchemes(idSchemes);
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
    assertHasNoConflicts(summary);
    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(12, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(0, dataValues.size());
}
Also used : IdSchemes(org.hisp.dhis.common.IdSchemes) DataValue(org.hisp.dhis.datavalue.DataValue) 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 60 with DataValueSet

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

the class DataValueSetServiceTest method testImportDataValuesXml.

@Test
void testImportDataValuesXml() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    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) 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