use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class EventBaseCheckTest method verifyErrorOnInvalidEventDate.
@Test
void verifyErrorOnInvalidEventDate() {
event.setEvent(event.getUid());
event.setEventDate("111-12-122");
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(importSummary, event, null);
assertHasConflict(importSummary, event, "Invalid event date: " + event.getEventDate());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class FilteredDataValueCheckTest method testNotLinkedDataElementsAreReported.
@Test
void testNotLinkedDataElementsAreReported() {
Event event = new Event();
event.setProgramStage(PROGRAMSTAGE);
HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
event.setDataValues(dataValues);
WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
ImportSummary importSummary = dataValueCheck.check(new ImmutableEvent(event), ctx);
assertEquals(ImportStatus.WARNING, importSummary.getStatus());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramInstanceCheckTest method failOnMultipleProgramInstance.
@Test
void failOnMultipleProgramInstance() {
// Data preparation
Program programNoReg = createProgram('P');
programNoReg.setProgramType(ProgramType.WITHOUT_REGISTRATION);
Map<String, Program> programMap = new HashMap<>();
programMap.put(programNoReg.getUid(), programNoReg);
when(workContext.getProgramsMap()).thenReturn(programMap);
//
// Program Instance
//
when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
//
// Tracked Entity Instance
//
TrackedEntityInstance tei = createTrackedEntityInstance(createOrganisationUnit('A'));
Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
teiMap.put(event.getUid(), Pair.of(tei, true));
when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
ProgramInstance programInstance1 = new ProgramInstance();
ProgramInstance programInstance2 = new ProgramInstance();
when(this.programInstanceStore.get(programNoReg, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
event.setProgram(programNoReg.getUid());
//
// Method under test
//
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Multiple active program instances exists for program: " + programNoReg.getUid());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ExpirationDaysCheckTest method failWhenEventHasNoDateAndProgramExpiryDaysBasedOnPeriod.
@Test
void failWhenEventHasNoDateAndProgramExpiryDaysBasedOnPeriod() {
// Given
final String monthlyPeriodType = new SimpleDateFormat("yyyyMM").format(new Date());
// Prepare program
Program program = createProgram('P');
program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString(monthlyPeriodType));
program.setExpiryDays(3);
Map<String, Program> programMap = new HashMap<>();
programMap.put(program.getUid(), program);
when(workContext.getProgramsMap()).thenReturn(programMap);
// Prepare event
event.setProgram(program.getUid());
// When
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
// Then
assertHasError(importSummary, event, "Event needs to have at least one (event or schedule) date");
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ExpirationDaysCheckTest method failWhenEventHasDateBeforeCurrentDateAndProgramExpiryDaysBasedOnPeriod.
@Test
void failWhenEventHasDateBeforeCurrentDateAndProgramExpiryDaysBasedOnPeriod() {
// Given
final String monthlyPeriodType = new SimpleDateFormat("yyyyMM").format(new Date());
// Prepare program
Program program = createProgram('P');
program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString(monthlyPeriodType));
program.setExpiryDays(3);
Map<String, Program> programMap = new HashMap<>();
programMap.put(program.getUid(), program);
when(workContext.getProgramsMap()).thenReturn(programMap);
// Prepare event
event.setProgram(program.getUid());
event.setEventDate(new SimpleDateFormat("yyyy-MM-dd").format(getTodayMinusDays(100)));
// When
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
// Then
assertHasError(importSummary, event, "The event's date belongs to an expired period. It is not possible to create such event");
}
Aggregations