KEYCLOAK-12249 added test to test that time is localized
This commit is contained in:
parent
582046bbfe
commit
ace64c1f0c
6 changed files with 79 additions and 13 deletions
|
@ -51,7 +51,8 @@ public class LocaleDropdown {
|
||||||
else {
|
else {
|
||||||
Actions actions = new Actions(driver);
|
Actions actions = new Actions(driver);
|
||||||
log.info("Moving mouse cursor to the localization menu");
|
log.info("Moving mouse cursor to the localization menu");
|
||||||
actions.moveToElement(currentLocaleLink).perform();
|
actions.moveToElement(currentLocaleLink, -10, 0)
|
||||||
|
.moveToElement(currentLocaleLink).perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
// click desired locale
|
// click desired locale
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
parent=${theme-default-name}-preview
|
parent=${theme-default-name}-preview
|
||||||
locales=en,lang01,lang02,lang03,lang04,lang05,test,lang06,lang07,lang08,lang09,lang10
|
locales=en,de,lang01,lang02,lang03,lang04,lang05,test,lang06,lang07,lang08,lang09,lang10
|
|
@ -1,2 +1,2 @@
|
||||||
parent=${theme-default-name}
|
parent=${theme-default-name}
|
||||||
locales=en,lang01,lang02,lang03,lang04,lang05,test,lang06,lang07,lang08,lang09,lang10
|
locales=en,de,lang01,lang02,lang03,lang04,lang05,test,lang06,lang07,lang08,lang09,lang10
|
|
@ -26,6 +26,7 @@ import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.models.UserSessionModel;
|
import org.keycloak.models.UserSessionModel;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
|
import org.keycloak.representations.idm.UserRepresentation;
|
||||||
import org.keycloak.testsuite.ui.account2.page.AbstractLoggedInPage;
|
import org.keycloak.testsuite.ui.account2.page.AbstractLoggedInPage;
|
||||||
import org.keycloak.testsuite.ui.account2.page.DeviceActivityPage;
|
import org.keycloak.testsuite.ui.account2.page.DeviceActivityPage;
|
||||||
import org.keycloak.testsuite.util.ClientBuilder;
|
import org.keycloak.testsuite.util.ClientBuilder;
|
||||||
|
@ -33,7 +34,9 @@ import org.keycloak.testsuite.util.OAuthClient;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -50,8 +53,10 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD;
|
import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD;
|
||||||
import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
||||||
|
import static org.keycloak.testsuite.util.UIUtils.refreshPageAndWaitForLoad;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
@ -101,6 +106,7 @@ public class DeviceActivityTest extends BaseAccountPageTest {
|
||||||
));
|
));
|
||||||
|
|
||||||
realm.setAccountTheme(LOCALIZED_THEME_PREVIEW); // using localized custom theme for the client localized name
|
realm.setAccountTheme(LOCALIZED_THEME_PREVIEW); // using localized custom theme for the client localized name
|
||||||
|
configureInternationalizationForRealm(testRealms.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -229,6 +235,27 @@ public class DeviceActivityTest extends BaseAccountPageTest {
|
||||||
assertEquals(startedAt.plusSeconds(ssoLifespan), expiresAt);
|
assertEquals(startedAt.plusSeconds(ssoLifespan), expiresAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void timeLocaleTest() {
|
||||||
|
String sessionId = createSession(Browsers.CHROME);
|
||||||
|
UserRepresentation user = testUserResource().toRepresentation();
|
||||||
|
final Locale locale = Locale.GERMAN;
|
||||||
|
user.setAttributes(new HashMap<String, List<String>>() {{
|
||||||
|
put("locale", Collections.singletonList(locale.toLanguageTag()));
|
||||||
|
}});
|
||||||
|
testUserResource().update(user);
|
||||||
|
|
||||||
|
refreshPageAndWaitForLoad();
|
||||||
|
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d. MMMM yyyy, H:mm", locale);
|
||||||
|
DeviceActivityPage.Session session = deviceActivityPage.getSession(sessionId);
|
||||||
|
try {
|
||||||
|
LocalDateTime.parse(session.getLastAccess(), formatter);
|
||||||
|
} catch (DateTimeParseException e) {
|
||||||
|
fail("Time was not formatted with the locale");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ipTest() {
|
public void ipTest() {
|
||||||
final String ip = "146.58.69.12";
|
final String ip = "146.58.69.12";
|
||||||
|
@ -255,8 +282,7 @@ public class DeviceActivityTest extends BaseAccountPageTest {
|
||||||
// using direct grant not to use current browser
|
// using direct grant not to use current browser
|
||||||
res = oauth.doGrantAccessTokenRequest(
|
res = oauth.doGrantAccessTokenRequest(
|
||||||
TEST, testUser.getUsername(), PASSWORD, null, TEST_CLIENT_ID, TEST_CLIENT_SECRET, browser.userAgent);
|
TEST, testUser.getUsername(), PASSWORD, null, TEST_CLIENT_ID, TEST_CLIENT_SECRET, browser.userAgent);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return res.getSessionState(); // session id
|
return res.getSessionState(); // session id
|
||||||
|
@ -267,8 +293,7 @@ public class DeviceActivityTest extends BaseAccountPageTest {
|
||||||
assertTrue("Session should be present", session.isPresent());
|
assertTrue("Session should be present", session.isPresent());
|
||||||
if (browser.sessionBrowser != null) {
|
if (browser.sessionBrowser != null) {
|
||||||
assertEquals(browser.sessionBrowser, session.getBrowser());
|
assertEquals(browser.sessionBrowser, session.getBrowser());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
assertFalse("Browser identification shouldn't be present", session.isBrowserDisplayed());
|
assertFalse("Browser identification shouldn't be present", session.isBrowserDisplayed());
|
||||||
}
|
}
|
||||||
assertEquals(browser.iconName, session.getBrowserIconName());
|
assertEquals(browser.iconName, session.getBrowserIconName());
|
||||||
|
@ -276,7 +301,7 @@ public class DeviceActivityTest extends BaseAccountPageTest {
|
||||||
assertSessionRowsAreNotEmpty(session, true);
|
assertSessionRowsAreNotEmpty(session, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertSessionRowsAreNotEmpty(DeviceActivityPage.Session session, boolean expectSignOutPresent){
|
private void assertSessionRowsAreNotEmpty(DeviceActivityPage.Session session, boolean expectSignOutPresent) {
|
||||||
assertFalse("IP address shouldn't be empty", session.getIp().isEmpty());
|
assertFalse("IP address shouldn't be empty", session.getIp().isEmpty());
|
||||||
assertFalse("Last accessed shouldn't be empty", session.getLastAccess().isEmpty());
|
assertFalse("Last accessed shouldn't be empty", session.getLastAccess().isEmpty());
|
||||||
assertFalse("Started shouldn't be empty", session.getStarted().isEmpty());
|
assertFalse("Started shouldn't be empty", session.getStarted().isEmpty());
|
||||||
|
|
|
@ -21,17 +21,24 @@ import org.jboss.arquillian.graphene.page.Page;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
|
import org.keycloak.models.credential.PasswordCredentialModel;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
import org.keycloak.testsuite.ui.account2.page.PersonalInfoPage;
|
import org.keycloak.testsuite.ui.account2.page.PersonalInfoPage;
|
||||||
|
import org.keycloak.testsuite.ui.account2.page.SigningInPage;
|
||||||
import org.keycloak.testsuite.ui.account2.page.WelcomeScreen;
|
import org.keycloak.testsuite.ui.account2.page.WelcomeScreen;
|
||||||
import org.keycloak.testsuite.util.WaitUtils;
|
import org.keycloak.testsuite.util.WaitUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
import static java.util.Collections.singletonMap;
|
import static java.util.Collections.singletonMap;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
|
@ -43,6 +50,10 @@ public class InternationalizationTest extends AbstractAccountTest {
|
||||||
@Page
|
@Page
|
||||||
private PersonalInfoPage personalInfoPage;
|
private PersonalInfoPage personalInfoPage;
|
||||||
|
|
||||||
|
@Page
|
||||||
|
private SigningInPage signingInPage;
|
||||||
|
private SigningInPage.CredentialType passwordCredentialType;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||||
super.addTestRealms(testRealms);
|
super.addTestRealms(testRealms);
|
||||||
|
@ -52,6 +63,7 @@ public class InternationalizationTest extends AbstractAccountTest {
|
||||||
@Before
|
@Before
|
||||||
public void beforeI18nTest() {
|
public void beforeI18nTest() {
|
||||||
assertTestUserLocale(null);
|
assertTestUserLocale(null);
|
||||||
|
passwordCredentialType = signingInPage.getCredentialType(PasswordCredentialModel.TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,6 +105,34 @@ public class InternationalizationTest extends AbstractAccountTest {
|
||||||
assertCustomLocalePersonalInfo();
|
assertCustomLocalePersonalInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDisplayTimeUsingSelectedLocale() {
|
||||||
|
signingInPage.navigateTo();
|
||||||
|
loginToAccount();
|
||||||
|
SigningInPage.UserCredential passwordCred =
|
||||||
|
passwordCredentialType.getUserCredential(testUserResource().credentials().get(0).getId());
|
||||||
|
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy, h:mm a", Locale.ENGLISH);
|
||||||
|
try {
|
||||||
|
LocalDateTime.parse(passwordCred.getCreatedAtStr(), formatter);
|
||||||
|
} catch (DateTimeParseException e) {
|
||||||
|
fail("Time was not formatted with the locale");
|
||||||
|
}
|
||||||
|
|
||||||
|
signingInPage.header().clickLogoutBtn();
|
||||||
|
signingInPage.navigateTo();
|
||||||
|
loginPage.localeDropdown().selectAndAssert("Deutsch");
|
||||||
|
loginPage.form().login(testUser);
|
||||||
|
|
||||||
|
DateTimeFormatter formatterDe = DateTimeFormatter.ofPattern("d. MMMM yyyy, H:mm", Locale.GERMAN);
|
||||||
|
|
||||||
|
try {
|
||||||
|
LocalDateTime.parse(passwordCred.getCreatedAtStr(), formatterDe);
|
||||||
|
} catch (DateTimeParseException e) {
|
||||||
|
fail("Time was not formatted with the locale");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void assertCustomLocaleWelcomeScreen() {
|
private void assertCustomLocaleWelcomeScreen() {
|
||||||
assertEquals("Vítejte v Keycloaku", welcomeScreen.getWelcomeMessage());
|
assertEquals("Vítejte v Keycloaku", welcomeScreen.getWelcomeMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,21 +41,21 @@ public class WelcomeScreen extends AbstractAccountPage {
|
||||||
@FindBy(xpath = "//*[@id='" + ROOT_ELEMENT_ID + "']//header")
|
@FindBy(xpath = "//*[@id='" + ROOT_ELEMENT_ID + "']//header")
|
||||||
private WelcomeScreenHeader header;
|
private WelcomeScreenHeader header;
|
||||||
|
|
||||||
@FindBy(xpath = "//*[@id='landing-personal-info']/a")
|
@FindBy(xpath = "//a[@id='landing-personal-info']")
|
||||||
private WebElement personalInfoLink;
|
private WebElement personalInfoLink;
|
||||||
@FindBy(xpath = "//*[@id='landingChangePasswordLink']/a")
|
@FindBy(xpath = "//*[@id='landingChangePasswordLink']/a")
|
||||||
private WebElement changePasswordLink;
|
private WebElement changePasswordLink;
|
||||||
@FindBy(xpath = "//*[@id='landing-authenticator']/a")
|
@FindBy(xpath = "//a[@id='landing-authenticator']")
|
||||||
private WebElement authenticatorLink;
|
private WebElement authenticatorLink;
|
||||||
@FindBy(xpath = "//*[@id='landing-device-activity']/a")
|
@FindBy(xpath = "//*[@id='landing-device-activity']/a")
|
||||||
private WebElement deviceActivityLink;
|
private WebElement deviceActivityLink;
|
||||||
@FindBy(xpath = "//*[@id='landing-linked-accounts']/a")
|
@FindBy(xpath = "//*[@id='landing-linked-accounts']/a")
|
||||||
private WebElement linkedAccountsLink;
|
private WebElement linkedAccountsLink;
|
||||||
@FindBy(xpath = "//*[@id='landing-applications']/a")
|
@FindBy(xpath = "//a[@id='landing-applications']")
|
||||||
private WebElement applicationsLink;
|
private WebElement applicationsLink;
|
||||||
@FindBy(id = "landing-resources")
|
@FindBy(id = "landing-resources")
|
||||||
private WebElement myResourcesCard;
|
private WebElement myResourcesCard;
|
||||||
@FindBy(xpath = "//*[@id='landing-resources']/a")
|
@FindBy(xpath = "//a[@id='landing-resources']")
|
||||||
private WebElement myResourcesLink;
|
private WebElement myResourcesLink;
|
||||||
@FindBy(id = "landingLogo")
|
@FindBy(id = "landingLogo")
|
||||||
private WebElement logoLink;
|
private WebElement logoLink;
|
||||||
|
|
Loading…
Reference in a new issue