Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Administration page settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djansen-redhat committed Mar 11, 2015
1 parent f66cff3 commit 895a90e
Show file tree
Hide file tree
Showing 3 changed files with 248 additions and 6 deletions.
Expand Up @@ -20,11 +20,13 @@
*/
package org.zanata.page.administration;

import com.google.common.base.Function;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.zanata.page.BasePage;

/**
Expand All @@ -34,9 +36,18 @@
@Slf4j
public class ServerConfigurationPage extends BasePage {

private By urlField = By.id("serverConfigForm:urlField");
private By urlField = By.id("serverConfigForm:urlField:url");
public static By registerUrlField = By.id("serverConfigForm:registerField:registerUrl");
private By emailDomainField = By.id("serverConfigForm:emailDomainField:emailDomain");
private By adminEmailField = By.id("serverConfigForm:adminEmailField:adminEml");
public static By fromEmailField = By.id("serverConfigForm:fromEmailField:fromEml");
private By enableLogCheck = By.id("serverConfigForm:enableLogCheck");
private By logLevelSelect = By.id("serverConfigForm:logEmailLvl");
private By emailDestinationField = By.id("serverConfigForm:logDestEmailField:logDestEml");
private By helpUrlField = By.id("serverConfigForm:helpUrlField");
private By termsUrlField = By.id("serverConfigForm:termsOfUseUrlField");
private By piwikUrl = By.id("serverConfigForm:piwikUrlField:piwikUrlEml");
private By piwikId = By.id("serverConfigForm:piwikIdSiteEml");
private By maxConcurrentField = By.id("serverConfigForm:maxConcurrentPerApiKeyField:maxConcurrentPerApiKeyEml");
private By maxActiveField = By.id("serverConfigForm:maxActiveRequestsPerApiKeyField:maxActiveRequestsPerApiKeyEml");
private By saveButton = By.id("serverConfigForm:save");
Expand All @@ -54,6 +65,42 @@ private void enterTextConfigField(By by, String text) {
.sendKeys(text).perform();
}

public ServerConfigurationPage inputServerURL(String url) {
log.info("Enter Server URL {}", url);
enterTextConfigField(urlField, url);
return new ServerConfigurationPage(getDriver());
}

public ServerConfigurationPage inputRegisterURL(String url) {
log.info("Enter Register URL {}", url);
enterTextConfigField(registerUrlField, url);
return new ServerConfigurationPage(getDriver());
}

public boolean expectFieldValue(final By by, final String expectedValue) {
log.info("Wait for field {} value", by.toString(), expectedValue);
return waitForAMoment().until(new Function<WebDriver, Boolean>() {
@Override
public Boolean apply(WebDriver input) {
String value = waitForWebElement(by).getAttribute("value");
log.info("Found {}", value);
return expectedValue.equals(value);
}
});
}

public ServerConfigurationPage inputAdminEmail(String email) {
log.info("Enter admin email address {}", email);
enterTextConfigField(adminEmailField, email);
return new ServerConfigurationPage(getDriver());
}

public ServerConfigurationPage inputAdminFromEmail(String email) {
log.info("Enter admin From email address {}", email);
enterTextConfigField(fromEmailField, email);
return new ServerConfigurationPage(getDriver());
}

public ServerConfigurationPage inputHelpURL(String url) {
log.info("Enter Help URL {}", url);
enterTextConfigField(helpUrlField, url);
Expand All @@ -66,10 +113,61 @@ public ServerConfigurationPage inputTermsOfUseURL(String url) {
return new ServerConfigurationPage(getDriver());
}

public ServerConfigurationPage clickLoggingEnabledCheckbox() {
log.info("Click enable logging checkbox");
waitForWebElement(enableLogCheck).click();
return new ServerConfigurationPage(getDriver());
}

public ServerConfigurationPage selectLoggingLevel(String logLevel) {
log.info("Select logging level {}", logLevel);
new Select(waitForWebElement(logLevelSelect)).selectByVisibleText(
logLevel);
return new ServerConfigurationPage(getDriver());
}

public String selectedLoggingLevel() {
log.info("Query selected logging level");
return new Select(waitForWebElement(logLevelSelect))
.getFirstSelectedOption().getText();
}

public ServerConfigurationPage inputLogEmailTarget(String email) {
log.info("Enter log email target {}", email);
enterTextConfigField(emailDestinationField, email);
return new ServerConfigurationPage(getDriver());
}

public String getLogEmailTarget() {
log.info("Query log email target");
return waitForWebElement(emailDestinationField).getAttribute("value");
}

public ServerConfigurationPage inputPiwikUrl(String url) {
log.info("Enter Piwik URL", url);
enterTextConfigField(piwikUrl, url);
return new ServerConfigurationPage(getDriver());
}

public String getPiwikUrl() {
log.info("Query Piwik URL");
return waitForWebElement(piwikUrl).getAttribute("value");
}

public ServerConfigurationPage inputPiwikID(String id) {
log.info("Enter Piwik ID", id);
enterTextConfigField(piwikId, id);
return new ServerConfigurationPage(getDriver());
}

public String getPiwikID() {
log.info("Query Piwik ID");
return waitForWebElement(piwikId).getAttribute("value");
}

public ServerConfigurationPage inputMaxConcurrent(int max) {
log.info("Enter maximum concurrent API requests {}", max);
waitForWebElement(maxConcurrentField).clear();
waitForWebElement(maxConcurrentField).sendKeys(max + "");
enterTextConfigField(maxConcurrentField, Integer.toString(max));
return new ServerConfigurationPage(getDriver());
}

Expand All @@ -80,8 +178,7 @@ public String getMaxConcurrentRequestsPerApiKey() {

public ServerConfigurationPage inputMaxActive(int max) {
log.info("Enter maximum active API requests {}", max);
waitForWebElement(maxActiveField).clear();
waitForWebElement(maxActiveField).sendKeys(max + "");
enterTextConfigField(maxActiveField, Integer.toString(max));
return new ServerConfigurationPage(getDriver());
}

Expand Down
@@ -1,27 +1,133 @@
/*
* Copyright 2015, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.feature.administration;

import lombok.extern.slf4j.Slf4j;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.testharness.TestPlan;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.page.account.RegisterPage;
import org.zanata.page.administration.ServerConfigurationPage;
import org.zanata.page.utility.HomePage;
import org.zanata.util.AddUsersRule;
import org.zanata.util.HasEmailRule;
import org.zanata.workflow.LoginWorkFlow;
import org.zanata.workflow.RegisterWorkFlow;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Damian Jansen
* <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@Slf4j
@Category(TestPlan.DetailedTest.class)
public class ServerSettingsTest extends ZanataTestCase {

@Rule
public HasEmailRule hasEmailRule = new HasEmailRule();

@Rule
public AddUsersRule addUsersRule = new AddUsersRule();

@Test
public void setServerURLTest() {
new LoginWorkFlow()
.signIn("admin", "admin")
.goToAdministration()
.goToServerConfigPage()
.inputServerURL("http://myserver.com/zanata")
.save()
.goToHomePage()
.clickContactAdmin()
.inputSubject("I AM THE ADMIN")
.inputMessage("Test pattern")
.send(HomePage.class);
String emailContent = HasEmailRule
.getEmailContent(hasEmailRule.getMessages().get(0));

assertThat(emailContent).contains("http://myserver.com/zanata")
.as("The email indicates the expected server url");
}

@Test
public void setRegisterURLTest() {
String url = "http://myserver.com/register";
ServerConfigurationPage serverConfigurationPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToAdministration()
.goToServerConfigPage()
.inputRegisterURL(url)
.save()
.goToServerConfigPage();

assertThat(serverConfigurationPage
.expectFieldValue(ServerConfigurationPage.registerUrlField, url))
.as("The expected url was displayed");
}

@Test
public void setAdministratorEmailTest() {
new LoginWorkFlow()
.signIn("admin", "admin")
.goToAdministration()
.goToServerConfigPage()
.inputAdminEmail("lara@example.com")
.save()
.goToHomePage()
.clickContactAdmin()
.inputSubject("Test email recipient")
.inputMessage("Test pattern")
.send(HomePage.class);

assertThat(hasEmailRule.getMessages().get(0).getEnvelopeReceiver())
.contains("lara@example.com")
.as("The recipient admin was set");
}

@Test
public void setAdministratorEmailFromTest() {
String email = "lara@example.com";
ServerConfigurationPage serverConfigurationPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToAdministration()
.goToServerConfigPage()
.inputAdminFromEmail(email)
.save()
.goToServerConfigPage();

assertThat(serverConfigurationPage.expectFieldValue(
ServerConfigurationPage.fromEmailField, email));

serverConfigurationPage.goToHomePage().logout();
new RegisterWorkFlow().registerInternal("test1", "test1", "test123",
"test1@test.com");

assertThat(hasEmailRule.getMessages().get(0).getEnvelopeSender())
.contains("lara@example.com")
.as("The server email sender was set");
}

@Test
public void setHelpURLTest() {
HomePage homePage = new LoginWorkFlow()
Expand Down Expand Up @@ -70,4 +176,43 @@ public void setTermsOfUseURLTest() {
.isEqualTo("http://www.test.com/")
.as("The Terms of Use URL was set correctly");
}

@Test
public void setEmailLoggingTest() {
ServerConfigurationPage serverConfigurationPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToAdministration()
.goToServerConfigPage()
.clickLoggingEnabledCheckbox()
.selectLoggingLevel("Error")
.inputLogEmailTarget("lara@example.com")
.save()
.goToServerConfigPage();

assertThat(serverConfigurationPage.selectedLoggingLevel())
.isEqualTo("Error")
.as("Level is correct");
assertThat(serverConfigurationPage.getLogEmailTarget())
.isEqualTo("lara@example.com")
.as("Recipient is correct");
}

@Test
public void setPiwikTest() {
ServerConfigurationPage serverConfigurationPage = new LoginWorkFlow()
.signIn("admin", "admin")
.goToAdministration()
.goToServerConfigPage()
.inputPiwikUrl("http://example.com/piwik")
.inputPiwikID("12345")
.save()
.goToServerConfigPage();

assertThat(serverConfigurationPage.getPiwikUrl())
.isEqualTo("http://example.com/piwik")
.as("Piwik url is correct is correct");
assertThat(serverConfigurationPage.getPiwikID())
.isEqualTo("12345")
.as("Piwik ID is correct");
}
}
Expand Up @@ -134,7 +134,7 @@
<div class="l--push-top-half">
<h:outputLabel>Enabled <i class="i i--info txt--meta"
title="#{msgs['jsf.config.EnableLogEmails.tooltip']}"></i></h:outputLabel>
<h:selectBooleanCheckbox
<h:selectBooleanCheckbox id="enableLogCheck"
value="#{serverConfigurationBean.enableLogEmail}"
styleClass="l--push-h-quarter">
<a4j:ajax execute="@this" render="emailLogSettings"/>
Expand Down

0 comments on commit 895a90e

Please sign in to comment.