Search in sources :

Example 1 with JsonArray

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

the class UserLookupControllerTest method testLookUpUsers.

/**
 * This test makes sure a user having the same role as users in the system
 * can see those users.
 */
@Test
void testLookUpUsers() {
    User tester = switchToNewUser("tester");
    switchToSuperuser();
    assertStatus(HttpStatus.NO_CONTENT, POST("/userRoles/" + roleId + "/users/" + tester.getUid()));
    switchContextToUser(tester);
    JsonArray matches = GET("/userLookup?query=John").content().getArray("users");
    assertEquals(1, matches.size());
    JsonUser user = matches.get(0, JsonUser.class);
    assertEquals("John", user.getFirstName());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) User(org.hisp.dhis.user.User) Test(org.junit.jupiter.api.Test) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest)

Example 2 with JsonArray

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

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

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

the class GistFieldsControllerTest method testField_Collection_DefaultIsSize.

@Test
void testField_Collection_DefaultIsSize() {
    JsonArray matches = GET("/userGroups/gist?fields=name,users&headless=true").content();
    assertEquals(1, matches.size());
    assertEquals(1, matches.getObject(0).getNumber("users").intValue());
    assertTrue(matches.getObject(0).getObject("apiEndpoints").getString("users").exists());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) Test(org.junit.jupiter.api.Test)

Example 5 with JsonArray

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

the class GistFieldsControllerTest method testField_UserNameAutomaticFromTransformation.

@Test
void testField_UserNameAutomaticFromTransformation() {
    JsonArray users = GET("/users/gist?fields=id,name&headless=true").content();
    assertEquals("admin admin", users.getObject(0).getString("name").string());
}
Also used : JsonArray(org.hisp.dhis.jsontree.JsonArray) 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