Search in sources :

Example 1 with RelationshipDataBuilder

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));
}
Also used : JsonObject(com.google.gson.JsonObject) RelationshipDataBuilder(org.hisp.dhis.tracker.importer.databuilder.RelationshipDataBuilder) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with RelationshipDataBuilder

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));
}
Also used : JsonObject(com.google.gson.JsonObject) RelationshipDataBuilder(org.hisp.dhis.tracker.importer.databuilder.RelationshipDataBuilder) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

JsonObject (com.google.gson.JsonObject)2 ApiResponse (org.hisp.dhis.dto.ApiResponse)2 TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)2 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)2 RelationshipDataBuilder (org.hisp.dhis.tracker.importer.databuilder.RelationshipDataBuilder)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2