Search in sources :

Example 66 with JsonObject

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

the class GistFieldsControllerTest method testField_DisplayName.

@Test
void testField_DisplayName() {
    JsonObject gist = GET("/users/{uid}/userGroups/gist?fields=displayName,id", getSuperuserUid()).content();
    JsonArray groups = gist.getArray("userGroups");
    assertEquals(1, groups.size());
    JsonObject group = groups.getObject(0);
    assertEquals(asList("displayName", "id"), group.names());
    assertEquals("groupX", group.getString("displayName").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 67 with JsonObject

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

the class GistFieldsControllerTest method testField_Remove_MinusSyntax.

@Test
void testField_Remove_MinusSyntax() {
    JsonObject user = GET("/users/{uid}/gist?fields=*,-surname", getSuperuserUid()).content();
    assertFalse(user.has("surname"));
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 68 with JsonObject

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

the class GistFieldsControllerTest method testField_Href.

/*
     * Synthetic Fields
     */
@Test
void testField_Href() {
    JsonArray users = GET("/users/gist?fields=id,href&headless=true", getSuperuserUid()).content();
    JsonObject user0 = users.getObject(0);
    assertTrue(user0.has("id", "href"));
    assertEquals("/users/" + user0.getString("id").string() + "/gist", user0.getString("href").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 69 with JsonObject

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

the class GistFieldsControllerTest method testField_Remove_BangSyntax.

@Test
void testField_Remove_BangSyntax() {
    JsonObject user = GET("/users/{uid}/gist?fields=*,!surname", getSuperuserUid()).content();
    assertFalse(user.has("surname"));
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 70 with JsonObject

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

the class GistPagerControllerTest method testPager_Total_CountQuery.

@Test
void testPager_Total_CountQuery() {
    // create some members we can count a total for
    createDataSetsForOrganisationUnit(10, orgUnitId, "extra");
    String url = "/organisationUnits/{id}/dataSets/gist?total=true&pageSize=3&order=name&filter=name:startsWith:extra";
    JsonObject gist = GET(url, orgUnitId).content();
    assertHasPager(gist, 1, 3, 10);
    // now page 2
    gist = GET(url + "&page=2", orgUnitId).content();
    assertHasPager(gist, 2, 3, 10);
    assertEquals("/organisationUnits/{id}/dataSets/gist?total=true&pageSize=3&order=name&filter=name:startsWith:extra&page=1".replace("{id}", orgUnitId), gist.getObject("pager").getString("prevPage").string());
    assertEquals("/organisationUnits/{id}/dataSets/gist?total=true&pageSize=3&order=name&filter=name:startsWith:extra&page=3".replace("{id}", orgUnitId), gist.getObject("pager").getString("nextPage").string());
    JsonArray dataSets = gist.getArray("dataSets");
    assertEquals("extra3", dataSets.getObject(0).getString("name").string());
    assertEquals("extra4", dataSets.getObject(1).getString("name").string());
    assertEquals("extra5", dataSets.getObject(2).getString("name").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) 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