diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/ClientModelTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/client/ClientModelTest.java similarity index 87% rename from testsuite/model/src/test/java/org/keycloak/testsuite/model/ClientModelTest.java rename to testsuite/model/src/test/java/org/keycloak/testsuite/model/client/ClientModelTest.java index 1c74dafdc0..596ff38d1a 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/ClientModelTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/client/ClientModelTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.keycloak.testsuite.model; +package org.keycloak.testsuite.model.client; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.MatcherAssert.assertThat; @@ -38,6 +38,8 @@ import org.keycloak.models.RoleProvider; import org.keycloak.models.map.client.MapClientProvider; import org.keycloak.models.map.client.MapClientProviderFactory; +import org.keycloak.testsuite.model.KeycloakModelTest; +import org.keycloak.testsuite.model.RequireProvider; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -237,42 +239,4 @@ public class ClientModelTest extends KeycloakModelTest { return null; }); } - - @Test - public void testClientScopes() { - List clientScopes = new LinkedList<>(); - withRealm(realmId, (session, realm) -> { - ClientModel client = session.clients().addClient(realm, "myClientId"); - - ClientScopeModel clientScope1 = session.clientScopes().addClientScope(realm, "myClientScope1"); - clientScopes.add(clientScope1.getId()); - ClientScopeModel clientScope2 = session.clientScopes().addClientScope(realm, "myClientScope2"); - clientScopes.add(clientScope2.getId()); - - - client.addClientScope(clientScope1, true); - client.addClientScope(clientScope2, false); - - return null; - }); - - withRealm(realmId, (session, realm) -> { - List actualClientScopes = session.clientScopes().getClientScopesStream(realm).map(ClientScopeModel::getId).collect(Collectors.toList()); - assertThat(actualClientScopes, containsInAnyOrder(clientScopes.toArray())); - - ClientScopeModel clientScopeById = session.clientScopes().getClientScopeById(realm, clientScopes.get(0)); - assertThat(clientScopeById.getId(), is(clientScopes.get(0))); - - session.clientScopes().removeClientScopes(realm); - - return null; - }); - - withRealm(realmId, (session, realm) -> { - List actualClientScopes = session.clientScopes().getClientScopesStream(realm).collect(Collectors.toList()); - assertThat(actualClientScopes, empty()); - - return null; - }); - } } diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/clientscope/ClientScopeModelTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/clientscope/ClientScopeModelTest.java new file mode 100644 index 0000000000..29e3ba85bf --- /dev/null +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/clientscope/ClientScopeModelTest.java @@ -0,0 +1,100 @@ +/* + * Copyright 2023 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.keycloak.testsuite.model.clientscope; + +import org.keycloak.models.ClientModel; +import org.keycloak.models.ClientProvider; +import org.keycloak.models.ClientScopeModel; +import org.keycloak.models.ClientScopeProvider; +import org.keycloak.models.Constants; +import org.keycloak.models.KeycloakSession; +import org.keycloak.models.RealmModel; +import org.keycloak.models.RealmProvider; +import org.keycloak.models.RoleProvider; +import org.keycloak.testsuite.model.KeycloakModelTest; +import org.keycloak.testsuite.model.RequireProvider; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; + +/** + * + * @author hmlnarik + */ +@RequireProvider(RealmProvider.class) +@RequireProvider(ClientProvider.class) +@RequireProvider(ClientScopeProvider.class) +@RequireProvider(RoleProvider.class) +public class ClientScopeModelTest extends KeycloakModelTest { + + private String realmId; + + @Override + public void createEnvironment(KeycloakSession s) { + RealmModel realm = createRealm(s, "realm"); + realm.setDefaultRole(s.roles().addRealmRole(realm, Constants.DEFAULT_ROLES_ROLE_PREFIX + "-" + realm.getName())); + this.realmId = realm.getId(); + } + + @Override + public void cleanEnvironment(KeycloakSession s) { + s.realms().removeRealm(realmId); + } + + @Test + public void testClientScopes() { + List clientScopes = new LinkedList<>(); + withRealm(realmId, (session, realm) -> { + ClientModel client = session.clients().addClient(realm, "myClientId"); + + ClientScopeModel clientScope1 = session.clientScopes().addClientScope(realm, "myClientScope1"); + clientScopes.add(clientScope1.getId()); + ClientScopeModel clientScope2 = session.clientScopes().addClientScope(realm, "myClientScope2"); + clientScopes.add(clientScope2.getId()); + + + client.addClientScope(clientScope1, true); + client.addClientScope(clientScope2, false); + + return null; + }); + + withRealm(realmId, (session, realm) -> { + List actualClientScopes = session.clientScopes().getClientScopesStream(realm).map(ClientScopeModel::getId).collect(Collectors.toList()); + assertThat(actualClientScopes, containsInAnyOrder(clientScopes.toArray())); + + ClientScopeModel clientScopeById = session.clientScopes().getClientScopeById(realm, clientScopes.get(0)); + assertThat(clientScopeById.getId(), is(clientScopes.get(0))); + + session.clientScopes().removeClientScopes(realm); + + return null; + }); + + withRealm(realmId, (session, realm) -> { + List actualClientScopes = session.clientScopes().getClientScopesStream(realm).collect(Collectors.toList()); + assertThat(actualClientScopes, empty()); + + return null; + }); + } +} diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/ClientScopeStorageTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/clientscope/ClientScopeStorageTest.java similarity index 95% rename from testsuite/model/src/test/java/org/keycloak/testsuite/model/ClientScopeStorageTest.java rename to testsuite/model/src/test/java/org/keycloak/testsuite/model/clientscope/ClientScopeStorageTest.java index 63243e50a8..b05772fb6f 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/ClientScopeStorageTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/clientscope/ClientScopeStorageTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.keycloak.testsuite.model; +package org.keycloak.testsuite.model.clientscope; import org.hamcrest.Matchers; import org.junit.Assert; @@ -30,6 +30,8 @@ import org.keycloak.storage.StorageId; import org.keycloak.storage.clientscope.ClientScopeStorageProvider; import org.keycloak.storage.clientscope.ClientScopeStorageProviderModel; import org.keycloak.testsuite.federation.HardcodedClientScopeStorageProviderFactory; +import org.keycloak.testsuite.model.KeycloakModelTest; +import org.keycloak.testsuite.model.RequireProvider; @RequireProvider(RealmProvider.class) @RequireProvider(ClientScopeStorageProvider.class) diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserModelTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserModelTest.java similarity index 99% rename from testsuite/model/src/test/java/org/keycloak/testsuite/model/UserModelTest.java rename to testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserModelTest.java index 843bc64a8d..6f92548b73 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserModelTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserModelTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.keycloak.testsuite.model; +package org.keycloak.testsuite.model.user; import org.keycloak.component.ComponentModel; import org.keycloak.models.Constants; @@ -32,6 +32,8 @@ import org.keycloak.storage.UserStorageProviderFactory; import org.keycloak.storage.UserStorageProviderModel; import org.keycloak.storage.UserStorageUtil; import org.keycloak.storage.user.UserRegistrationProvider; +import org.keycloak.testsuite.model.KeycloakModelTest; +import org.keycloak.testsuite.model.RequireProvider; import java.util.ArrayList; import java.util.HashSet; import java.util.List; diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserPaginationTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserPaginationTest.java similarity index 97% rename from testsuite/model/src/test/java/org/keycloak/testsuite/model/UserPaginationTest.java rename to testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserPaginationTest.java index 1dd279df50..a0f4f50919 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserPaginationTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserPaginationTest.java @@ -1,4 +1,4 @@ -package org.keycloak.testsuite.model; +package org.keycloak.testsuite.model.user; import org.hamcrest.Matchers; import org.junit.Test; @@ -10,12 +10,13 @@ import org.keycloak.models.RealmProvider; import org.keycloak.models.UserModel; import org.keycloak.models.UserProvider; import org.keycloak.storage.UserStorageProvider; -import org.keycloak.storage.UserStorageProviderFactory; import org.keycloak.storage.UserStorageProviderModel; import org.keycloak.testsuite.federation.UserPropertyFileStorage; import org.keycloak.testsuite.federation.UserPropertyFileStorage.UserPropertyFileStorageCall; import org.keycloak.testsuite.federation.UserPropertyFileStorageFactory; +import org.keycloak.testsuite.model.KeycloakModelTest; +import org.keycloak.testsuite.model.RequireProvider; import java.util.Arrays; import java.util.Collections; import java.util.List; diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserSyncTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserSyncTest.java similarity index 97% rename from testsuite/model/src/test/java/org/keycloak/testsuite/model/UserSyncTest.java rename to testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserSyncTest.java index f6ddd15e7a..57182d02f5 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/UserSyncTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/user/UserSyncTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.keycloak.testsuite.model; +package org.keycloak.testsuite.model.user; import org.hamcrest.Matchers; import org.junit.Test; @@ -35,6 +35,8 @@ import org.keycloak.storage.ldap.LDAPStorageProvider; import org.keycloak.storage.ldap.LDAPStorageProviderFactory; import org.keycloak.storage.user.ImportSynchronization; import org.keycloak.storage.user.SynchronizationResult; +import org.keycloak.testsuite.model.KeycloakModelTest; +import org.keycloak.testsuite.model.RequireProvider; import org.keycloak.testsuite.util.LDAPTestUtils; import java.util.stream.IntStream;