Search in sources :

Example 46 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithAttributeOptionCombo.

@Test
void testImportDataValuesWithAttributeOptionCombo() throws Exception {
    in = new ClassPathResource("datavalueset/dataValueSetD.xml").getInputStream();
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in);
    assertEquals(ImportStatus.SUCCESS, summary.getStatus());
    assertHasNoConflicts(summary);
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(3, dataValues.size());
    assertTrue(dataValues.contains(new DataValue(deA, peA, ouA, ocDef, ocA)));
    assertTrue(dataValues.contains(new DataValue(deB, peA, ouA, ocDef, ocA)));
    assertTrue(dataValues.contains(new DataValue(deC, 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 47 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesWithNewPeriod.

@Test
void testImportDataValuesWithNewPeriod() throws Exception {
    ImportSummary summary = dataValueSetService.importDataValueSetXml(new ClassPathResource("datavalueset/dataValueSetC.xml").getInputStream());
    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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 48 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesUpdatedSkipAudit.

@Test
void testImportDataValuesUpdatedSkipAudit() throws Exception {
    // as existing we return the imported DataValue with changed comment
    // to prevent the update from being skipped
    mockDataValueBatchHandler.withFindObject(dataValue -> dataValue.toBuilder().comment(dataValue.getComment() + "42").build());
    in = new ClassPathResource("datavalueset/dataValueSetA.xml").getInputStream();
    ImportOptions importOptions = new ImportOptions();
    importOptions.setSkipAudit(true);
    ImportSummary summary = dataValueSetService.importDataValueSetXml(in, importOptions);
    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());
    assertEquals(0, auditValues.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) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 49 with DataValue

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

the class DataValueSetImportValidatorTest method testCheckDataValueStrictCategoryOptionCombos.

@Test
void testCheckDataValueStrictCategoryOptionCombos() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    valueContext.getDataElement().setCategoryCombo(new CategoryCombo());
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).strictCategoryOptionCombos(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7634, "Category option combo: `<object1>` must be part of category combo of data element: `<object2>`", context, dataValue.getCategoryOptionCombo(), dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Example 50 with DataValue

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

the class DataValueSetImportValidatorTest method testValidateDataValueDataElementExists.

/*
     * Data Value validation (should the entry be skipped)
     */
@Test
void testValidateDataValueDataElementExists() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = DataValueContext.builder().build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7610, "Data element not found or not accessible: `<object1>`", context, dataValue.getDataElement());
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) 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