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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations