use of org.keycloak.admin.client.resource.GroupResource in project keycloak by keycloak.
the class GroupTest method defaultMaxResults.
@Test
public void defaultMaxResults() {
GroupsResource groups = adminClient.realms().realm("test").groups();
try (Response response = groups.add(GroupBuilder.create().name("test").build())) {
String groupId = ApiUtil.getCreatedId(response);
GroupResource group = groups.group(groupId);
UsersResource users = adminClient.realms().realm("test").users();
for (int i = 0; i < 110; i++) {
try (Response r = users.create(UserBuilder.create().username("test-" + i).build())) {
users.get(ApiUtil.getCreatedId(r)).joinGroup(groupId);
}
}
assertEquals(100, group.members(null, null).size());
assertEquals(100, group.members().size());
assertEquals(105, group.members(0, 105).size());
assertEquals(110, group.members(0, 1000).size());
assertEquals(110, group.members(-1, -2).size());
}
}
use of org.keycloak.admin.client.resource.GroupResource in project keycloak by keycloak.
the class GroupTest method testBriefRepresentationOnGroupMembers.
@Test
public void testBriefRepresentationOnGroupMembers() {
RealmResource realm = adminClient.realms().realm("test");
String groupName = "brief-grouptest-group";
String userName = "brief-grouptest-user";
GroupsResource groups = realm.groups();
try (Response response = groups.add(GroupBuilder.create().name(groupName).build())) {
String groupId = ApiUtil.getCreatedId(response);
GroupResource group = groups.group(groupId);
UsersResource users = realm.users();
UserRepresentation userRepresentation = UserBuilder.create().username(userName).addAttribute("myattribute", "myvalue").build();
Response r = users.create(userRepresentation);
UserResource user = users.get(ApiUtil.getCreatedId(r));
user.joinGroup(groupId);
UserRepresentation defaultRepresentation = group.members(null, null).get(0);
UserRepresentation fullRepresentation = group.members(null, null, false).get(0);
UserRepresentation briefRepresentation = group.members(null, null, true).get(0);
assertEquals("full group member representation includes attributes", fullRepresentation.getAttributes(), userRepresentation.getAttributes());
assertEquals("default group member representation is full", defaultRepresentation.getAttributes(), userRepresentation.getAttributes());
assertNull("brief group member representation omits attributes", briefRepresentation.getAttributes());
group.remove();
user.remove();
}
}
Aggregations