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));
}
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());
}
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);
}
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);
}
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");
}
Aggregations