Search in sources :

Example 26 with JsonArray

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

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

the class ProgramMessageControllerTest method testSaveMessages.

@Test
void testSaveMessages() {
    JsonObject status = POST("/messages", "{'programMessages': []}").content(HttpStatus.OK);
    assertTrue(status.isObject());
    assertEquals(1, status.size());
    JsonArray summaries = status.getArray("summaries");
    assertTrue(summaries.isArray());
    assertTrue(summaries.isEmpty());
}
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 28 with JsonArray

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

the class SchemaBasedControllerTest method testGistAPI.

private void testGistAPI(JsonSchema schema, String uid) {
    if (IGNORED_GIST_ENDPOINTS.contains(schema.getName())) {
        return;
    }
    String endpoint = schema.getRelativeApiEndpoint();
    // test gist list of object for the schema
    JsonObject gist = GET(endpoint + "/gist").content();
    assertTrue(gist.getObject("pager").exists());
    JsonArray list = gist.getArray(schema.getPlural());
    assertFalse(list.isEmpty());
    // only if there is only one we are sure its the one we created
    if (list.size() == 1) {
        assertEquals(uid, list.getObject(0).getString("id").string());
    }
    // test the single object gist as well
    JsonObject object = GET(endpoint + "/" + uid + "/gist").content();
    assertTrue(object.exists());
    assertEquals(uid, object.getString("id").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject)

Example 29 with JsonArray

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

the class SmsGatewayControllerTest method tearDown.

@AfterEach
void tearDown() {
    JsonArray gateways = GET("/gateways").content().getArray("gateways");
    for (JsonObject gateway : gateways.asList(JsonObject.class)) {
        assertStatus(HttpStatus.OK, DELETE("/gateways/" + gateway.getString("uid").string()));
    }
    assertTrue(GET("/gateways").content().getArray("gateways").isEmpty());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) AfterEach(org.junit.jupiter.api.AfterEach)

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