Skip to content

Commit

Permalink
KEYCLOAK-6300 List of group members is not sorted alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
vramik authored and stianst committed Jan 25, 2018
1 parent 7c66f76 commit b0fbe5c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@NamedQueries({
@NamedQuery(name="userMemberOf", query="select m from UserGroupMembershipEntity m where m.user = :user and m.groupId = :groupId"),
@NamedQuery(name="userGroupMembership", query="select m from UserGroupMembershipEntity m where m.user = :user"),
@NamedQuery(name="groupMembership", query="select g.user from UserGroupMembershipEntity g where g.groupId = :groupId"),
@NamedQuery(name="groupMembership", query="select g.user from UserGroupMembershipEntity g where g.groupId = :groupId order by g.user.username"),
@NamedQuery(name="userGroupIds", query="select m.groupId from UserGroupMembershipEntity m where m.user = :user"),
@NamedQuery(name="deleteUserGroupMembershipByRealm", query="delete from UserGroupMembershipEntity mapping where mapping.user IN (select u from UserEntity u where u.realmId=:realmId)"),
@NamedQuery(name="deleteUserGroupMembershipsByRealmAndLink", query="delete from UserGroupMembershipEntity mapping where mapping.user IN (select u from UserEntity u where u.realmId=:realmId and u.federationLink=:link)"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.core.Response.Status;
import static org.hamcrest.Matchers.*;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -403,6 +405,38 @@ public void groupMembership() {
assertNames(members, "user-b");
}


@Test
//KEYCLOAK-6300
public void groupMembershipUsersOrder() {
RealmResource realm = adminClient.realms().realm("test");

GroupRepresentation group = new GroupRepresentation();
group.setName("group");
String groupId = createGroup(realm, group).getId();

List<String> usernames = new ArrayList<>();
for (int i = 0; i < 9; i++) {
UserRepresentation user = UserBuilder.create().username("user" + i).build();
usernames.add(user.getUsername());

Response create = realm.users().create(user);
assertEquals(Status.CREATED, create.getStatusInfo());

String userAId = ApiUtil.getCreatedId(create);
realm.users().get(userAId).joinGroup(groupId);

create.close();
}

List<String> memberUsernames = new ArrayList<>();
for (UserRepresentation member : realm.groups().group(groupId).members(0, 10)) {
memberUsernames.add(member.getUsername());
}
assertArrayEquals("Expected: " + usernames + ", was: " + memberUsernames,
usernames.toArray(), memberUsernames.toArray());
}

@Test
// KEYCLOAK-2700
public void deleteRealmWithDefaultGroups() throws IOException {
Expand Down

0 comments on commit b0fbe5c

Please sign in to comment.