KEYCLOAK-3733 Added tests for max results in paginated endpoints

This commit is contained in:
Stian Thorgersen 2016-12-02 08:25:46 +01:00
parent 8621733e17
commit 695aa7bec9
4 changed files with 86 additions and 0 deletions

View file

@ -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);

View file

@ -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<AdminEventRepresentation> 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);
}
}

View file

@ -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

View file

@ -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());
}
}