Search in sources :

Example 46 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent 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 47 with ImmutableEvent

use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent 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 48 with ImmutableEvent

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

the class EventBaseCheckTest method verifyErrorOnInvalidDueDate.

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

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

the class EventBaseCheckTest method verifyErrorOnInvalidCreatedAtClientDate.

@Test
void verifyErrorOnInvalidCreatedAtClientDate() {
    event.setEvent(event.getUid());
    event.setCreatedAtClient("111-12-122");
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(importSummary, event, null);
    assertHasConflict(importSummary, event, "Invalid event created at client date: " + event.getCreatedAtClient());
}
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 50 with ImmutableEvent

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

the class EventBaseCheckTest method verifyErrorOnEventWithDateNewerThanCompletedProgramInstance.

@Test
void verifyErrorOnEventWithDateNewerThanCompletedProgramInstance() {
    // Given
    ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
    importOptions.setUser(new User());
    event.setEvent(event.getUid());
    Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setStatus(ProgramStatus.COMPLETED);
    // Set program instance end date to NOW - one month
    programInstance.setEndDate(Date.from(ZonedDateTime.now().minusMonths(1).toInstant()));
    programInstanceMap.put(event.getUid(), programInstance);
    when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
    when(workContext.getImportOptions()).thenReturn(importOptions);
    // When
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    // Then
    assertHasError(importSummary, event, null);
}
Also used : User(org.hisp.dhis.user.User) 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) 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