use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class ProgramInstancePreProcessorTest method verifyEnrollmentIsNotSetOnEventWhenMultipleProgramInstanceAreFound.
@Test
void verifyEnrollmentIsNotSetOnEventWhenMultipleProgramInstanceAreFound() {
//
// 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(programInstanceStore.get(tei, program, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
event.setProgram(program.getUid());
subject.process(event, workContext);
assertThat(event.getEnrollment(), is(nullValue()));
assertThat(programInstanceMap.get(event.getUid()), is(nullValue()));
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class ProgramOrgUnitCheckTest method verifySuccessWhenProgramHasOrgUnitMatchingEventOrgUnit.
private void verifySuccessWhenProgramHasOrgUnitMatchingEventOrgUnit(String orgUnitId, IdScheme scheme) {
// assign a UID to the event's org unit
event.setOrgUnit(orgUnitId);
// Prepare data
Program program = createProgram('P');
program.setId(1);
OrganisationUnit ou = new OrganisationUnit();
ou.setId(1);
ou.setUid(orgUnitId);
when(workContext.getOrganisationUnitMap()).thenReturn(ImmutableMap.of(event.getUid(), ou));
when(workContext.getProgramWithOrgUnitsMap()).thenReturn(ImmutableMap.of(1L, ImmutableList.of(1L)));
ProgramInstance pi = new ProgramInstance();
pi.setProgram(program);
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
programInstanceMap.put(event.getUid(), pi);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
importOptions.setOrgUnitIdScheme(scheme.name());
when(workContext.getImportOptions()).thenReturn(importOptions);
// method under test
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertNoError(summary);
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class EventStoredByPreProcessorTest method t1.
@Test
void t1() {
WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).build();
Event event = new Event();
event.setDataValues(Sets.newHashSet(new DataValue("aaa", "one"), new DataValue("bbb", "two")));
preProcessor.process(event, ctx);
assertThat(event.getStoredBy(), is(FALLBACK_USERNAME));
assertThat(event.getDataValues(), hasItems(allOf(Matchers.hasProperty("storedBy", is(FALLBACK_USERNAME)))));
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class ImportOptionsPreProcessorTest method verifyExceptionIsThrownOnMissingImportOptions.
@Test
void verifyExceptionIsThrownOnMissingImportOptions() {
WorkContext wc = WorkContext.builder().build();
assertThrows(UnrecoverableImportException.class, () -> subject.process(new Event(), wc));
}
use of org.hisp.dhis.dxf2.events.importer.context.WorkContext in project dhis2-core by dhis2.
the class EventGeometryCheckTest method failOnEventWithGeometryAndProgramStageWithNoGeometry.
@Test
void failOnEventWithGeometryAndProgramStageWithNoGeometry() {
event.setGeometry(createRandomPoint());
ProgramStage programStage = createProgramStage();
programStage.setFeatureType(FeatureType.NONE);
when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
assertHasError(importSummary, event, "Geometry (Point) does not conform to the feature type (None) specified for the program stage: " + programStage.getUid());
}
Aggregations