use of org.hisp.dhis.tracker.importer.databuilder.RelationshipDataBuilder in project dhis2-core by dhis2.
the class RelationshipsTests method shouldNotDuplicateNonBidirectionalRelationship.
@Test
public void shouldNotDuplicateNonBidirectionalRelationship() throws Exception {
// Given 2 existing tracked entities and a unidirectional relationship
// between them
String trackedEntity_1 = importTei();
String trackedEntity_2 = importTei();
JsonObject jsonObject = new RelationshipDataBuilder().buildUniDirectionalRelationship(trackedEntity_1, trackedEntity_2).array();
trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImport().validateRelationships().body("stats.created", equalTo(1));
// when posting the same payload, then relationship is ignored when in
// the same way
trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImportWithIgnored(1).validateRelationships().body("stats.ignored", equalTo(1));
// and is imported again when the relation is in inverse order
jsonObject = new RelationshipDataBuilder().buildUniDirectionalRelationship(trackedEntity_2, trackedEntity_1).array();
trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImport().validateRelationships().body("stats.ignored", equalTo(0)).body("stats.created", equalTo(1));
// and there are 2 relationships for any of the tracked entities
ApiResponse relationshipResponse = trackerActions.get("/relationships?tei=" + trackedEntity_1);
relationshipResponse.validate().statusCode(200).body("instances.size()", is(2));
}
use of org.hisp.dhis.tracker.importer.databuilder.RelationshipDataBuilder in project dhis2-core by dhis2.
the class RelationshipsTests method shouldNotDuplicateBidirectionalRelationship.
@Test
public void shouldNotDuplicateBidirectionalRelationship() throws Exception {
// Given 2 existing tracked entities and a bidirectional relationship
// between them
String trackedEntity_1 = importTei();
String trackedEntity_2 = importTei();
JsonObject jsonObject = new RelationshipDataBuilder().buildBidirectionalRelationship(trackedEntity_1, trackedEntity_2).array();
JsonObject invertedRelationship = new RelationshipDataBuilder().buildBidirectionalRelationship(trackedEntity_2, trackedEntity_1).array();
TrackerApiResponse trackerApiResponse = trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImport();
trackerApiResponse.validateRelationships().body("stats.created", equalTo(1));
String createdRelationshipUid = trackerApiResponse.extractImportedRelationships().get(0);
// when posting the same payload, then relationship is ignored both ways
Stream.of(jsonObject, invertedRelationship).map(trackerActions::postAndGetJobReport).map(tar -> tar.validateSuccessfulImportWithIgnored(1)).map(TrackerApiResponse::validateRelationships).forEach(validatableResponse -> validatableResponse.body("stats.ignored", equalTo(1)));
// and relationship is not duplicated
ApiResponse relationshipResponse = trackerActions.get("/relationships?tei=" + trackedEntity_1);
relationshipResponse.validate().statusCode(200).body("instances[0].relationship", is(createdRelationshipUid)).body("instances.size()", is(1));
}
Aggregations