Search in sources :

Example 11 with JsonArray

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

the class AbstractCrudControllerTest method replaceTranslationsOk.

@Test
public void replaceTranslationsOk() {
    String id = assertStatus(HttpStatus.CREATED, POST("/dataSets/", "{'name':'My data set', 'periodType':'Monthly'}"));
    JsonArray translations = GET("/dataSets/{id}/translations", id).content().getArray("translations");
    assertTrue(translations.isEmpty());
    PUT("/dataSets/" + id + "/translations", "{'translations': [{'locale':'sv', 'property':'name', 'value':'name sv'}]}").content(HttpStatus.NO_CONTENT);
    JsonResponse content = GET("/dataSets/{id}", id).content();
    translations = GET("/dataSets/{id}/translations", id).content().getArray("translations");
    assertEquals(1, translations.size());
    JsonTranslation translation = translations.get(0, JsonTranslation.class);
    assertEquals("sv", translation.getLocale());
    assertEquals("name", translation.getProperty());
    assertEquals("name sv", translation.getValue());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonResponse(org.hisp.dhis.jsontree.JsonResponse) JsonTranslation(org.hisp.dhis.webapi.json.domain.JsonTranslation) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 12 with JsonArray

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

the class DataApprovalControllerTest method testGetApproval.

@Test
void testGetApproval() {
    JsonArray statuses = GET("/dataApprovals/status?ou={ou}&pe=202101&wf={wf}&ds={ds}", ouId, wfId, dsId).content(HttpStatus.OK).getArray("dataApprovalStateResponses");
    assertEquals(1, statuses.size());
    JsonObject status_t0 = statuses.getObject(0);
    assertEquals("UNAPPROVED_READY", status_t0.getString("state").string());
    JsonObject permissions = status_t0.getObject("permissions");
    assertFalse(permissions.getString("acceptedBy").exists());
    assertFalse(permissions.getString("acceptedAt").exists());
    // now create an approval (approve it)
    assertStatus(HttpStatus.NO_CONTENT, POST("/dataApprovals?ou={ou}&pe=202101&wf={wf}", ouId, wfId));
    JsonObject status_t1 = GET("/dataApprovals/status?ou={ou}&pe=202101&wf={wf}&ds={ds}", ouId, wfId, dsId).content(HttpStatus.OK).getArray("dataApprovalStateResponses").getObject(0);
    assertEquals("APPROVED_HERE", status_t1.getString("state").string());
    permissions = status_t1.getObject("permissions");
    assertFalse(permissions.getBoolean("mayReadAcceptedBy").exists());
    assertTrue(permissions.getString("acceptedAt").exists());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 13 with JsonArray

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

the class DataApprovalControllerTest method testGetMultipleApprovalPermissions_Multiple.

@Test
void testGetMultipleApprovalPermissions_Multiple() {
    JsonArray statuses = GET("/dataApprovals/multiple?ou={ou}&pe=202101&wf={wf}", ouId, wfId).content(HttpStatus.OK);
    assertEquals(1, statuses.size());
    JsonObject status = statuses.getObject(0);
    assertTrue(status.has("wf", "pe", "ou", "aoc"));
    assertEquals(ouId, status.getString("ou").string());
    assertEquals(wfId, status.getString("wf").string());
    assertEquals("202101", status.getString("pe").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 14 with JsonArray

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

the class GistFilterControllerTest method testFilter_GroupAND.

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

Example 15 with JsonArray

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

the class DimensionControllerTest method testGetDimensionsForDataSet.

@Test
void testGetDimensionsForDataSet() {
    String dsId = assertStatus(HttpStatus.CREATED, POST("/dataSets/", "{'name':'My data set', 'periodType':'Monthly', 'categoryCombo':{'id':'" + ccId + "'}}"));
    JsonObject response = GET("/dimensions/dataSet/{ds}", dsId).content();
    JsonArray dimensions = response.getArray("dimensions");
    assertEquals(1, dimensions.size());
    JsonObject gender = dimensions.getObject(0);
    assertEquals("Gender", gender.getString("name").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) 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