Search in sources :

Example 46 with JsonObject

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

the class GistTransformControllerTest method testTransform_Pluck_NoArgument.

@Test
void testTransform_Pluck_NoArgument() {
    JsonObject gist = GET("/users/{uid}/userGroups/gist?fields=name,users::pluck", getSuperuserUid()).content();
    assertHasPager(gist, 1, 50);
    assertEquals(getSuperuserUid(), gist.getArray("userGroups").getObject(0).getArray("users").getString(0).string());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 47 with JsonObject

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

the class GistTransformControllerTest method testTransform_NotMember.

@Test
void testTransform_NotMember() {
    String url = "/users/{uid}/userGroups/gist?fields=name,users::not-member({uid})";
    // not-member(id) with a user that is a member
    JsonObject gist = GET(url, getSuperuserUid(), getSuperuserUid()).content();
    assertFalse(gist.getArray("userGroups").getObject(0).getBoolean("users").booleanValue());
    // not-member(id) with a user that is not a member
    gist = GET(url, getSuperuserUid(), "non-existing-user-uid").content();
    assertTrue(gist.getArray("userGroups").getObject(0).getBoolean("users").booleanValue());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 48 with JsonObject

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

the class GistTransformControllerTest method testTransform_Member.

@Test
void testTransform_Member() {
    String url = "/users/{uid}/userGroups/gist?fields=name,users::member({uid})";
    // member(id) with a user that is a member
    JsonObject gist = GET(url, getSuperuserUid(), getSuperuserUid()).content();
    assertTrue(gist.getArray("userGroups").getObject(0).getBoolean("users").booleanValue());
    // member(id) with a user that is not a member
    gist = GET(url, getSuperuserUid(), "non-existing-user-uid").content();
    assertFalse(gist.getArray("userGroups").getObject(0).getBoolean("users").booleanValue());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 49 with JsonObject

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

the class GistTransformControllerTest method testTransform_Pluck.

@Test
void testTransform_Pluck() {
    JsonObject gist = GET("/users/{uid}/userGroups/gist?fields=name,users::pluck(surname)", getSuperuserUid()).content();
    assertHasPager(gist, 1, 50);
    assertEquals("admin", gist.getArray("userGroups").getObject(0).getArray("users").getString(0).string());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 50 with JsonObject

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

the class InterpretationControllerTest method testDeleteComment.

@Test
void testDeleteComment() {
    String cuid = assertStatus(HttpStatus.CREATED, POST("/interpretations/" + uid + "/comments", "text/plain:comment"));
    assertStatus(HttpStatus.NO_CONTENT, DELETE("/interpretations/" + uid + "/comments/" + cuid));
    JsonObject comments = GET("/interpretations/{uid}/comments", uid).content(HttpStatus.OK);
    assertEquals(0, comments.getArray("comments").size());
}
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