use of org.hisp.dhis.dxf2.events.importer.context.WorkContext 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.context.WorkContext 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");
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext 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.context.WorkContext 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.context.WorkContext in project dhis2-core by dhis2.
the class EventStatusPreProcessorTest method testVisitedStatusIsConvertedToActive.
@Test
void testVisitedStatusIsConvertedToActive() {
WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).build();
Event event = new Event();
event.setStatus(EventStatus.VISITED);
event.setDataValues(Sets.newHashSet(new DataValue("aaa", "one"), new DataValue("bbb", "two")));
preProcessor.process(event, ctx);
assertThat(event.getStatus(), is(EventStatus.ACTIVE));
}
Aggregations