Search in sources :

Example 6 with GroupResource

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());
    }
}
Also used : Response(javax.ws.rs.core.Response) UsersResource(org.keycloak.admin.client.resource.UsersResource) GroupResource(org.keycloak.admin.client.resource.GroupResource) GroupsResource(org.keycloak.admin.client.resource.GroupsResource) Test(org.junit.Test)

Example 7 with GroupResource

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();
    }
}
Also used : Response(javax.ws.rs.core.Response) RealmResource(org.keycloak.admin.client.resource.RealmResource) UsersResource(org.keycloak.admin.client.resource.UsersResource) UserResource(org.keycloak.admin.client.resource.UserResource) GroupResource(org.keycloak.admin.client.resource.GroupResource) GroupsResource(org.keycloak.admin.client.resource.GroupsResource) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Aggregations

GroupResource (org.keycloak.admin.client.resource.GroupResource)7 Test (org.junit.Test)6 Response (javax.ws.rs.core.Response)5 RealmResource (org.keycloak.admin.client.resource.RealmResource)5 GroupsResource (org.keycloak.admin.client.resource.GroupsResource)3 GroupRepresentation (org.keycloak.representations.idm.GroupRepresentation)3 ArrayList (java.util.ArrayList)2 UserResource (org.keycloak.admin.client.resource.UserResource)2 UsersResource (org.keycloak.admin.client.resource.UsersResource)2 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Logger (org.jboss.logging.Logger)1 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)1