From 695aa7bec97db2ea79cacd98a2ee6aa1fa3551bf Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 2 Dec 2016 08:25:46 +0100 Subject: [PATCH] KEYCLOAK-3733 Added tests for max results in paginated endpoints --- .../keycloak/testsuite/admin/UserTest.java | 14 ++++++++++ .../testsuite/admin/event/AdminEventTest.java | 24 +++++++++++++++++ .../admin/event/LoginEventsTest.java | 21 +++++++++++++++ .../testsuite/admin/group/GroupTest.java | 27 +++++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java index 545fbff0f1..5b4777b9cc 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/UserTest.java @@ -28,6 +28,7 @@ import org.keycloak.admin.client.resource.IdentityProviderResource; import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RoleMappingResource; import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.admin.client.resource.UsersResource; import org.keycloak.events.admin.OperationType; import org.keycloak.events.admin.ResourceType; import org.keycloak.models.Constants; @@ -847,6 +848,19 @@ public class UserTest extends AbstractAdminTest { assertNames(roles.clientLevel(clientUuid).listAll(), "client-composite"); } + @Test + public void defaultMaxResults() { + UsersResource users = adminClient.realms().realm("test").users(); + + for (int i = 0; i < 110; i++) { + users.create(UserBuilder.create().username("test-" + i).build()).close(); + } + + assertEquals(100, users.search("test", null, null).size()); + assertEquals(105, users.search("test", 0, 105).size()); + assertEquals(111, users.search("test", 0, 1000).size()); + } + private void switchEditUsernameAllowedOn() { RealmRepresentation rep = realm.toRepresentation(); rep.setEditUsernameAllowed(true); diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java index 2d48ccc3c8..3d33fdc436 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/AdminEventTest.java @@ -19,11 +19,17 @@ package org.keycloak.testsuite.admin.event; import org.junit.Before; import org.junit.Test; +import org.keycloak.admin.client.resource.RealmResource; +import org.keycloak.admin.client.resource.UsersResource; +import org.keycloak.events.EventType; +import org.keycloak.events.admin.OperationType; import org.keycloak.representations.idm.AdminEventRepresentation; import org.keycloak.representations.idm.AuthDetailsRepresentation; +import org.keycloak.representations.idm.EventRepresentation; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.admin.ApiUtil; +import org.keycloak.testsuite.util.UserBuilder; import java.util.Arrays; import java.util.Collections; @@ -127,4 +133,22 @@ public class AdminEventTest extends AbstractEventTest { List events = testRealmResource().getAdminEvents(Arrays.asList("CREATE"), realmName(), null, null, null, null, null, null, null, null); assertEquals(2, events.size()); } + + @Test + public void defaultMaxResults() { + RealmResource realm = adminClient.realms().realm("test"); + AdminEventRepresentation event = new AdminEventRepresentation(); + event.setOperationType(OperationType.CREATE.toString()); + event.setAuthDetails(new AuthDetailsRepresentation()); + event.setRealmId(realm.toRepresentation().getId()); + + for (int i = 0; i < 110; i++) { + testingClient.testing("test").onAdminEvent(event, false); + } + + assertEquals(100, realm.getAdminEvents(null, null, null, null, null, null, null, null, null, null).size()); + assertEquals(105, realm.getAdminEvents(null, null, null, null, null, null, null, null, 0, 105).size()); + assertTrue(realm.getAdminEvents(null, null, null, null, null, null, null, null, 0, 1000).size() >= 110); + } + } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java index a4fa8be87e..dc0d787cd4 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/event/LoginEventsTest.java @@ -20,8 +20,13 @@ package org.keycloak.testsuite.admin.event; import org.jboss.arquillian.graphene.page.Page; import org.junit.Before; import org.junit.Test; +import org.keycloak.admin.client.resource.RealmResource; +import org.keycloak.admin.client.resource.UsersResource; +import org.keycloak.events.EventBuilder; +import org.keycloak.events.EventType; import org.keycloak.representations.idm.EventRepresentation; import org.keycloak.testsuite.console.page.events.LoginEvents; +import org.keycloak.testsuite.util.UserBuilder; import java.util.Arrays; import java.util.List; @@ -128,6 +133,22 @@ public class LoginEventsTest extends AbstractEventTest { assertEquals(2, filteredEvents.size()); } + @Test + public void defaultMaxResults() { + RealmResource realm = adminClient.realms().realm("test"); + EventRepresentation event = new EventRepresentation(); + event.setRealmId(realm.toRepresentation().getId()); + event.setType(EventType.LOGIN.toString()); + + for (int i = 0; i < 110; i++) { + testingClient.testing("test").onEvent(event); + } + + assertEquals(100, realm.getEvents(null, null, null, null, null, null, null, null).size()); + assertEquals(105, realm.getEvents(null, null, null, null, null, null, 0, 105).size()); + assertTrue(realm.getEvents(null, null, null, null, null, null, 0, 1000).size() >= 110); + } + /* Removed this test because it takes too long. The default interval for event cleanup is 15 minutes (900 seconds). I don't have time to figure out diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java index 1f0274e9cb..d16626f86a 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/group/GroupTest.java @@ -19,8 +19,11 @@ package org.keycloak.testsuite.admin.group; import org.junit.Assert; import org.junit.Test; +import org.keycloak.admin.client.resource.GroupResource; +import org.keycloak.admin.client.resource.GroupsResource; import org.keycloak.admin.client.resource.RealmResource; import org.keycloak.admin.client.resource.RoleMappingResource; +import org.keycloak.admin.client.resource.UsersResource; import org.keycloak.events.admin.OperationType; import org.keycloak.events.admin.ResourceType; import org.keycloak.models.Constants; @@ -578,4 +581,28 @@ public class GroupTest extends AbstractGroupTest { assertThat(userClient.realms().findAll(), // Any admin operation will do not(empty())); } + + @Test + public void defaultMaxResults() { + GroupsResource groups = adminClient.realms().realm("test").groups(); + Response response = groups.add(GroupBuilder.create().name("test").build()); + String groupId = ApiUtil.getCreatedId(response); + response.close(); + + GroupResource group = groups.group(groupId); + + UsersResource users = adminClient.realms().realm("test").users(); + + for (int i = 0; i < 110; i++) { + Response r = users.create(UserBuilder.create().username("test-" + i).build()); + String userId = ApiUtil.getCreatedId(r); + r.close(); + + users.get(userId).joinGroup(groupId); + } + + assertEquals(100, group.members(null, null).size()); + assertEquals(105, group.members(0, 105).size()); + assertEquals(110, group.members(0, 1000).size()); + } }