Search in sources :

Example 21 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class EventBaseCheckTest method verifyErrorOnInvalidEventDate.

@Test
void verifyErrorOnInvalidEventDate() {
    event.setEvent(event.getUid());
    event.setEventDate("111-12-122");
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(importSummary, event, null);
    assertHasConflict(importSummary, event, "Invalid event date: " + event.getEventDate());
}
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 22 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class FilteredDataValueCheckTest method testNotLinkedDataElementsAreReported.

@Test
void testNotLinkedDataElementsAreReported() {
    Event event = new Event();
    event.setProgramStage(PROGRAMSTAGE);
    HashSet<DataValue> dataValues = Sets.newHashSet(new DataValue(DATA_ELEMENT_1, "whatever"), new DataValue(DATA_ELEMENT_2, "another value"));
    event.setDataValues(dataValues);
    WorkContext ctx = WorkContext.builder().importOptions(ImportOptions.getDefaultImportOptions()).programsMap(getProgramMap()).eventDataValueMap(new EventDataValueAggregator().aggregateDataValues(ImmutableList.of(event), Collections.emptyMap(), ImportOptions.getDefaultImportOptions())).build();
    ImportSummary importSummary = dataValueCheck.check(new ImmutableEvent(event), ctx);
    assertEquals(ImportStatus.WARNING, importSummary.getStatus());
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) EventDataValueAggregator(org.hisp.dhis.dxf2.events.importer.context.EventDataValueAggregator) Event(org.hisp.dhis.dxf2.events.event.Event) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) WorkContext(org.hisp.dhis.dxf2.events.importer.context.WorkContext) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test)

Example 23 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ProgramInstanceCheckTest method failOnMultipleProgramInstance.

@Test
void failOnMultipleProgramInstance() {
    // Data preparation
    Program programNoReg = createProgram('P');
    programNoReg.setProgramType(ProgramType.WITHOUT_REGISTRATION);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(programNoReg.getUid(), programNoReg);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // 
    // Program Instance
    // 
    when(workContext.getProgramInstanceMap()).thenReturn(new HashMap<>());
    // 
    // 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(this.programInstanceStore.get(programNoReg, ProgramStatus.ACTIVE)).thenReturn(Lists.newArrayList(programInstance1, programInstance2));
    event.setProgram(programNoReg.getUid());
    // 
    // Method under test
    // 
    ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(summary, event, "Multiple active program instances exists for program: " + programNoReg.getUid());
}
Also used : 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) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisConvenienceTest.createTrackedEntityInstance(org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance) Pair(org.apache.commons.lang3.tuple.Pair) 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 24 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ExpirationDaysCheckTest method failWhenEventHasNoDateAndProgramExpiryDaysBasedOnPeriod.

@Test
void failWhenEventHasNoDateAndProgramExpiryDaysBasedOnPeriod() {
    // Given
    final String monthlyPeriodType = new SimpleDateFormat("yyyyMM").format(new Date());
    // Prepare program
    Program program = createProgram('P');
    program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString(monthlyPeriodType));
    program.setExpiryDays(3);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // Prepare event
    event.setProgram(program.getUid());
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, "Event needs to have at least one (event or schedule) date");
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) 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 25 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.

the class ExpirationDaysCheckTest method failWhenEventHasDateBeforeCurrentDateAndProgramExpiryDaysBasedOnPeriod.

@Test
void failWhenEventHasDateBeforeCurrentDateAndProgramExpiryDaysBasedOnPeriod() {
    // Given
    final String monthlyPeriodType = new SimpleDateFormat("yyyyMM").format(new Date());
    // Prepare program
    Program program = createProgram('P');
    program.setExpiryPeriodType(PeriodType.getPeriodTypeFromIsoString(monthlyPeriodType));
    program.setExpiryDays(3);
    Map<String, Program> programMap = new HashMap<>();
    programMap.put(program.getUid(), program);
    when(workContext.getProgramsMap()).thenReturn(programMap);
    // Prepare event
    event.setProgram(program.getUid());
    event.setEventDate(new SimpleDateFormat("yyyy-MM-dd").format(getTodayMinusDays(100)));
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, "The event's date belongs to an expired period. It is not possible to create such event");
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) HashMap(java.util.HashMap) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)49 ImmutableEvent (org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent)38 Test (org.junit.jupiter.api.Test)35 BaseValidationTest (org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)34 Program (org.hisp.dhis.program.Program)18 HashMap (java.util.HashMap)17 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)13 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)11 ProgramInstance (org.hisp.dhis.program.ProgramInstance)10 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)9 ProgramStage (org.hisp.dhis.program.ProgramStage)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)5 DhisConvenienceTest.createProgramStageDataElement (org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement)5 DhisConvenienceTest.createTrackedEntityInstance (org.hisp.dhis.DhisConvenienceTest.createTrackedEntityInstance)5 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)5 EventTestUtils.createDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue)5 EventTestUtils.createEventDataValue (org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue)5