Search in sources :

Example 41 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithNonExistingDataElementOrgUnit.

@Test
void testImportDataValuesWithNonExistingDataElementOrgUnit() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetG.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(3, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    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 42 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesInvalidAttributeOptionComboOrgUnit.

@Test
void testImportDataValuesInvalidAttributeOptionComboOrgUnit() throws Exception {
    clearSecurityContext();
    categoryOptionA.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    categoryService.updateCategoryOption(categoryOptionA);
    in = new ClassPathResource("datavalueset/dataValueSetH.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    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());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(2, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocA)));
    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 43 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesBooleanCsv.

@Test
void testImportDataValuesBooleanCsv() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetBooleanTest.csv").getInputStream();
    ImportConflicts summary = dataValueSetService.importDataValueSetCsv(in, null, null);
    String description = summary.getConflictsDescription();
    assertEquals(4, summary.getTotalConflictOccurrenceCount(), description);
    assertEquals(4, summary.getConflictOccurrenceCount(ErrorCode.E7619), description);
    assertEquals(2, summary.getConflictCount(), description);
    Iterator<ImportConflict> conflicts = summary.getConflicts().iterator();
    assertArrayEquals(new int[] { 10, 11 }, conflicts.next().getIndexes());
    assertArrayEquals(new int[] { 16, 17 }, conflicts.next().getIndexes());
    List<String> expectedBools = Lists.newArrayList("true", "false");
    List<DataValue> resultBools = mockDataValueBatchHandler.getInserts();
    for (DataValue dataValue : resultBools) {
        assertTrue(expectedBools.contains(dataValue.getValue()));
    }
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportConflicts(org.hisp.dhis.dxf2.importsummary.ImportConflicts) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 44 with DataValue

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

the class DataValueSetServiceTest method testImportDataValueSetXml.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testImportDataValueSetXml() throws Exception {
    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.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());
    assertEquals(0, auditValues.size());
    // TODO This throw an error : "org.postgresql.util.PSQLException: ERROR:
    // cannot execute UPDATE in a read-only transaction"
    // Need to investigate
    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());
}
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) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 45 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesXmlDryRun.

@Test
void testImportDataValuesXmlDryRun() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions().setDryRun(true).setIdScheme("UID").setDataElementIdScheme("UID").setOrgUnitIdScheme("UID");
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertHasNoConflicts(summary);
    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) 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)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