Search in sources :

Example 16 with WorkContext

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()));
}
Also used : HashMap(java.util.HashMap) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) Pair(org.apache.commons.lang3.tuple.Pair) BasePreProcessTest(org.hisp.dhis.dxf2.events.importer.BasePreProcessTest) Test(org.junit.jupiter.api.Test)

Example 17 with WorkContext

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);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)

Example 18 with WorkContext

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)))));
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) Event(org.hisp.dhis.dxf2.events.event.Event) Test(org.junit.jupiter.api.Test)

Example 19 with WorkContext

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));
}
Also used : WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) Event(org.hisp.dhis.dxf2.events.event.Event) Test(org.junit.jupiter.api.Test)

Example 20 with WorkContext

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());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStage(org.hisp.dhis.program.ProgramStage) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)47 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)35 Test (org.junit.jupiter.api.Test)35 BaseValidationTest (org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)26 Program (org.hisp.dhis.program.Program)23 HashMap (java.util.HashMap)20 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)16 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)14 ProgramInstance (org.hisp.dhis.program.ProgramInstance)14 WorkContext (org.hisp.dhis.dxf2.events.importer.context.WorkContext)13 Event (org.hisp.dhis.dxf2.events.event.Event)12 ProgramStage (org.hisp.dhis.program.ProgramStage)11 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)9 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)9 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 Set (java.util.Set)7 DhisConvenienceTest.createTrackedEntityInstance (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance)7 IdScheme (org.hisp.dhis.common.IdScheme)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 User (org.hisp.dhis.user.User)5