Search in sources :

Example 81 with DataValue

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

the class DataValueCheckTest method verifyValidationFailOnMissingDataElement.

@Test
void verifyValidationFailOnMissingDataElement() {
    event.setProgramStage("prgstg1");
    DataElement de1 = addToDataElementMap(createDataElement('A'));
    programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true)));
    addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"), createEventDataValue("iDontExist", "2"));
    DataValue dv1 = createDataValue(de1.getUid(), "1");
    DataValue dv2 = createDataValue("iDontExist", "2");
    event.setDataValues(Sets.newHashSet(dv1, dv2));
    final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
    assertHasError(summary, event, null);
    assertHasConflict(summary, "iDontExist is not a valid data element", "dataElement");
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventTestUtils.createEventDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue) EventTestUtils.createDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Example 82 with DataValue

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

the class DataValueCheckTest method verifyNoMandatoryCheckHasNoErrors.

@Test
void verifyNoMandatoryCheckHasNoErrors() {
    programStageA.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
    event.setProgramStage("prgstg1");
    DataElement de1 = addToDataElementMap(createDataElement('A'));
    DataElement de2 = addToDataElementMap(createDataElement('B'));
    DataValue dv1 = createDataValue(de1.getUid(), "1");
    DataValue dv2 = createDataValue(de2.getUid(), "2");
    event.setDataValues(Sets.newHashSet(dv1, dv2));
    assertNoError(rule.check(new ImmutableEvent(event), this.workContext));
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventTestUtils.createEventDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue) EventTestUtils.createDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Example 83 with DataValue

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

the class DataValueCheckTest method verifyMandatoryCheckFailsOnMandatoryDataElement.

@Test
void verifyMandatoryCheckFailsOnMandatoryDataElement() {
    event.setProgramStage("prgstg1");
    DataElement de1 = addToDataElementMap(createDataElement('A'));
    DataElement de2 = addToDataElementMap(createDataElement('B'));
    DataElement de3 = addToDataElementMap(createDataElement('C'));
    programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true), createProgramStageDataElement(programStageA, de2, 2, true), createProgramStageDataElement(programStageA, de3, 3, true)));
    addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"), createEventDataValue(de2.getUid(), "2"));
    DataValue dv1 = createDataValue(de1.getUid(), "1");
    DataValue dv2 = createDataValue(de2.getUid(), "2");
    event.setDataValues(Sets.newHashSet(dv1, dv2));
    final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
    assertHasError(summary, event, null);
    assertHasConflict(summary, "value_required_but_not_provided", de3.getUid());
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventTestUtils.createEventDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue) EventTestUtils.createDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Example 84 with DataValue

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

the class DataValueCheckTest method verifyMandatoryCheckSucceeds.

@Test
void verifyMandatoryCheckSucceeds() {
    event.setProgramStage("prgstg1");
    DataElement de1 = addToDataElementMap(createDataElement('A'));
    DataElement de2 = addToDataElementMap(createDataElement('B'));
    programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true), createProgramStageDataElement(programStageA, de2, 2, true)));
    addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"), createEventDataValue(de2.getUid(), "2"));
    DataValue dv1 = createDataValue(de1.getUid(), "1");
    DataValue dv2 = createDataValue(de2.getUid(), "2");
    event.setDataValues(Sets.newHashSet(dv1, dv2));
    final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
    assertNoError(summary);
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventTestUtils.createEventDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue) EventTestUtils.createDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Example 85 with DataValue

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

the class ProgramStageValidationStrategyTest method createDefaultEvent.

private Event createDefaultEvent(String uid, DataValue... dataValues) {
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
    event.getDataValues().addAll(Arrays.asList(dataValues));
    event.setUid(uid);
    event.setEvent(uid);
    return event;
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event)

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