use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ExpirationDaysCheckTest method failWhenProgramStageInstanceHasNoExecDateAndProgramHasPeriodType.
@Test
void failWhenProgramStageInstanceHasNoExecDateAndProgramHasPeriodType() {
// Given
// Prepare program
Program program = createProgram('P');
program.setCompleteEventsExpiryDays(3);
program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString("202001"));
program.setExpiryDays(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.setCompletedDate(getTodayPlusDays(5));
psi.setUid(event.getUid());
psiMap.put(event.getUid(), psi);
when(workContext.getProgramStageInstanceMap()).thenReturn(psiMap);
// Prepare event
event.setProgram(program.getUid());
// When
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
// Then
assertHasError(importSummary, event, "Event needs to have event date");
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ExpirationDaysCheckTest method failWhenEventHasNoCompletedDateAndProgramHasExpiryDays.
@Test
void failWhenEventHasNoCompletedDateAndProgramHasExpiryDays() {
// 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 event
event.setProgram(program.getUid());
event.setStatus(EventStatus.COMPLETED);
// When
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
// Then
assertHasError(importSummary, event, "Event needs to have completed date");
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramInstanceCheckTest method failOnMultipleProgramInstanceByActiveProgramAndTei.
@Test
void failOnMultipleProgramInstanceByActiveProgramAndTei() {
// Data preparation
//
// Program Instance
//
when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
//
// Tracked Entity Instance
//
TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
when(workContext.getTrackedEntityInstance(event.getUid())).thenReturn(Optional.of(tei));
ProgramInstance programInstance1 = new ProgramInstance();
ProgramInstance programInstance2 = new ProgramInstance();
when(this.programInstanceStore.get(tei, program, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
event.setProgram(program.getUid());
//
// Method under test
//
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Tracked entity instance: " + tei.getUid() + " has multiple active enrollments in program: " + program.getUid());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramStageInstanceBasicCheckTest method failOnDeletedProgramStageInstance.
@Test
void failOnDeletedProgramStageInstance() {
Map<String, ProgramStageInstance> programStageInstanceMap = new HashMap<>();
ProgramStageInstance psi = new ProgramStageInstance();
psi.setDeleted(true);
programStageInstanceMap.put(event.getEvent(), psi);
when(workContext.getProgramStageInstanceMap()).thenReturn(programStageInstanceMap);
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Event ID " + event.getEvent() + " was already used and/or deleted. This event can not be modified.");
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramStageInstanceBasicCheckTest method failOnMissingProgramStageInstance.
@Test
void failOnMissingProgramStageInstance() {
when(workContext.getProgramStageInstanceMap()).thenReturn(new HashMap<>());
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Event ID " + event.getEvent() + " doesn't point to valid event");
}
Aggregations