Search in sources :

Example 76 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue 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 77 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue 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 78 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithInvalidAttributeOptionCombo.

@Test
void testImportDataValuesWithInvalidAttributeOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetF.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(0, summary.getImportCount().getImported());
    assertEquals(ImportStatus.ERROR, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(0, dataValues.size());
}
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 79 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportNullDataValues.

@Test
void testImportNullDataValues() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetANull.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    assertEquals(2, summary.getImportCount().getIgnored());
    assertEquals(1, summary.getImportCount().getImported());
    assertEquals(2, summary.getConflictCount(), summary.getConflictsDescription());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
}
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 80 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class DataValueSetServiceTest method testImportDataValuesWithDataSetAllowsPeriods.

@Test
void testImportDataValuesWithDataSetAllowsPeriods() {
    clearSecurityContext();
    Date thisMonth = DateUtils.truncate(new Date(), Calendar.MONTH);
    dsA.setExpiryDays(62);
    dsA.setOpenFuturePeriods(2);
    dataSetService.updateDataSet(dsA);
    Period tooEarly = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 4));
    Period okBefore = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 1));
    Period okAfter = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -1));
    Period tooLate = createMonthlyPeriod(DateUtils.addMonths(thisMonth, -4));
    Period outOfRange = createMonthlyPeriod(DateUtils.addMonths(thisMonth, 6));
    periodService.addPeriod(tooEarly);
    periodService.addPeriod(okBefore);
    periodService.addPeriod(okAfter);
    periodService.addPeriod(tooLate);
    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=\"" + tooEarly.getIsoDate() + "\" value=\"10001\" />\n" + "  <dataValue dataElement=\"DE_B\" period=\"" + okBefore.getIsoDate() + "\" value=\"10002\" />\n" + "  <dataValue dataElement=\"DE_C\" period=\"" + okAfter.getIsoDate() + "\" value=\"10003\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"" + tooLate.getIsoDate() + "\" value=\"10004\" />\n" + "  <dataValue dataElement=\"DE_D\" period=\"" + outOfRange.getIsoDate() + "\" value=\"10005\" />\n" + "</dataValueSet>\n";
    in = new ByteArrayInputStream(importData.getBytes(StandardCharsets.UTF_8));
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(3, summary.getConflictCount(), summary.getConflictsDescription());
    assertEquals(2, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(3, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(2, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deB, okBefore, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, okAfter, ouA, ocDef, ocDef)));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Period(org.hisp.dhis.period.Period) Date(java.util.Date) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)58 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)33 DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)32 DataValue (org.hisp.dhis.datavalue.DataValue)31 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)29 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 DataElement (org.hisp.dhis.dataelement.DataElement)26 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)26 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)21 Event (org.hisp.dhis.dxf2.events.event.Event)20 ClassPathResource (org.springframework.core.io.ClassPathResource)20 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)16 Period (org.hisp.dhis.period.Period)16 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)11 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)11 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)8 User (org.hisp.dhis.user.User)8