use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramStageInstanceBasicCheckTest method failOnProgramStageInstanceAndInvalidImportOption.
@Test
void failOnProgramStageInstanceAndInvalidImportOption() {
Map<String, ProgramStageInstance> programStageInstanceMap = new HashMap<>();
ProgramStageInstance psi = new ProgramStageInstance();
programStageInstanceMap.put(event.getEvent(), psi);
ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
importOptions.setImportStrategy(ImportStrategy.CREATE);
when(workContext.getImportOptions()).thenReturn(importOptions);
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 ProgramStageCheckTest method failOnNullProgramStage.
@Test
void failOnNullProgramStage() {
Program program = new Program();
program.setUid(CodeGenerator.generateUid());
program.setProgramType(ProgramType.WITH_REGISTRATION);
Map<String, Program> programMap = new HashMap<>();
programMap.put(program.getUid(), program);
event.setProgram(program.getUid());
when(workContext.getProgramsMap()).thenReturn(programMap);
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(summary, event, "Event.programStage does not point to a valid programStage: " + event.getProgramStage());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class EventBaseCheckTest method verifyErrorOnInvalidDueDate.
@Test
void verifyErrorOnInvalidDueDate() {
event.setEvent(event.getUid());
event.setDueDate("111-12-122");
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(importSummary, event, null);
assertHasConflict(importSummary, event, "Invalid event due date: " + event.getDueDate());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class EventBaseCheckTest method verifyErrorOnInvalidCreatedAtClientDate.
@Test
void verifyErrorOnInvalidCreatedAtClientDate() {
event.setEvent(event.getUid());
event.setCreatedAtClient("111-12-122");
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(importSummary, event, null);
assertHasConflict(importSummary, event, "Invalid event created at client date: " + event.getCreatedAtClient());
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class EventBaseCheckTest method verifyErrorOnEventWithDateNewerThanCompletedProgramInstance.
@Test
void verifyErrorOnEventWithDateNewerThanCompletedProgramInstance() {
// Given
ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
importOptions.setUser(new User());
event.setEvent(event.getUid());
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
ProgramInstance programInstance = new ProgramInstance();
programInstance.setStatus(ProgramStatus.COMPLETED);
// Set program instance end date to NOW - one month
programInstance.setEndDate(Date.from(ZonedDateTime.now().minusMonths(1).toInstant()));
programInstanceMap.put(event.getUid(), programInstance);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
when(workContext.getImportOptions()).thenReturn(importOptions);
// When
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
// Then
assertHasError(importSummary, event, null);
}
Aggregations