Search in sources :

Example 21 with JsonArray

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

the class DataApprovalControllerTest method testGetApprovalByCategoryOptionCombos.

@Test
void testGetApprovalByCategoryOptionCombos() {
    JsonArray statuses = GET("/dataApprovals/categoryOptionCombos?ou={ou}&pe=202101&wf={wf}", ouId, wfId).content(HttpStatus.OK);
    assertTrue(statuses.isArray());
    assertEquals(1, statuses.size());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 22 with JsonArray

use of org.hisp.dhis.jsontree.JsonArray 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 23 with JsonArray

use of org.hisp.dhis.jsontree.JsonArray 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 24 with JsonArray

use of org.hisp.dhis.jsontree.JsonArray 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)

Example 25 with JsonArray

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

the class GistFilterControllerTest method testFilter_GroupsOR.

@Test
void testFilter_GroupsOR() {
    createDataSetsForOrganisationUnit(5, orgUnitId, "alpha");
    createDataSetsForOrganisationUnit(5, orgUnitId, "beta");
    createDataSetsForOrganisationUnit(5, orgUnitId, "gamma");
    // both filters in group 2 are combined OR because root junction is
    // implicitly AND
    String url = "/dataSets/gist?filter=1:name:endsWith:3&filter=2:name:like:alpha&filter=2:name:like:beta&headless=true&order=name";
    JsonArray matches = GET(url).content();
    assertEquals(2, matches.size());
    assertEquals("alpha3", matches.getObject(0).getString("name").string());
    assertEquals("beta3", matches.getObject(1).getString("name").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) Test(org.junit.jupiter.api.Test)

Aggregations

JsonArray (org.hisp.dhis.jsontree.JsonArray)29 Test (org.junit.jupiter.api.Test)26 JsonObject (org.hisp.dhis.jsontree.JsonObject)16 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)16 JsonErrorReport (org.hisp.dhis.webapi.json.domain.JsonErrorReport)2 JsonWebMessage (org.hisp.dhis.webapi.json.domain.JsonWebMessage)2 JsonResponse (org.hisp.dhis.jsontree.JsonResponse)1 JsonString (org.hisp.dhis.jsontree.JsonString)1 User (org.hisp.dhis.user.User)1 JsonTranslation (org.hisp.dhis.webapi.json.domain.JsonTranslation)1 JsonUser (org.hisp.dhis.webapi.json.domain.JsonUser)1 AfterEach (org.junit.jupiter.api.AfterEach)1