Search in sources :

Example 86 with DataValue

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

the class EventStatusPreProcessorTest method testVisitedStatusIsConvertedToActive.

@Test
void testVisitedStatusIsConvertedToActive() {
    WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).build();
    Event event = new Event();
    event.setStatus(EventStatus.VISITED);
    event.setDataValues(Sets.newHashSet(new DataValue("aaa", "one"), new DataValue("bbb", "two")));
    preProcessor.process(event, ctx);
    assertThat(event.getStatus(), is(EventStatus.ACTIVE));
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) Event(org.hisp.dhis.dxf2.events.event.Event) Test(org.junit.jupiter.api.Test)

Example 87 with DataValue

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

the class DataValueSetImportValidatorTest method createRandomDataValue.

private static DataValue createRandomDataValue() {
    DataValue dv = new DataValue();
    dv.setDataElement(CodeGenerator.generateUid());
    dv.setPeriod("2021-01");
    dv.setOrgUnit(CodeGenerator.generateUid());
    dv.setCategoryOptionCombo(CodeGenerator.generateUid());
    dv.setAttributeOptionCombo(CodeGenerator.generateUid());
    dv.setComment("comment");
    dv.setValue("true");
    return dv;
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue)

Example 88 with DataValue

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

the class DataValueSetImportValidatorTest method testValidateDataValueCategoryOptionComboExists.

@Test
void testValidateDataValueCategoryOptionComboExists() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).categoryOptionCombo(null).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7613, "Category option combo not found or not accessible for writing data: `<object1>`", context, dataValue.getCategoryOptionCombo());
}
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 89 with DataValue

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

the class DataValueSetImportValidatorTest method testValidateDataValueAttrOptionComboExists.

@Test
void testValidateDataValueAttrOptionComboExists() {
    DataValue dataValue = createRandomDataValue();
    DataValueContext valueContext = createDataValueContext(dataValue).attrOptionCombo(null).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7615, "Attribute option combo not found or not accessible for writing data: `<object1>`", context, dataValue.getAttributeOptionCombo());
}
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 90 with DataValue

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

the class DataValueSetImportValidatorTest method createDataValueContext.

private DataValueContextBuilder createDataValueContext(DataValue dataValue) {
    DataValueContextBuilder builder = DataValueContext.builder();
    String deId = dataValue.getDataElement();
    String period = dataValue.getPeriod();
    String ouId = dataValue.getOrgUnit();
    String coId = dataValue.getCategoryOptionCombo();
    String aoId = dataValue.getAttributeOptionCombo();
    if (deId != null) {
        DataElement de = new DataElement();
        de.setUid(deId);
        de.setValueType(ValueType.BOOLEAN);
        builder.dataElement(de);
    }
    if (period != null) {
        Period p = PeriodType.getPeriodFromIsoString("2021-01");
        builder.period(p);
    }
    if (ouId != null) {
        OrganisationUnit ou = new OrganisationUnit();
        ou.setUid(ouId);
        builder.orgUnit(ou);
    }
    if (coId != null) {
        builder.categoryOptionCombo(createMinimalOptionCombo(coId));
    }
    if (aoId != null) {
        builder.attrOptionCombo(createMinimalOptionCombo(aoId));
    }
    return builder;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataValueContextBuilder(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext.DataValueContextBuilder) DataInputPeriod(org.hisp.dhis.dataset.DataInputPeriod) Period(org.hisp.dhis.period.Period) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

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