Search in sources :

Example 36 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent 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 37 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent 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 38 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent 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 39 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class EventGeometryCheckTest method allowEventWithNoGeometry.

@Test
void allowEventWithNoGeometry() {
    ProgramStage programStage = createProgramStage();
    when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    assertNoError(importSummary);
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStage(org.hisp.dhis.program.ProgramStage) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 40 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ExpirationDaysCheckTest method failWhenProgramStageInstanceCompletedDateFallsAfterCurrentDay.

@Test
void failWhenProgramStageInstanceCompletedDateFallsAfterCurrentDay() {
    // Given
    // Prepare program
    Program program = createProgram('P');
    program.setCompleteEventsExpiryDays(3);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // Prepare program stage instance
    Map<String, ProgramStageInstance> psiMap = new HashMap<>();
    ProgramStageInstance psi = new ProgramStageInstance();
    psi.setStatus(EventStatus.COMPLETED);
    psi.setCompletedDate(getTodayMinusDays(5));
    psi.setUid(event.getUid());
    psiMap.put(event.getUid(), psi);
    when(workContext.getProgramStageInstanceMap()).thenReturn(psiMap);
    // Prepare event
    event.setProgram(program.getUid());
    event.setStatus(EventStatus.COMPLETED);
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, "The event's completeness date has expired. Not possible to make changes to this event");
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)49 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)38 Test (org.junit.jupiter.api.Test)35 BaseValidationTest (org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)34 Program (org.hisp.dhis.program.Program)18 HashMap (java.util.HashMap)17 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)13 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)11 ProgramInstance (org.hisp.dhis.program.ProgramInstance)10 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)9 ProgramStage (org.hisp.dhis.program.ProgramStage)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)5 DhisConvenienceTest.createProgramStageDataElement (org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement)5 DhisConvenienceTest.createTrackedEntityInstance (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance)5 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)5 EventTestUtils.createDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue)5 EventTestUtils.createEventDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue)5