Search in sources :

Example 81 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method successValidationWhenDataElementIsNullAndDataElementIsNotCompulsory.

@Test
void successValidationWhenDataElementIsNullAndDataElementIsNotCompulsory() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, false);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setValue(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.COMPLETED).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 82 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method successValidationWhenFileResourceValueIsNullAndDataElementIsNotCompulsory.

@Test
void successValidationWhenFileResourceValueIsNullAndDataElementIsNotCompulsory() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement(ValueType.FILE_RESOURCE);
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, false);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setValue(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.COMPLETED).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 83 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class AssignedUserValidationHookTest method testEventWithNullEnabledUserAssignment.

@Test
void testEventWithNullEnabledUserAssignment() {
    // given
    Event event = new Event();
    event.setEvent(CodeGenerator.generateUid());
    event.setAssignedUser(USER_ID);
    event.setProgramStage(PROGRAM_STAGE);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    // when
    ProgramStage programStage = new ProgramStage();
    programStage.setEnableUserAssignment(null);
    when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
    this.hookToTest.validateEvent(reporter, event);
    // then
    assertFalse(reporter.hasErrors());
    assertTrue(reporter.hasWarnings());
    assertTrue(reporter.hasWarningReport(r -> E1120.equals(r.getWarningCode()) && TrackerType.EVENT.equals(r.getTrackerType()) && event.getUid().equals(r.getUid())));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Mock(org.mockito.Mock) AssertValidationErrorReporter.hasTrackerError(org.hisp.dhis.tracker.validation.hooks.AssertValidationErrorReporter.hasTrackerError) E1120(org.hisp.dhis.tracker.report.TrackerErrorCode.E1120) Mockito.when(org.mockito.Mockito.when) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) TrackerIdentifier(org.hisp.dhis.tracker.TrackerIdentifier) ProgramStage(org.hisp.dhis.program.ProgramStage) E1118(org.hisp.dhis.tracker.report.TrackerErrorCode.E1118) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) User(org.hisp.dhis.user.User) CodeGenerator(org.hisp.dhis.common.CodeGenerator) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 84 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class DataValueFilteringTestSupport method getProgramStages.

public static Set<ProgramStage> getProgramStages() {
    ProgramStage programStage = new ProgramStage();
    programStage.setProgramStageDataElements(getProgramStageDataElements(DATA_ELEMENT_1, DATA_ELEMENT_3));
    programStage.setUid(PROGRAMSTAGE);
    return Sets.newHashSet(programStage);
}
Also used : ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 85 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class DataValueCheckTest method verifyValidationFailOnJsonSerializationError.

@Test
void verifyValidationFailOnJsonSerializationError() throws JsonProcessingException {
    ObjectMapper localObjectMapper = mock(ObjectMapper.class);
    when(serviceDelegator.getJsonMapper()).thenReturn(localObjectMapper);
    when(localObjectMapper.writeValueAsString(Mockito.any())).thenThrow(new JsonProcessingException("Error") {
    });
    event.setProgramStage("prgstg1");
    DataElement de1 = addToDataElementMap(createDataElement('A'));
    final Program programA = createProgram('A');
    final ProgramStage programStageA = createProgramStage('A', programA);
    programStageA.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    programStageA.setProgramStageDataElements(Sets.newHashSet(createProgramStageDataElement(programStageA, de1, 1, true)));
    when(workContext.getProgramStage(IdScheme.UID, "prgstg1")).thenReturn(programStageA);
    addToDataValueMap(event.getUid(), createEventDataValue(de1.getUid(), "1"));
    DataValue dv1 = createDataValue(de1.getUid(), "1");
    event.setDataValues(Sets.newHashSet(dv1));
    final ImportSummary summary = rule.check(new ImmutableEvent(event), this.workContext);
    assertHasError(summary, event, null);
    assertHasConflict(summary, "Invalid data value found.", de1.getUid());
}
Also used : DhisConvenienceTest.createProgramStageDataElement(org.hisp.dhis.DhisConvenienceTest.createProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) EventTestUtils.createEventDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createEventDataValue) EventTestUtils.createDataValue(org.hisp.dhis.dxf2.events.importer.EventTestUtils.createDataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage) ProgramStage(org.hisp.dhis.program.ProgramStage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)209 Test (org.junit.jupiter.api.Test)86 Program (org.hisp.dhis.program.Program)82 DataElement (org.hisp.dhis.dataelement.DataElement)67 Event (org.hisp.dhis.tracker.domain.Event)47 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)40 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)39 ProgramInstance (org.hisp.dhis.program.ProgramInstance)38 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)26 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)22 DataValue (org.hisp.dhis.tracker.domain.DataValue)22 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 User (org.hisp.dhis.user.User)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)17 ArrayList (java.util.ArrayList)16 Date (java.util.Date)16 List (java.util.List)16 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)16 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)16