Search in sources :

Example 11 with DataValue

use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method failValidationWhenFileResourceValueIsNullAndDataElementIsCompulsory.

@Test
void failValidationWhenFileResourceValueIsNullAndDataElementIsCompulsory() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement(ValueType.FILE_RESOURCE);
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, true);
    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);
    assertThat(reporter.getReportList(), hasSize(1));
    assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
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 12 with DataValue

use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method failsOnCompletedEventWithDataElementValueNullAndValidationStrategyOnUpdate.

@Test
void failsOnCompletedEventWithDataElementValueNullAndValidationStrategyOnUpdate() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, true);
    programStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    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);
    assertThat(reporter.getReportList(), hasSize(1));
    assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
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 13 with DataValue

use of org.hisp.dhis.tracker.domain.DataValue 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 14 with DataValue

use of org.hisp.dhis.tracker.domain.DataValue 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 15 with DataValue

use of org.hisp.dhis.tracker.domain.DataValue in project dhis2-core by dhis2.

the class EventTrackerConverterServiceTest method fromForRuleEngineGivenNewEvent.

@Test
void fromForRuleEngineGivenNewEvent() {
    setUpMocks();
    DataElement dataElement = new DataElement();
    dataElement.setUid(CodeGenerator.generateUid());
    when(preheat.get(DataElement.class, dataElement.getUid())).thenReturn(dataElement);
    DataValue dataValue = dataValue(dataElement.getUid(), "900");
    Event event = event(dataValue);
    ProgramStageInstance programStageInstance = converter.fromForRuleEngine(preheat, event);
    assertNotNull(programStageInstance);
    assertNotNull(programStageInstance.getProgramStage());
    assertNotNull(programStageInstance.getProgramStage().getProgram());
    assertNotNull(programStageInstance.getOrganisationUnit());
    assertEquals(PROGRAM_UID, programStageInstance.getProgramStage().getProgram().getUid());
    assertEquals(PROGRAM_STAGE_UID, programStageInstance.getProgramStage().getUid());
    assertEquals(ORGANISATION_UNIT_UID, programStageInstance.getOrganisationUnit().getUid());
    assertEquals(ORGANISATION_UNIT_UID, programStageInstance.getOrganisationUnit().getUid());
    assertEquals(1, programStageInstance.getEventDataValues().size());
    EventDataValue actual = programStageInstance.getEventDataValues().stream().findFirst().get();
    assertEquals(dataValue.getDataElement(), actual.getDataElement());
    assertEquals(dataValue.getValue(), actual.getValue());
    assertTrue(actual.getProvidedElsewhere());
    assertEquals(USERNAME, actual.getCreatedByUserInfo().getUsername());
    assertEquals(USERNAME, actual.getLastUpdatedByUserInfo().getUsername());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) Event(org.hisp.dhis.tracker.domain.Event) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

DataValue (org.hisp.dhis.tracker.domain.DataValue)45 Event (org.hisp.dhis.tracker.domain.Event)35 DataElement (org.hisp.dhis.dataelement.DataElement)33 Test (org.junit.jupiter.api.Test)29 ProgramStage (org.hisp.dhis.program.ProgramStage)26 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)25 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)19 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)10 EventDataValue (org.hisp.dhis.eventdatavalue.EventDataValue)9 Lists (com.google.common.collect.Lists)6 Sets (com.google.common.collect.Sets)6 List (java.util.List)6 Map (java.util.Map)6 Optional (java.util.Optional)6 Set (java.util.Set)6 ValueType (org.hisp.dhis.common.ValueType)6 EventStatus (org.hisp.dhis.event.EventStatus)6 RuleActionAssign (org.hisp.dhis.rules.models.RuleActionAssign)6 SettingKey (org.hisp.dhis.setting.SettingKey)6 SystemSettingManager (org.hisp.dhis.setting.SystemSettingManager)6