Search in sources :

Example 6 with JsonObject

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

the class RequestInfoControllerTest method testGetCurrentInfo_NoHeader.

@Test
void testGetCurrentInfo_NoHeader() {
    JsonObject info = GET("/request").content();
    assertTrue(info.isObject());
    assertTrue(info.isEmpty());
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 7 with JsonObject

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

the class SmsGatewayControllerTest method testUpdateGateway.

@Test
void testUpdateGateway() {
    uid = assertStatus(HttpStatus.OK, POST("/gateways", "{'name':'test', 'username':'user', 'password':'pwd', 'type':'http'}"));
    JsonObject gateway = GET("/gateways/{uid}", uid).content();
    assertWebMessage("OK", 200, "OK", "Gateway with uid: " + uid + " has been updated", PUT("/gateways/" + uid, gateway.toString()).content(HttpStatus.OK));
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 8 with JsonObject

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

the class GistFieldsControllerTest method testField_PresetExpandsToReadableFields.

@Test
void testField_PresetExpandsToReadableFields() {
    switchToGuestUser();
    JsonArray users = GET("/users/gist?headless=true").content();
    JsonObject user0 = users.getObject(0);
    assertContainsOnly(user0.node().members().keySet(), "id", "code", "surname", "firstName", "username");
    switchToSuperuser();
    users = GET("/users/gist?headless=true").content();
    user0 = users.getObject(0);
    assertTrue(user0.node().members().keySet().size() > 4);
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

Example 9 with JsonObject

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

the class GistFieldsControllerTest method testField_Attribute.

@Test
void testField_Attribute() {
    // setup a DE with custom attribute value
    String attrId = assertStatus(HttpStatus.CREATED, POST("/attributes", "{" + "'name':'extra', " + "'valueType':'TEXT', " + "'" + ObjectType.DATA_ELEMENT.getPropertyName() + "':true}"));
    String ccId = GET("/categoryCombos/gist?fields=id,categoryOptionCombos::ids&pageSize=1&headless=true&filter=name:eq:default").content().getObject(0).getString("id").string();
    String deId = assertStatus(HttpStatus.CREATED, POST("/dataElements/", "{'name':'My data element', 'shortName':'DE1', 'code':'DE1', 'valueType':'INTEGER', " + "'aggregationType':'SUM', 'zeroIsSignificant':false, 'domainType':'AGGREGATE', " + "'categoryCombo': {'id': '" + ccId + "'}," + "'attributeValues':[{'attribute': {'id':'" + attrId + "'}, 'value':'extra-value'}]" + "}"));
    // test single field
    assertEquals("extra-value", GET("/dataElements/{de}/gist?fields={attr}", deId, attrId).content().string());
    // test multiple fields also with an alias 'extra'
    JsonObject dataElement = GET("/dataElements/{de}/gist?fields=id,name,{attr}::rename(extra)", deId, attrId).content();
    assertEquals(deId, dataElement.getString("id").string());
    assertEquals("My data element", dataElement.getString("name").string());
    assertEquals("extra-value", dataElement.getString("extra").string());
    // test in listing
    JsonArray dataElements = GET("/dataElements/gist?fields=id,name,{attr}::rename(extra)&headless=true", attrId).content();
    assertEquals(1, dataElements.size());
    assertEquals("extra-value", dataElements.getObject(0).getString("extra").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonObject(org.hisp.dhis.jsontree.JsonObject) JsonString(org.hisp.dhis.jsontree.JsonString) Test(org.junit.jupiter.api.Test)

Example 10 with JsonObject

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

the class GistFieldsControllerTest method testField_Sharing_EmbedsObject.

@Test
void testField_Sharing_EmbedsObject() {
    JsonObject groups = GET("/users/{uid}/userGroups/gist?fields=id,sharing,users&headless=true", getSuperuserUid()).content().getObject(0);
    assertTrue(groups.has("id", "sharing"));
    assertTrue(groups.getObject("sharing").has("owner", "external", "users", "userGroups", "public"));
}
Also used : JsonObject(org.hisp.dhis.jsontree.JsonObject) Test(org.junit.jupiter.api.Test)

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