Search in sources :

Example 91 with JsonObject

use of org.hisp.dhis.jsontree.JsonObject in project dhis2-core by dhis2.

the class TrackerRelationshipsExportControllerTest method getRelationshipsByTrackedEntity.

@Test
void getRelationshipsByTrackedEntity() {
    TrackedEntityInstance tei = trackedEntityInstance();
    ProgramInstance programInstance = programInstance(tei);
    RelationshipType rType = relationshipType(RelationshipEntity.PROGRAM_INSTANCE, RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    Relationship r = relationship(rType, programInstance, tei);
    JsonObject relationship = GET("/tracker/relationships?trackedEntity=" + tei.getUid()).content(HttpStatus.OK);
    JsonObject jsonRelationship = assertFirstRelationship(relationship, r);
    assertEnrollment(jsonRelationship.getObject("from"), programInstance);
    assertTrackedEntity(jsonRelationship.getObject("to"), tei);
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) Relationship(org.hisp.dhis.relationship.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) JsonObject(org.hisp.dhis.jsontree.JsonObject) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 92 with JsonObject

use of org.hisp.dhis.jsontree.JsonObject in project dhis2-core by dhis2.

the class TrackerRelationshipsExportControllerTest method getRelationshipsById.

@Test
void getRelationshipsById() {
    TrackedEntityInstance tei = trackedEntityInstance();
    ProgramInstance programInstance = programInstance(tei);
    ProgramStageInstance programStageInstance = programStageInstance(programInstance);
    RelationshipType rType = relationshipType(RelationshipEntity.PROGRAM_STAGE_INSTANCE, RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    Relationship r = relationship(rType, programStageInstance, tei);
    JsonObject relationship = GET("/tracker/relationships/" + r.getUid()).content(HttpStatus.OK);
    assertRelationship(relationship, r);
    assertEvent(relationship.getObject("from"), programStageInstance);
    assertTrackedEntity(relationship.getObject("to"), tei);
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) Relationship(org.hisp.dhis.relationship.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) JsonObject(org.hisp.dhis.jsontree.JsonObject) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 93 with JsonObject

use of org.hisp.dhis.jsontree.JsonObject in project dhis2-core by dhis2.

the class TrackerRelationshipsExportControllerTest method assertNthRelationship.

private JsonObject assertNthRelationship(JsonObject body, Relationship r, int n) {
    assertFalse(body.isEmpty());
    JsonArray rels = body.getArray("instances");
    assertFalse(rels.isEmpty());
    assertTrue(rels.size() >= n);
    JsonObject jsonRelationship = rels.get(n).as(JsonObject.class);
    assertRelationship(jsonRelationship, r);
    return jsonRelationship;
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject)

Example 94 with JsonObject

use of org.hisp.dhis.jsontree.JsonObject in project dhis2-core by dhis2.

the class TrackerRelationshipsExportControllerTest method getRelationshipsByTei.

@Test
void getRelationshipsByTei() {
    TrackedEntityInstance tei = trackedEntityInstance();
    ProgramInstance programInstance = programInstance(tei);
    RelationshipType rType = relationshipType(RelationshipEntity.PROGRAM_INSTANCE, RelationshipEntity.TRACKED_ENTITY_INSTANCE);
    Relationship r = relationship(rType, programInstance, tei);
    JsonObject relationship = GET("/tracker/relationships?tei=" + tei.getUid()).content(HttpStatus.OK);
    JsonObject jsonRelationship = assertFirstRelationship(relationship, r);
    assertEnrollment(jsonRelationship.getObject("from"), programInstance);
    assertTrackedEntity(jsonRelationship.getObject("to"), tei);
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) Relationship(org.hisp.dhis.relationship.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType) JsonObject(org.hisp.dhis.jsontree.JsonObject) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 95 with JsonObject

use of org.hisp.dhis.jsontree.JsonObject in project dhis2-core by dhis2.

the class UserControllerTest method testPutJsonObject.

@Test
void testPutJsonObject() {
    JsonObject user = GET("/users/{id}", peter.getUid()).content();
    assertWebMessage("OK", 200, "OK", null, PUT("/38/users/" + peter.getUid(), user.toString()).content(HttpStatus.OK));
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonObject (org.hisp.dhis.jsontree.JsonObject)106 Test (org.junit.jupiter.api.Test)92 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)51 JsonArray (org.hisp.dhis.jsontree.JsonArray)16 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)6 Relationship (org.hisp.dhis.relationship.Relationship)5 RelationshipType (org.hisp.dhis.relationship.RelationshipType)5 GeoJsonObject (org.geojson.GeoJsonObject)3 JsonString (org.hisp.dhis.jsontree.JsonString)3 HttpStatus (org.springframework.http.HttpStatus)3 ObjectType (org.hisp.dhis.attribute.Attribute.ObjectType)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 Arrays.stream (java.util.Arrays.stream)1 Date (java.util.Date)1 JsonResponse (org.hisp.dhis.jsontree.JsonResponse)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 Program (org.hisp.dhis.program.Program)1 ApiToken (org.hisp.dhis.security.apikey.ApiToken)1 SettingKey (org.hisp.dhis.setting.SettingKey)1