Search in sources :

Example 51 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method shouldFailValidationMissingTea.

@Test
void shouldFailValidationMissingTea() {
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Arrays.asList(Attribute.builder().attribute("aaaaa").build(), Attribute.builder().attribute("bbbbb").build())).trackedEntityType("tet").build();
    when(validationContext.getTrackedEntityType(anyString())).thenReturn(new TrackedEntityType());
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertTrue(reporter.hasErrors());
    assertEquals(2, reporter.getReportList().size());
    assertEquals(2, reporter.getReportList().stream().filter(e -> e.getErrorCode() == TrackerErrorCode.E1006).count());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 52 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method shouldPassValidationWhenValueIsNullAndAttributeIsNotMandatory.

@Test
void shouldPassValidationWhenValueIsNullAndAttributeIsNotMandatory() {
    TrackedEntityTypeAttribute trackedEntityTypeAttribute = new TrackedEntityTypeAttribute();
    TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
    trackedEntityAttribute.setUid("trackedEntityAttribute");
    trackedEntityAttribute.setValueType(ValueType.TEXT);
    trackedEntityTypeAttribute.setTrackedEntityAttribute(trackedEntityAttribute);
    TrackedEntityType trackedEntityType = new TrackedEntityType();
    trackedEntityType.setTrackedEntityTypeAttributes(Collections.singletonList(trackedEntityTypeAttribute));
    when(validationContext.getTrackedEntityAttribute("trackedEntityAttribute")).thenReturn(trackedEntityAttribute);
    when(validationContext.getTrackedEntityType(anyString())).thenReturn(trackedEntityType);
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute("trackedEntityAttribute").build())).trackedEntityType("trackedEntityType").build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertFalse(reporter.hasErrors());
    assertEquals(0, reporter.getReportList().size());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 53 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method shouldFailValidationMandatoryFields.

@Test
void shouldFailValidationMandatoryFields() {
    String tet = "tet";
    TrackedEntityType trackedEntityType = new TrackedEntityType();
    TrackedEntityTypeAttribute trackedEntityTypeAttribute = new TrackedEntityTypeAttribute();
    trackedEntityTypeAttribute.setMandatory(true);
    TrackedEntityAttribute trackedEntityAttribute = new TrackedEntityAttribute();
    trackedEntityAttribute.setUid("c");
    trackedEntityTypeAttribute.setTrackedEntityAttribute(trackedEntityAttribute);
    trackedEntityType.setTrackedEntityTypeAttributes(Collections.singletonList(trackedEntityTypeAttribute));
    when(validationContext.getTrackedEntityType(tet)).thenReturn(trackedEntityType);
    TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntityType(tet).attributes(Arrays.asList(Attribute.builder().attribute("a").value("value").build(), Attribute.builder().attribute("b").value("value").build())).build();
    TrackedEntityAttribute contextAttribute = new TrackedEntityAttribute();
    contextAttribute.setUid("uid");
    contextAttribute.setValueType(ValueType.TEXT);
    when(validationContext.getTrackedEntityAttribute(anyString())).thenReturn(contextAttribute);
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertTrue(reporter.hasErrors());
    assertEquals(1, reporter.getReportList().size());
    assertEquals(1, reporter.getReportList().stream().filter(e -> e.getErrorCode() == TrackerErrorCode.E1090).count());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityTypeAttribute(org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 54 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class PreCheckMetaValidationHookTest method verifyTrackedEntityValidationSuccess.

@Test
void verifyTrackedEntityValidationSuccess() {
    // given
    TrackedEntity tei = validTei();
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    // when
    when(ctx.getOrganisationUnit(ORG_UNIT_UID)).thenReturn(new OrganisationUnit());
    when(ctx.getTrackedEntityType(TRACKED_ENTITY_TYPE_UID)).thenReturn(new TrackedEntityType());
    validatorToTest.validateTrackedEntity(reporter, tei);
    // then
    assertFalse(reporter.hasErrors());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 55 with TrackedEntityType

use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.

the class TrackedEntityAttributeValidationHookTest method shouldPassValidationValueInOptionSet.

@Test
void shouldPassValidationValueInOptionSet() {
    TrackedEntityAttribute trackedEntityAttribute = getTrackedEntityAttributeWithOptionSet();
    when(validationContext.getTrackedEntityAttribute(anyString())).thenReturn(trackedEntityAttribute);
    when(validationContext.getTrackedEntityType(anyString())).thenReturn(new TrackedEntityType());
    TrackedEntity trackedEntity = TrackedEntity.builder().attributes(Collections.singletonList(Attribute.builder().attribute("trackedEntity").value("code").build())).trackedEntityType("trackedEntityType").build();
    ValidationErrorReporter reporter = new ValidationErrorReporter(validationContext);
    trackedEntityAttributeValidationHook.validateTrackedEntity(reporter, trackedEntity);
    assertFalse(reporter.hasErrors());
    assertEquals(0, reporter.getReportList().size());
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Aggregations

TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)57 Test (org.junit.jupiter.api.Test)27 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Program (org.hisp.dhis.program.Program)19 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)16 User (org.hisp.dhis.user.User)16 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)15 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)15 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)11 Date (java.util.Date)10 HashSet (java.util.HashSet)10 ProgramStage (org.hisp.dhis.program.ProgramStage)8 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)6 RelationshipType (org.hisp.dhis.relationship.RelationshipType)6 TrackedEntityTypeAttribute (org.hisp.dhis.trackedentity.TrackedEntityTypeAttribute)6 Collectors (java.util.stream.Collectors)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)5 CategoryOption (org.hisp.dhis.category.CategoryOption)5