Search in sources :

Example 36 with DataValue

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

the class DataValueSetServiceTest method testImportDataValueSetXmlPreheatCache.

@Test
void testImportDataValueSetXmlPreheatCache() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setPreheatCache(true);
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertHasNoConflicts(summary);
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertEquals("10002", ((List<DataValue>) dataValues).get(1).getValue());
    assertEquals("10003", ((List<DataValue>) dataValues).get(2).getValue());
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
    assertNotNull(registration);
    assertEquals(dsA, registration.getDataSet());
    assertEquals(peA, registration.getPeriod());
    assertEquals(ouA, registration.getSource());
    assertEquals(getDate(2012, 1, 9), registration.getDate());
    assertEquals(0, auditValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) List(java.util.List) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 37 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithCategoryOptionComboIdScheme.

@Test
void testImportDataValuesWithCategoryOptionComboIdScheme() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetCCode.xml").getInputStream();
    ImportOptions options = new ImportOptions().setCategoryOptionComboIdScheme("CODE");
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in, options);
    assertHasNoConflicts(summary);
    assertEquals(3, summary.getImportCount().getImported());
    assertEquals(0, summary.getImportCount().getUpdated());
    assertEquals(0, summary.getImportCount().getDeleted());
    assertEquals(0, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
}
Also used : 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 38 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesUpdatedAudit.

@Test
void testImportDataValuesUpdatedAudit() throws Exception {
    // as existing we return the imported DataValue with changed value
    // to prevent the update from being skipped
    mockDataValueBatchHandler.withFindObject(dataValue -> dataValue.toBuilder().value(dataValue.getValue() + "42").build());
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertHasNoConflicts(summary);
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getUpdates();
    Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertEquals("10002", ((List<DataValue>) dataValues).get(1).getValue());
    assertEquals("10003", ((List<DataValue>) dataValues).get(2).getValue());
    assertEquals(3, auditValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 39 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesUpdatedSkipNoChange.

@Test
void testImportDataValuesUpdatedSkipNoChange() throws Exception {
    mockDataValueBatchHandler.withFindSelf(true);
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertHasNoConflicts(summary);
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getUpdates();
    Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, summary.getImportCount().getUpdated());
    assertEquals(0, dataValues.size(), "Updates to unchanged data values were not skipped");
    assertEquals(0, auditValues.size(), "Updates to unchanged data value did not skip audit");
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 40 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesXmlWithCodeA.

@Test
void testImportDataValuesXmlWithCodeA() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetACode.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertNotNull(summary);
    assertNotNull(summary.getImportCount());
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertHasNoConflicts(summary);
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    Collection<DataValueAudit> auditValues = mockDataValueAuditBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocDef)));
    assertTrue(dataValues.contains(new DataValue(deC, peA, ouA, ocDef, ocDef)));
    CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(dsA, peA, ouA, ocDef);
    assertNotNull(registration);
    assertEquals(dsA, registration.getDataSet());
    assertEquals(peA, registration.getPeriod());
    assertEquals(ouA, registration.getSource());
    assertEquals(getDate(2012, 1, 9), registration.getDate());
    assertEquals(0, auditValues.size());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) ClassPathResource(org.springframework.core.io.ClassPathResource) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) 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