From a35aa47f275629d2bbff208de50b7d83744b0dcf Mon Sep 17 00:00:00 2001 From: Vaclav Muzikar Date: Thu, 25 Feb 2016 17:51:38 +0100 Subject: [PATCH 1/3] Add support for some test constants in props file --- .../integration-arquillian/tests/base/pom.xml | 5 +++++ .../keycloak/testsuite/AbstractKeycloakTest.java | 16 ++++++++++++++++ .../src/test/resources/test-constants.properties | 2 ++ 3 files changed, 23 insertions(+) create mode 100644 testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties diff --git a/testsuite/integration-arquillian/tests/base/pom.xml b/testsuite/integration-arquillian/tests/base/pom.xml index ecfe1cea55..61b360484c 100644 --- a/testsuite/integration-arquillian/tests/base/pom.xml +++ b/testsuite/integration-arquillian/tests/base/pom.xml @@ -52,6 +52,11 @@ + + commons-configuration + commons-configuration + 1.10 + diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java index 92dc9c57e2..989b105fb6 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/AbstractKeycloakTest.java @@ -16,6 +16,8 @@ */ package org.keycloak.testsuite; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; import org.keycloak.testsuite.arquillian.TestContext; import java.util.ArrayList; import java.util.List; @@ -98,6 +100,8 @@ public abstract class AbstractKeycloakTest { protected UserRepresentation adminUser; + private PropertiesConfiguration constantsProperties; + @Before public void beforeAbstractKeycloakTest() { adminClient = Keycloak.getInstance(AuthServerTestEnricher.getAuthServerContextRoot() + "/auth", @@ -205,4 +209,16 @@ public abstract class AbstractKeycloakTest { return adminClient.realms(); } + private void loadConstantsProperties() throws ConfigurationException { + constantsProperties = new PropertiesConfiguration("test-constants.properties"); + constantsProperties.setThrowExceptionOnMissing(true); + } + + protected PropertiesConfiguration getConstantsProperties() throws ConfigurationException { + if (constantsProperties == null) { + loadConstantsProperties(); + } + return constantsProperties; + } + } diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties b/testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties new file mode 100644 index 0000000000..6dbea51bbe --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties @@ -0,0 +1,2 @@ +# Some constants used in tests which may vary +ldap-vendors = Active Directory,Red Hat Directory Server,Tivoli,Novell eDirectory,Other \ No newline at end of file From cd063c6a3650dea2a87c1489a2d7eb99b4a1b40b Mon Sep 17 00:00:00 2001 From: Vaclav Muzikar Date: Thu, 25 Feb 2016 17:52:11 +0100 Subject: [PATCH 2/3] Add LDAP vendors test --- .../page/federation/LdapUserProviderForm.java | 18 ++++++++++++++++++ .../federation/LdapUserFederationTest.java | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/federation/LdapUserProviderForm.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/federation/LdapUserProviderForm.java index 5a346416a7..efad97667f 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/federation/LdapUserProviderForm.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/federation/LdapUserProviderForm.java @@ -11,6 +11,9 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; +import java.util.ArrayList; +import java.util.List; + /** * @author fkiss, pdrozd */ @@ -181,6 +184,21 @@ public class LdapUserProviderForm extends Form { vendorSelect.selectByVisibleText(vendor); } + public List getVendors() { + waitUntilElement(By.id("vendor")).is().present(); + + List vendorsElements = vendorSelect.getOptions(); + List vendorsString = new ArrayList<>(); + + for (WebElement vendorElement : vendorsElements) { + String text = vendorElement.getText(); + if (text.equals("")) {continue;} + vendorsString.add(text); + } + + return vendorsString; + } + public void selectAuthenticationType(String authenticationType) { waitUntilElement(By.id("authType")).is().present(); authTypeSelect.selectByVisibleText(authenticationType); diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/federation/LdapUserFederationTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/federation/LdapUserFederationTest.java index a127e418cc..c81c26e8b5 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/federation/LdapUserFederationTest.java +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/federation/LdapUserFederationTest.java @@ -1,9 +1,12 @@ package org.keycloak.testsuite.console.federation; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import java.util.List; import java.util.Properties; +import org.apache.commons.configuration.ConfigurationException; import org.jboss.arquillian.graphene.page.Page; import org.junit.Ignore; import org.junit.Test; @@ -12,6 +15,7 @@ import org.keycloak.representations.idm.UserFederationProviderRepresentation; import org.keycloak.testsuite.console.AbstractConsoleTest; import org.keycloak.testsuite.console.page.federation.CreateLdapUserProvider; import org.keycloak.util.ldap.LDAPEmbeddedServer; +import org.openqa.selenium.WebElement; /** * @author fkiss, pdrozd @@ -141,6 +145,21 @@ public class LdapUserFederationTest extends AbstractConsoleTest { } } + @Test + public void checkVendors() throws ConfigurationException { + createLdapUserProvider.navigateTo(); + + List vendorsExpected = (List) (List) getConstantsProperties().getList("ldap-vendors"); + List vendorsActual = createLdapUserProvider.form().getVendors(); + + int vendorsExpectedSize = vendorsExpected.size(); + int vendorsActualSize = vendorsActual.size(); + assertTrue("Expected vendors count: " + vendorsExpectedSize + "; actual count: " + vendorsActualSize, + vendorsExpectedSize == vendorsActualSize); + + assertTrue("Vendors list doesn't match", vendorsExpected.containsAll(vendorsActual)); + } + private void assertLdapProviderSetting(UserFederationProviderRepresentation ufpr, String name, int priority, String editMode, String syncRegistrations, String vendor, String searchScope, String connectionPooling, String pagination, String enableAccountAfterPasswordUpdate) { From 2d7424c6975353b8017ef32c1b37ba84e7a1b60e Mon Sep 17 00:00:00 2001 From: Vaclav Muzikar Date: Fri, 26 Feb 2016 13:59:28 +0100 Subject: [PATCH 3/3] Add support for testing default theme name in prop file --- .../testsuite/auth/page/login/Login.java | 18 +++++++-- .../org/keycloak/testsuite/model/Theme.java | 39 ------------------- .../test/resources/test-constants.properties | 4 +- .../console/page/realm/GeneralSettings.java | 17 ++++---- .../console/realm/ThemeSettingsTest.java | 10 +++-- 5 files changed, 31 insertions(+), 57 deletions(-) delete mode 100644 testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/model/Theme.java diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/login/Login.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/login/Login.java index 67c145b262..f489f0087d 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/login/Login.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/auth/page/login/Login.java @@ -18,6 +18,7 @@ package org.keycloak.testsuite.auth.page.login; import org.jboss.arquillian.graphene.page.Page; import org.keycloak.testsuite.auth.page.AuthRealm; +import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @@ -36,6 +37,7 @@ public abstract class Login extends AuthRealm { public static final String OIDC = "openid-connect"; public static final String SAML = "saml"; public static final String LOGIN_ACTION = "login-action"; + private String keycloakThemeCssName; @Override public UriBuilder createUriBuilder() { @@ -58,15 +60,23 @@ public abstract class Login extends AuthRealm { return form; } - @FindBy(css = "link[href*='login/keycloak/css/login.css']") - private WebElement keycloakTheme; + public void setKeycloakThemeCssName(String name) { + keycloakThemeCssName = name; + } + + protected By getKeycloakThemeLocator() { + if (keycloakThemeCssName == null) { + throw new IllegalStateException("keycloakThemeCssName property must be set"); + } + return By.cssSelector("link[href*='login/" + keycloakThemeCssName + "/css/login.css']"); + } public void waitForKeycloakThemeNotPresent() { - waitUntilElement(keycloakTheme).is().not().present(); + waitUntilElement(getKeycloakThemeLocator()).is().not().present(); } public void waitForKeycloakThemePresent() { - waitUntilElement(keycloakTheme).is().present(); + waitUntilElement(getKeycloakThemeLocator()).is().present(); } } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/model/Theme.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/model/Theme.java deleted file mode 100644 index a063d6ce2f..0000000000 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/model/Theme.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 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; - -/** - * - * @author Petr Mensik - */ -public enum Theme { - - BASE("base"), KEYCLOAK("keycloak"), PATTERNFLY("patternfly"); - - private final String name; - - private Theme(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - -} diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties b/testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties index 6dbea51bbe..2e405b8455 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/test-constants.properties @@ -1,2 +1,4 @@ # Some constants used in tests which may vary -ldap-vendors = Active Directory,Red Hat Directory Server,Tivoli,Novell eDirectory,Other \ No newline at end of file +ldap-vendors = Active Directory,Red Hat Directory Server,Tivoli,Novell eDirectory,Other +theme-default-name = keycloak +theme-default-css-name = keycloak \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/GeneralSettings.java b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/GeneralSettings.java index a2a32de2a6..32387a59a8 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/GeneralSettings.java +++ b/testsuite/integration-arquillian/tests/other/console/src/main/java/org/keycloak/testsuite/console/page/realm/GeneralSettings.java @@ -18,7 +18,6 @@ package org.keycloak.testsuite.console.page.realm; -import org.keycloak.testsuite.model.Theme; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.Select; @@ -58,19 +57,19 @@ public class GeneralSettings extends RealmSettings { saveButton.click(); } - public void selectLoginTheme(Theme theme) { - loginThemeSelect.selectByVisibleText(theme.getName()); + public void selectLoginTheme(String theme) { + loginThemeSelect.selectByVisibleText(theme); } - public void selecAccountTheme(Theme theme) { - accountThemeSelect.selectByVisibleText(theme.getName()); + public void selecAccountTheme(String theme) { + accountThemeSelect.selectByVisibleText(theme); } - public void selectAdminTheme(Theme theme) { - adminThemeSelect.selectByVisibleText(theme.getName()); + public void selectAdminTheme(String theme) { + adminThemeSelect.selectByVisibleText(theme); } - public void selectEmailTheme(Theme theme) { - emailThemeSelect.selectByVisibleText(theme.getName()); + public void selectEmailTheme(String theme) { + emailThemeSelect.selectByVisibleText(theme); } } diff --git a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/ThemeSettingsTest.java b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/ThemeSettingsTest.java index 092b89324d..57ada69c5d 100644 --- a/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/ThemeSettingsTest.java +++ b/testsuite/integration-arquillian/tests/other/console/src/test/java/org/keycloak/testsuite/console/realm/ThemeSettingsTest.java @@ -17,10 +17,10 @@ */ package org.keycloak.testsuite.console.realm; +import org.apache.commons.configuration.ConfigurationException; import org.jboss.arquillian.graphene.page.Page; import org.junit.Before; import org.junit.Test; -import org.keycloak.testsuite.model.Theme; import org.keycloak.testsuite.console.page.realm.ThemeSettings; /** @@ -41,8 +41,10 @@ public class ThemeSettingsTest extends AbstractRealmTest { } @Test - public void changeLoginThemeTest() { - themeSettingsPage.changeLoginTheme(Theme.BASE.getName()); + public void changeLoginThemeTest() throws ConfigurationException { + testRealmLoginPage.setKeycloakThemeCssName(getConstantsProperties().getString("theme-default-css-name")); + + themeSettingsPage.changeLoginTheme("base"); themeSettingsPage.saveTheme(); testRealmAdminConsolePage.navigateTo(); @@ -51,7 +53,7 @@ public class ThemeSettingsTest extends AbstractRealmTest { testRealmAdminConsolePage.logOut(); themeSettingsPage.navigateTo(); - themeSettingsPage.changeLoginTheme(Theme.KEYCLOAK.getName()); + themeSettingsPage.changeLoginTheme(getConstantsProperties().getString("theme-default-name")); themeSettingsPage.saveTheme(); testRealmAdminConsolePage.navigateTo();