From 15f8e83d4ac44393b16a993bf28f8c2642056547 Mon Sep 17 00:00:00 2001 From: fkiss Date: Wed, 10 Jun 2015 15:02:25 +0200 Subject: [PATCH] added initial tests and page for assigning user role mappings --- .../page/settings/user/RoleMappingsPage.java | 71 +++++++++++++++++++ .../ui/page/settings/{ => user}/UserPage.java | 2 +- .../ui/test/role/AddNewRoleTest.java | 2 +- .../ui/test/user/AddNewUserTest.java | 2 +- .../ui/test/user/RegisterNewUserTest.java | 2 +- .../ui/test/user/RoleMappingsTest.java | 70 ++++++++++++++++++ 6 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/user/RoleMappingsPage.java rename testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/{ => user}/UserPage.java (98%) create mode 100644 testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RoleMappingsTest.java diff --git a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/user/RoleMappingsPage.java b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/user/RoleMappingsPage.java new file mode 100644 index 0000000000..3b92314e10 --- /dev/null +++ b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/user/RoleMappingsPage.java @@ -0,0 +1,71 @@ +package org.keycloak.testsuite.ui.page.settings.user; + +import org.keycloak.testsuite.ui.page.AbstractPage; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.Select; + +import static org.keycloak.testsuite.ui.util.SeleniumUtils.waitGuiForElement; + +/** + * Created by fkiss. + */ +public class RoleMappingsPage extends AbstractPage { + + @FindBy(id = "available") + private Select availableRolesSelect; + + @FindBy(id = "assigned") + private Select assignedRolesSelect; + + @FindBy(id = "realm-composite") + private Select effectiveRolesSelect; + + @FindBy(id = "available-client") + private Select availableClientRolesSelect; + + @FindBy(id = "assigned-client") + private Select assignedClientRolesSelect; + + @FindBy(css = "button[ng-click*='addRealm']") + private WebElement addSelected; + + @FindBy(css = "button[ng-click*='addRealm']") + private WebElement addSelectedButton; + + @FindBy(css = "button[ng-click*='deleteRealm']") + private WebElement removeSelectedButton; + + @FindBy(id = "clients") + private Select clientRolesSelect; + + public void addAvailableRole(String role){ + waitGuiForElement(By.id("available")); + availableRolesSelect.selectByVisibleText(role); + addSelected.click(); + } + + public void removeAssignedRole(String client){ + waitGuiForElement(By.id("assigned")); + assignedRolesSelect.selectByVisibleText(client); + removeSelectedButton.click(); + } + + public void selectClientRole(String client){ + waitGuiForElement(By.id("clients")); + clientRolesSelect.selectByVisibleText(client); + } + + public void addAvailableClientRole(String role){ + waitGuiForElement(By.id("available-client")); + availableRolesSelect.selectByVisibleText(role); + addSelected.click(); + } + + public void removeAssignedClientRole(String client){ + waitGuiForElement(By.id("assigned-client")); + assignedClientRolesSelect.selectByVisibleText(client); + removeSelectedButton.click(); + } +} diff --git a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/UserPage.java b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/user/UserPage.java similarity index 98% rename from testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/UserPage.java rename to testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/user/UserPage.java index 18450b413c..2068879992 100644 --- a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/UserPage.java +++ b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/page/settings/user/UserPage.java @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.keycloak.testsuite.ui.page.settings; +package org.keycloak.testsuite.ui.page.settings.user; import org.jboss.arquillian.graphene.findby.FindByJQuery; import org.keycloak.testsuite.ui.model.User; diff --git a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/role/AddNewRoleTest.java b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/role/AddNewRoleTest.java index 7bcd681d7b..03066e602f 100644 --- a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/role/AddNewRoleTest.java +++ b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/role/AddNewRoleTest.java @@ -17,7 +17,7 @@ import org.junit.Before; import org.junit.Ignore; import org.keycloak.testsuite.ui.AbstractKeyCloakTest; import org.keycloak.testsuite.ui.fragment.FlashMessage; -import org.keycloak.testsuite.ui.page.settings.UserPage; +import org.keycloak.testsuite.ui.page.settings.user.UserPage; import static org.openqa.selenium.By.id; import org.openqa.selenium.support.ui.Select; diff --git a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/AddNewUserTest.java b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/AddNewUserTest.java index c59cd30b16..f65cc15846 100644 --- a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/AddNewUserTest.java +++ b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/AddNewUserTest.java @@ -22,7 +22,7 @@ import org.jboss.arquillian.graphene.findby.FindByJQuery; import org.junit.Test; import org.keycloak.testsuite.ui.fragment.FlashMessage; import org.keycloak.testsuite.ui.model.User; -import org.keycloak.testsuite.ui.page.settings.UserPage; +import org.keycloak.testsuite.ui.page.settings.user.UserPage; import static org.junit.Assert.*; diff --git a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RegisterNewUserTest.java b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RegisterNewUserTest.java index 834ba25263..981c531cd1 100644 --- a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RegisterNewUserTest.java +++ b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RegisterNewUserTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.keycloak.testsuite.ui.fragment.FlashMessage; import org.keycloak.testsuite.ui.model.User; import org.keycloak.testsuite.ui.page.RegisterPage; -import org.keycloak.testsuite.ui.page.settings.UserPage; +import org.keycloak.testsuite.ui.page.settings.user.UserPage; import static org.junit.Assert.*; import org.junit.Before; diff --git a/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RoleMappingsTest.java b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RoleMappingsTest.java new file mode 100644 index 0000000000..4c727b5dfd --- /dev/null +++ b/testsuite/integration-arquillian/src/test/java/org/keycloak/testsuite/ui/test/user/RoleMappingsTest.java @@ -0,0 +1,70 @@ +package org.keycloak.testsuite.ui.test.user; + +import org.jboss.arquillian.graphene.findby.FindByJQuery; +import org.jboss.arquillian.graphene.page.Page; +import org.junit.Before; +import org.junit.Test; +import org.keycloak.testsuite.ui.AbstractKeyCloakTest; +import org.keycloak.testsuite.ui.fragment.FlashMessage; +import org.keycloak.testsuite.ui.model.User; +import org.keycloak.testsuite.ui.page.settings.user.RoleMappingsPage; +import org.keycloak.testsuite.ui.page.settings.user.UserPage; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.openqa.selenium.By.linkText; + +/** + * Created by fkiss. + */ +public class RoleMappingsTest extends AbstractKeyCloakTest { + + @Page + private UserPage userPage; + + @FindByJQuery(".alert") + private FlashMessage flashMessage; + + @Before + public void beforeAddNewUserTest() { + navigation.users(); + } + + @Test + public void addUserAndAssignRole() { + String testUsername = "tester1"; + User testUser = new User(testUsername, "pass"); + userPage.addUser(testUser); + flashMessage.waitUntilPresent(); + assertTrue(flashMessage.getText(), flashMessage.isSuccess()); + navigation.users(); + userPage.findUser(testUsername); + driver.findElement(linkText(testUsername)).click(); + navigation.roleMappings(); + + page.addAvailableRole("create-realm"); + assertTrue(flashMessage.getText(), flashMessage.isSuccess()); + navigation.users(); + userPage.deleteUser(testUsername); + } + + @Test + public void addAndRemoveUserAndAssignRole() { + String testUsername = "tester2"; + User testUser = new User(testUsername, "pass"); + userPage.addUser(testUser); + flashMessage.waitUntilPresent(); + assertTrue(flashMessage.getText(), flashMessage.isSuccess()); + navigation.users(); + userPage.findUser(testUsername); + driver.findElement(linkText(testUsername)).click(); + navigation.roleMappings(); + + page.addAvailableRole("create-realm"); + assertTrue(flashMessage.getText(), flashMessage.isSuccess()); + page.removeAssignedRole("create-realm"); + assertTrue(flashMessage.getText(), flashMessage.isSuccess()); + navigation.users(); + userPage.deleteUser(testUsername); + } +}