From 19a59429aefce82c2e21a07528ae8bd82b6a8391 Mon Sep 17 00:00:00 2001 From: David Klassen Date: Wed, 19 Apr 2017 13:25:30 +0200 Subject: [PATCH] KEYCLOAK-2976 Merge two "ClientTest" classes in integration-arquillian --- .../keycloak/testsuite/admin/ClientTest.java | 27 +++-- .../testsuite/admin/client/ClientTest.java | 107 ------------------ 2 files changed, 20 insertions(+), 114 deletions(-) delete mode 100644 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientTest.java diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java index 1038491418..257eb7d309 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/ClientTest.java @@ -56,12 +56,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; /** * @author Stian Thorgersen @@ -82,7 +77,9 @@ public class ClientTest extends AbstractAdminTest { response.close(); String id = ApiUtil.getCreatedId(response); getCleanup().addClientUuid(id); + ClientRepresentation found = ApiUtil.findClientResourceByClientId(realm, "my-app").toRepresentation(); + assertEquals("my-app", found.getClientId()); assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.clientResourcePath(id), rep, ResourceType.CLIENT); rep.setId(id); @@ -102,8 +99,9 @@ public class ClientTest extends AbstractAdminTest { public void removeClient() { String id = createClient().getId(); + assertNotNull(ApiUtil.findClientByClientId(realm, "my-app")); realm.clients().get(id).remove(); - + assertNull(ApiUtil.findClientResourceByClientId(realm, "my-app")); assertAdminEvents.assertEvent(realmId, OperationType.DELETE, AdminEventPaths.clientResourcePath(id), ResourceType.CLIENT); } @@ -148,6 +146,21 @@ public class ClientTest extends AbstractAdminTest { assertEquals(1, userSessions.get(0).getClients().size()); } + @Test + public void getAllClients() { + List allClients = realm.clients().findAll(); + assertNotNull(allClients); + assertFalse(allClients.isEmpty()); + } + + @Test + public void getClientById() { + createClient(); + ClientRepresentation rep = ApiUtil.findClientResourceByClientId(realm, "my-app").toRepresentation(); + ClientRepresentation gotById = realm.clients().get(rep.getId()).toRepresentation(); + assertClient(rep, gotById); + } + @Test // KEYCLOAK-1110 public void deleteDefaultRole() { diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientTest.java deleted file mode 100644 index 4adee16752..0000000000 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/ClientTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2016 Red Hat Inc. and/or its affiliates and other contributors - * as indicated by the @author tags. All rights reserved. - * - * 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.admin.client; - -import org.junit.Test; -import org.keycloak.admin.client.resource.ClientResource; -import org.keycloak.events.admin.OperationType; -import org.keycloak.events.admin.ResourceType; -import org.keycloak.representations.idm.ClientRepresentation; -import org.keycloak.testsuite.util.AdminEventPaths; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * - * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. - */ -public class ClientTest extends AbstractClientTest { - - public static void assertEqualClients(ClientRepresentation expected, ClientRepresentation actual) { - assertEquals(expected.getClientId(), actual.getClientId()); - assertEquals(expected.getName(), actual.getName()); - assertEquals(expected.getDescription(), actual.getDescription()); - assertEquals(expected.getBaseUrl(), actual.getBaseUrl()); - - assertTrue(expected.getRedirectUris().containsAll(actual.getRedirectUris())); - assertTrue(expected.getWebOrigins().containsAll(actual.getWebOrigins())); - assertEquals(expected.getRegisteredNodes(), actual.getRegisteredNodes()); - } - - @Test - public void testCreateClient() { - createOidcClient("foo"); - ClientRepresentation found = findClientRepresentation("foo"); - assertEquals("foo", found.getName()); - } - - @Test - public void testDeleteClient() { - String clientDbId = createOidcClient("deleteMe"); - - ClientResource clientRsc = findClientResource("deleteMe"); - assertNotNull(clientRsc); - clientRsc.remove(); - assertNull(findClientResource("deleteMe")); - - assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.clientResourcePath(clientDbId), ResourceType.CLIENT); - } - - @Test - public void testUpdateClient() { - createOidcClient("updateMe"); - ClientRepresentation clientRep = findClientRepresentation("updateMe"); - assertEquals("updateMe", clientRep.getName()); - - clientRep.setName("iWasUpdated"); - findClientResource("updateMe").update(clientRep); - - ClientRepresentation updatedClient = findClientRepresentation("iWasUpdated"); - assertNotNull(updatedClient); - assertEquals("updateMe", updatedClient.getClientId()); - assertEquals("iWasUpdated", updatedClient.getName()); - - // Assert admin event - ClientRepresentation expectedClientRep = new ClientRepresentation(); - expectedClientRep.setClientId("updateMe"); - expectedClientRep.setName("iWasUpdated"); - assertAdminEvents.assertEvent(getRealmId(), OperationType.UPDATE, AdminEventPaths.clientResourcePath(clientRep.getId()), expectedClientRep, ResourceType.CLIENT); - } - - @Test - public void testGetAllClients() { - List allClients = testRealmResource().clients().findAll(); - assertNotNull(allClients); - assertFalse(allClients.isEmpty()); - } - - @Test - public void getClientByIdTest() { - createOidcClient("byidclient"); - ClientRepresentation rep = findClientRepresentation("byidclient"); - ClientRepresentation gotById = testRealmResource().clients().get(rep.getId()).toRepresentation(); - assertEqualClients(rep, gotById); - } - -}