Search in sources :

Example 56 with WorkContext

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

Example 57 with WorkContext

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

Example 58 with WorkContext

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.");
}
Also used : HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 59 with WorkContext

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

Example 60 with WorkContext

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));
}
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)

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