Search in sources :

Example 96 with JsonObject

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

the class UserControllerTest method testPutJsonObject_Pre38.

@Test
void testPutJsonObject_Pre38() {
    JsonObject user = GET("/users/{uid}", peter.getUid()).content();
    JsonImportSummary summary = PUT("/37/users/" + peter.getUid(), user.toString()).content(HttpStatus.OK).as(JsonImportSummary.class);
    assertEquals("ImportReport", summary.getResponseType());
    assertEquals("OK", summary.getStatus());
    assertEquals(1, summary.getStats().getUpdated());
    assertEquals(peter.getUid(), summary.getTypeReports().get(0).getObjectReports().get(0).getUid());
}
Also used : JsonImportSummary(org.hisp.dhis.webapi.json.domain.JsonImportSummary) JsonObject(org.hisp.dhis.jsontree.JsonObject) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 97 with JsonObject

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

the class SharingControllerTest method testGetSharing.

@Test
void testGetSharing() {
    String groupId = assertStatus(HttpStatus.CREATED, POST("/userGroups", "{'name':'test'}"));
    JsonObject sharing = GET("/sharing?type=userGroup&id=" + groupId).content(HttpStatus.OK);
    JsonObject meta = sharing.getObject("meta");
    assertTrue(meta.getBoolean("allowPublicAccess").booleanValue());
    assertFalse(meta.getBoolean("allowExternalAccess").booleanValue());
    JsonObject object = sharing.getObject("object");
    assertEquals(groupId, object.getString("id").string());
    assertEquals("test", object.getString("name").string());
    assertEquals("test", object.getString("displayName").string());
    assertEquals("rw------", object.getString("publicAccess").string());
    assertFalse(object.getBoolean("externalAccess").booleanValue());
    assertEquals("admin admin", object.getObject("user").getString("name").string());
    assertEquals(0, object.getArray("userGroupAccesses").size());
    assertEquals(0, object.getArray("userAccesses").size());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 98 with JsonObject

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

the class SharingControllerTest method testSearchUserGroups.

@Test
void testSearchUserGroups() {
    String groupId = assertStatus(HttpStatus.CREATED, POST("/userGroups", "{'name':'test'}"));
    JsonObject matches = GET("/sharing/search?key=" + groupId).content(HttpStatus.OK);
    assertTrue(matches.has("userGroups", "users"));
    assertEquals(0, matches.getArray("userGroups").size());
    assertEquals(0, matches.getArray("users").size());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 99 with JsonObject

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

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

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