Search in sources :

Example 46 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class TeiValidationTests method shouldReturnErrorWhenRemovingMandatoryAttributes.

@Test
public void shouldReturnErrorWhenRemovingMandatoryAttributes() {
    JsonObject object = buildTeiWithEnrollmentAndMandatoryAttributes().array();
    TrackerApiResponse response = trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("async=false"));
    String teiId = response.validateSuccessfulImport().extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    JsonObjectBuilder.jsonObject(object).addPropertyByJsonPath("trackedEntities[0].trackedEntity", teiId).addPropertyByJsonPath("trackedEntities[0].attributes[0].value", null).addPropertyByJsonPath("trackedEntities[0].enrollments[0].enrollment", enrollmentId).addPropertyByJsonPath("trackedEntities[0].enrollments[0].attributes[0].value", null);
    trackerActions.postAndGetJobReport(object, new QueryParamsBuilder().add("async=false")).validateErrorReport().body("", hasSize(2)).body("trackerType", hasItems("TRACKED_ENTITY", "ENROLLMENT")).body("errorCode", hasItems("E1076", "E1076")).body("message", hasItem(allOf(containsStringIgnoringCase("TrackedEntityAttribute"), containsStringIgnoringCase(mandatoryTetAttribute)))).body("message", hasItem(allOf(containsStringIgnoringCase("TrackedEntityAttribute"), containsStringIgnoringCase(mandatoryProgramAttribute))));
}
Also used : QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 47 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class TeiValidationTests method shouldReturnErrorWhenMandatoryProgramAttributeMissing.

@Test
public void shouldReturnErrorWhenMandatoryProgramAttributeMissing() {
    // arrange
    JsonObject trackedEntities = new TeiDataBuilder().buildWithEnrollment(trackedEntityType, Constants.ORG_UNIT_IDS[0], program);
    // assert
    TrackerApiResponse response = trackerActions.postAndGetJobReport(trackedEntities);
    response.validateErrorReport().body("trackerType", hasItem("ENROLLMENT")).body("errorCode", hasItem("E1018"));
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest)

Example 48 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class RelationshipsTests method shouldImportObjectsWithRelationship.

@ParameterizedTest
@ValueSource(strings = { "src/test/resources/tracker/importer/teis/teisAndRelationship.json", "src/test/resources/tracker/importer/teis/teisWithRelationship.json" })
public void shouldImportObjectsWithRelationship(String file) throws Exception {
    JsonObject jsonObject = new FileReaderUtils().read(new File(file)).get(JsonObject.class);
    TrackerApiResponse response = trackerActions.postAndGetJobReport(jsonObject).validateSuccessfulImport();
    response.validate().body("stats.total", equalTo(3));
    createdRelationships = response.extractImportedRelationships();
    ApiResponse relationshipResponse = trackerActions.get("/relationships/" + createdRelationships.get(0));
    relationshipResponse.validate().statusCode(200).body("from.trackedEntity", notNullValue()).body("to.trackedEntity", notNullValue());
    response.extractImportedTeis().forEach(tei -> {
        teiActions.get(tei, new QueryParamsBuilder().add("fields=relationships")).validate().statusCode(200).body("relationships.relationship", contains(createdRelationships.get(0)));
    });
}
Also used : FileReaderUtils(org.hisp.dhis.helpers.file.FileReaderUtils) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) File(java.io.File) ApiResponse(org.hisp.dhis.dto.ApiResponse) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse 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)

Example 50 with TrackerApiResponse

use of org.hisp.dhis.dto.TrackerApiResponse in project dhis2-core by dhis2.

the class ImportStrategyTests method shouldDeleteReferencingEventsWhenEnrollmentIsDeleted.

@Test
public void shouldDeleteReferencingEventsWhenEnrollmentIsDeleted() {
    // arrange
    JsonObject body = new TeiDataBuilder().buildWithEnrollmentAndEvent(Constants.TRACKED_ENTITY_TYPE, Constants.ORG_UNIT_IDS[0], Constants.TRACKER_PROGRAM_ID, "PaOOjwLVW23");
    TrackerApiResponse response = trackerActions.postAndGetJobReport(body).validateSuccessfulImport();
    String teiId = response.extractImportedTeis().get(0);
    String enrollmentId = response.extractImportedEnrollments().get(0);
    String eventId1 = response.extractImportedEvents().get(0);
    body = trackerActions.getEnrollment(enrollmentId).validateStatus(200).getBodyAsJsonBuilder().wrapIntoArray("enrollments");
    // act
    response = trackerActions.postAndGetJobReport(body, new QueryParamsBuilder().add("importStrategy=DELETE")).validateSuccessfulImport();
    // assert
    response.validateSuccessfulImport().validate().body("stats.deleted", Matchers.equalTo(1));
    trackerActions.getTrackedEntity(teiId + "?fields=*").validate().statusCode(200).body("enrollments", hasSize(0));
    trackerActions.get("/enrollments/" + enrollmentId).validate().statusCode(404);
    trackerActions.get("/events/" + eventId1).validate().statusCode(404);
}
Also used : TeiDataBuilder(org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder) QueryParamsBuilder(org.hisp.dhis.helpers.QueryParamsBuilder) JsonObject(com.google.gson.JsonObject) TrackerApiResponse(org.hisp.dhis.dto.TrackerApiResponse) Test(org.junit.jupiter.api.Test) TrackerNtiApiTest(org.hisp.dhis.tracker.TrackerNtiApiTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TrackerApiResponse (org.hisp.dhis.dto.TrackerApiResponse)53 JsonObject (com.google.gson.JsonObject)44 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 TrackerNtiApiTest (org.hisp.dhis.tracker.TrackerNtiApiTest)32 QueryParamsBuilder (org.hisp.dhis.helpers.QueryParamsBuilder)17 EventDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EventDataBuilder)15 File (java.io.File)14 FileReaderUtils (org.hisp.dhis.helpers.file.FileReaderUtils)11 ApiResponse (org.hisp.dhis.dto.ApiResponse)9 TeiDataBuilder (org.hisp.dhis.tracker.importer.databuilder.TeiDataBuilder)8 JsonObjectBuilder (org.hisp.dhis.helpers.JsonObjectBuilder)5 CsvSource (org.junit.jupiter.params.provider.CsvSource)5 ValueSource (org.junit.jupiter.params.provider.ValueSource)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 PotentialDuplicatesApiTest (org.hisp.dhis.tracker.deduplication.PotentialDuplicatesApiTest)3 EnrollmentDataBuilder (org.hisp.dhis.tracker.importer.databuilder.EnrollmentDataBuilder)3 IdGenerator (org.hisp.dhis.actions.IdGenerator)2 ProgramStageActions (org.hisp.dhis.actions.metadata.ProgramStageActions)2 JsonFileReader (org.hisp.dhis.helpers.file.JsonFileReader)1