use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckMandatoryFieldsValidationHookTest method verifyRelationshipValidationSuccess.
@Test
void verifyRelationshipValidationSuccess() {
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).relationshipType(CodeGenerator.generateUid()).from(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).to(RelationshipItem.builder().trackedEntity(CodeGenerator.generateUid()).build()).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class TrackerBundleParamsConverterTest method verifyNestedTeiStructureIsFlattenedDuringDeserialization.
@Test
void verifyNestedTeiStructureIsFlattenedDuringDeserialization() throws IOException {
List<Relationship> relationships1 = createRelationships(2, "rel1");
List<Relationship> relationships2 = createRelationships(2, "rel2");
List<Event> events1 = createEvent(3, "ev1", "enr1");
List<Event> events2 = createEvent(7, "ev2", "enr2");
List<Enrollment> enrollments = new ArrayList<>();
Enrollment enrollment1 = createEnrollment("enr1", "teiABC", events1);
Enrollment enrollment2 = createEnrollment("enr2", "teiABC", events2);
enrollment1.setRelationships(relationships2);
enrollment2.setRelationships(relationships1);
enrollments.add(enrollment1);
enrollments.add(enrollment2);
TrackedEntity trackedEntity = createTrackedEntity("teiABC", enrollments);
trackedEntity.setRelationships(relationships1);
TrackerBundleParams build = TrackerBundleParams.builder().trackedEntities(Collections.singletonList(trackedEntity)).build();
String jsonPayload = toJson(build);
TrackerBundleParams b2 = this.objectMapper.readValue(jsonPayload, TrackerBundleParams.class);
assertThat(b2.getTrackedEntities(), hasSize(1));
assertThat(b2.getEnrollments(), hasSize(2));
assertThat(b2.getEvents(), hasSize(10));
assertThat(b2.getRelationships(), hasSize(4));
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class TrackerBundleParamsConverterTest method createRelationships.
private List<Relationship> createRelationships(int size, String uid) {
List<Relationship> relationships = new ArrayList<>();
for (int i = 0; i < size; i++) {
Relationship relationship = rnd.nextObject(Relationship.class);
relationship.setRelationship(uid + i);
relationships.add(relationship);
}
return relationships;
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyRelationshipWithInvalidUidFails.
@Test
void verifyRelationshipWithInvalidUidFails() {
// given
Relationship relationship = Relationship.builder().relationship(INVALID_UID).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
// then
hasTrackerError(reporter, E1048, RELATIONSHIP, relationship.getUid());
}
use of org.hisp.dhis.tracker.domain.Relationship in project dhis2-core by dhis2.
the class PreCheckUidValidationHookTest method verifyRelationshipValidationSuccess.
@Test
void verifyRelationshipValidationSuccess() {
// given
Relationship relationship = Relationship.builder().relationship(CodeGenerator.generateUid()).build();
ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
validationHook.validateRelationship(reporter, relationship);
// then
assertFalse(reporter.hasErrors());
}
Aggregations