Search in sources :

Example 71 with DataValue

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

the class DataValueSetImportValidatorTest method testValidateDataValuePeriodExists.

@Test
void testValidateDataValuePeriodExists() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).period(null).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7611, "Period not valid: `<object1>`", context, dataValue.getPeriod());
}
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)

Example 72 with DataValue

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

the class DataValueSetServiceTest method testImportDataValuesInvalidAttributeOptionComboDates.

@Test
void testImportDataValuesInvalidAttributeOptionComboDates() throws Exception {
    clearSecurityContext();
    categoryOptionA.setStartDate(peB.getStartDate());
    categoryOptionA.setEndDate(peB.getEndDate());
    categoryService.updateCategoryOption(categoryOptionA);
    in = new ClassPathResource("datavalueset/dataValueSetH.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(2, summary.getImportCount().getIgnored());
    assertEquals(ImportStatus.WARNING, summary.getStatus());
    Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
    assertNotNull(dataValues);
    assertEquals(1, dataValues.size());
    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 73 with DataValue

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

the class EventDataValueAggregatorTest method createEvent.

private Event createEvent(DataValue... dataValues) {
    Event event = new Event();
    event.setUid(CodeGenerator.generateUid());
    event.setDataValues(Sets.newHashSet(dataValues));
    return event;
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event)

Example 74 with DataValue

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

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

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