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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations