Make sure pagination is used even when first is null for getGroups endpoint

Closes #25731

Signed-off-by: Michal Hajas <mhajas@redhat.com>
This commit is contained in:
Michal Hajas 2024-02-08 16:24:39 +01:00 committed by Pedro Igor
parent b4d289c562
commit e55ba5dcdc
2 changed files with 15 additions and 5 deletions

View file

@ -100,10 +100,8 @@ public class GroupsResource {
stream = ModelToRepresentation.searchGroupModelsByAttributes(session, realm, attributes, firstResult, maxResults); stream = ModelToRepresentation.searchGroupModelsByAttributes(session, realm, attributes, firstResult, maxResults);
} else if (Objects.nonNull(search)) { } else if (Objects.nonNull(search)) {
stream = session.groups().searchForGroupByNameStream(realm, search.trim(), exact, firstResult, maxResults); stream = session.groups().searchForGroupByNameStream(realm, search.trim(), exact, firstResult, maxResults);
} else if(Objects.nonNull(firstResult) && Objects.nonNull(maxResults)) {
stream = session.groups().getTopLevelGroupsStream(realm, firstResult, maxResults);
} else { } else {
stream = session.groups().getTopLevelGroupsStream(realm); stream = session.groups().getTopLevelGroupsStream(realm, firstResult, maxResults);
} }
if (populateHierarchy) { if (populateHierarchy) {

View file

@ -1149,9 +1149,21 @@ public class GroupTest extends AbstractGroupTest {
List<GroupRepresentation> allGroups = realm.groups().groups(); List<GroupRepresentation> allGroups = realm.groups().groups();
assertEquals(20, allGroups.size()); assertEquals(20, allGroups.size());
List<GroupRepresentation> slice = realm.groups().groups(5, 7); List<GroupRepresentation> slice = realm.groups().groups(0, 7);
assertEquals(7, slice.size()); assertEquals(7, slice.size());
slice = realm.groups().groups(null, 7);
assertEquals(7, slice.size());
slice = realm.groups().groups(10, null);
assertEquals(10, slice.size());
slice = realm.groups().groups(5, 7);
assertEquals(7, slice.size());
slice = realm.groups().groups(15, 7);
assertEquals(5, slice.size());
List<GroupRepresentation> search = realm.groups().groups("group1",0,20); List<GroupRepresentation> search = realm.groups().groups("group1",0,20);
assertEquals(11, search.size()); assertEquals(11, search.size());
for(GroupRepresentation group : search) { for(GroupRepresentation group : search) {