Search in sources :

Example 1 with JsonObject

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

the class AbstractDataIntegrityControllerTest method getSummary.

protected final JsonDataIntegritySummary getSummary(String check) {
    JsonObject content = GET("/dataIntegrity/summary?checks={check}&timeout=1000", check).content();
    JsonDataIntegritySummary summary = content.get(check.replace('-', '_'), JsonDataIntegritySummary.class);
    assertTrue(summary.exists());
    assertTrue(summary.isObject());
    return summary;
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) JsonDataIntegritySummary(org.hisp.dhis.webapi.json.domain.JsonDataIntegritySummary)

Example 2 with JsonObject

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

the class DomainJsonResponseTest method testCustomObjectTypeMap.

@Test
void testCustomObjectTypeMap() {
    JsonObject response = createJSON("{'users': {'foo':{'id':'foo'}, 'bar':{'id':'bar'}}}");
    JsonMap<JsonUser> usersById = response.getMap("users", JsonUser.class);
    assertFalse(usersById.isEmpty());
    assertEquals(2, usersById.size());
    assertEquals("foo", usersById.get("foo").getId());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 3 with JsonObject

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

the class DomainJsonResponseTest method testDateType.

@Test
void testDateType() {
    JsonObject response = createJSON("{'user': {'lastUpdated': '2021-01-21T15:14:54.000'}}");
    JsonUser user = response.get("user", JsonUser.class);
    assertEquals(LocalDateTime.of(2021, 1, 21, 15, 14, 54), user.getLastUpdated());
    Assertions.assertNull(user.getCreated());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 4 with JsonObject

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

the class DomainJsonResponseTest method testCustomObjectTypeList.

@Test
void testCustomObjectTypeList() {
    JsonObject response = createJSON("{'users': [ {'id':'foo'} ]}");
    JsonList<JsonUser> users = response.getList("users", JsonUser.class);
    assertEquals("foo", users.get(0).getId());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 5 with JsonObject

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

the class WebClientUtils method getCreatedId.

private static String getCreatedId(HttpResponse response) {
    HttpStatus actual = response.status();
    if (actual == HttpStatus.CREATED) {
        JsonObject report = response.contentUnchecked().getObject("response");
        if (report.exists()) {
            return report.getString("uid").string();
        }
    }
    String location = response.location();
    return location == null ? null : location.substring(location.lastIndexOf('/') + 1);
}
Also used : HttpStatus(org.springframework.http.HttpStatus) 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