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

Commit

Permalink
rhbz988202 - change field validation so that empty string is accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Mar 21, 2014
1 parent e9b8c66 commit 09874b4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
Expand Up @@ -7,8 +7,8 @@
import org.zanata.util.WebElementUtil;

/**
* @author Patrick Huang
* <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class ServerConfigurationPage extends BasePage {
@FindBy(id = "serverConfigForm:urlField")
Expand All @@ -17,6 +17,14 @@ public class ServerConfigurationPage extends BasePage {
@FindBy(id = "serverConfigForm:rateLimitField:rateLimitEml")
private WebElement rateLimitField;

@FindBy(
id = "serverConfigForm:maxConcurrentPerApiKeyField:maxConcurrentPerApiKeyEml")
private WebElement maxConcurrentField;

@FindBy(
id = "serverConfigForm:maxActiveRequestsPerApiKeyField:maxActiveRequestsPerApiKeyEml")
private WebElement maxActiveField;

@FindBy(id = "serverConfigForm:save")
private WebElement saveButton;

Expand All @@ -34,6 +42,26 @@ public String getRateLimit() {
return rateLimitField.getAttribute("value");
}

public ServerConfigurationPage inputMaxConcurrent(int max) {
maxConcurrentField.clear();
maxConcurrentField.sendKeys(max + "");
return this;
}

public String getMaxConcurrentRequestsPerApiKey() {
return maxConcurrentField.getAttribute("value");
}

public ServerConfigurationPage inputMaxActive(int max) {
maxActiveField.clear();
maxActiveField.sendKeys(max + "");
return this;
}

public String getMaxActiveRequestsPerApiKey() {
return maxActiveField.getAttribute("value");
}

public AdministrationPage save() {
saveButton.click();
return new AdministrationPage(getDriver());
Expand Down
Expand Up @@ -71,9 +71,12 @@ public void canConfigureRateLimitByWebUI() {
ServerConfigurationPage.class);

assertThat(serverConfigPage.getRateLimit(), Matchers.isEmptyString());
assertThat(serverConfigPage.getMaxConcurrentRequestsPerApiKey(), Matchers.isEmptyString());
assertThat(serverConfigPage.getMaxActiveRequestsPerApiKey(), Matchers.isEmptyString());

AdministrationPage administrationPage =
serverConfigPage.inputRateLimit(1).save();
serverConfigPage.inputRateLimit(1).inputMaxConcurrent(5)
.inputMaxActive(3).save();

assertThat(administrationPage.getNotificationMessage(),
Matchers.equalTo("Configuration was successfully updated."));
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.io.Serializable;

import javax.validation.constraints.Digits;
import javax.validation.constraints.Pattern;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -94,14 +95,13 @@ public class ServerConfigurationBean implements Serializable {
@Url(canEndInSlash = true)
private String termsOfUseUrl;

@Digits(integer = 10, fraction = 0)
// TODO this won't allow empty string
@Pattern(regexp = "\\d{0,5}")
private String rateLimitPerSecond;

@Digits(integer = 5, fraction = 0)
@Pattern(regexp = "\\d{0,5}")
private String maxConcurrentRequestsPerApiKey;

@Digits(integer = 5, fraction = 0)
@Pattern(regexp = "\\d{0,5}")
private String maxActiveRequestsPerApiKey;

public String getHomeContent() {
Expand Down
4 changes: 2 additions & 2 deletions zanata-war/src/test/resources/log4j.xml
Expand Up @@ -5,7 +5,7 @@
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<param name="threshold" value="DEBUG" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p [%c{1}] - %m%n" />
<param name="ConversionPattern" value="%d %t %-5p [%c{1}] - %m%n" />
</layout>
</appender>
<!--
Expand All @@ -31,7 +31,7 @@
<level value="OFF" />
</logger>
<logger name="org.zanata.rest">
<level value="DEBUG"/>
<level value="ERROR"/>
</logger>
<root>
<level value="ERROR" />
Expand Down

0 comments on commit 09874b4

Please sign in to comment.