Author: pyaschenko
Date: 2010-11-24 08:31:12 -0500 (Wed, 24 Nov 2010)
New Revision: 20158
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java
Log:
http://jira.jboss.com/jira/browse/RF-9329
DoubleRangeValidator, LongRangeValidator and tests was added
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/double-range-validator.js 2010-11-24
13:31:12 UTC (rev 20158)
@@ -0,0 +1,31 @@
+RichFaces.csv.addValidator({"double-range":
+ (function(rf) {
+ return function (componentId, value, params) {
+
+ if (typeof value == "string") {
+ value = $.trim(value);
+ }
+ if (!rf.csv.RE_FLOAT.test(value) || (value = parseFloat(value))==NaN) {
+ throw rf.csv.getMessage(params.customMessage, 'DOUBLE_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ }
+
+ var isMinSet = typeof params.minimum == "number";
+ var isMaxSet = typeof params.maximum == "number";
+
+ if (isMaxSet && value > params.maximum) {
+ if (isMinSet) {
+ throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ } else {
+ throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_MAXIMUM', [params.maximum, componentId]);
+ }
+ }
+ if (isMinSet && value < params.minimum) {
+ if (isMaxSet) {
+ throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ } else {
+ throw rf.csv.getMessage(params.customMessage,
'DOUBLE_RANGE_VALIDATOR_MINIMUM', [params.minimum, componentId]);
+ }
+ }
+ }
+ })(window.RichFaces || (window.RichFaces={}))
+});
\ No newline at end of file
Added:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/long-range-validator.js 2010-11-24
13:31:12 UTC (rev 20158)
@@ -0,0 +1,31 @@
+RichFaces.csv.addValidator({"long-range":
+ (function(rf) {
+ return function (componentId, value, params) {
+
+ if (typeof value == "string") {
+ value = $.trim(value);
+ }
+ if (!rf.csv.RE_DIGITS.test(value)) {
+ throw rf.csv.getMessage(params.customMessage, 'LONG_RANGE_VALIDATOR_TYPE',
[componentId, ""]);
+ }
+
+ var isMinSet = typeof params.minimum == "number";
+ var isMaxSet = typeof params.maximum == "number";
+
+ if (isMaxSet && value > params.maximum) {
+ if (isMinSet) {
+ throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ } else {
+ throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_MAXIMUM', [params.maximum, componentId]);
+ }
+ }
+ if (isMinSet && value < params.minimum) {
+ if (isMaxSet) {
+ throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
+ } else {
+ throw rf.csv.getMessage(params.customMessage,
'LONG_RANGE_VALIDATOR_MINIMUM', [params.minimum, componentId]);
+ }
+ }
+ }
+ })(window.RichFaces || (window.RichFaces={}))
+});
\ No newline at end of file
Modified:
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2010-11-24
13:27:13 UTC (rev 20157)
+++
branches/RF-8742-1/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2010-11-24
13:31:12 UTC (rev 20158)
@@ -10,6 +10,7 @@
$.extend(rf.csv, {
RE_DIGITS: /^-?\d+$/,
+ RE_FLOAT: /^(-?\d+)?(\.(\d+)?(e[+-]?\d+)?)?$/,
MESSAGE_EVENT_NAME: "onmessage."+rf.Event.RICH_NAMESPACE,
// Messages API
addMessage: function (messagesObject) {
Modified:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java 2010-11-24
13:27:13 UTC (rev 20157)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java 2010-11-24
13:31:12 UTC (rev 20158)
@@ -30,6 +30,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.Map.Entry;
@@ -55,7 +56,6 @@
import org.jboss.test.faces.jetty.JettyServer;
import org.junit.After;
import org.junit.Before;
-import org.junit.runner.RunWith;
import org.richfaces.application.MessageFactory;
import org.richfaces.application.ServiceTracker;
@@ -262,6 +262,7 @@
@Before
public void setUp() throws Exception {
+ Locale.setDefault(Locale.US);
testBean = new TestBean();
environment = new HtmlUnitEnvironment(new JettyServer());
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/DoubleRangeValidatorTest.java 2010-11-24
13:31:12 UTC (rev 20158)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt 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.richfaces.convert;
+
+import javax.faces.validator.DoubleRangeValidator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.appplication.FacesMessages;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+(a)RunWith(ValidatorTestRunner.class)
+public class DoubleRangeValidatorTest extends BaseTest {
+
+ private Enum<?>[] messages = { FacesMessages.DOUBLE_RANGE_VALIDATOR_MAXIMUM,
FacesMessages.DOUBLE_RANGE_VALIDATOR_MINIMUM,
FacesMessages.DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE,
FacesMessages.DOUBLE_RANGE_VALIDATOR_TYPE };
+
+ private void setup() {
+
setClientFunction("RichFaces.csv.getValidator('double-range')");
+ setObjectId(DoubleRangeValidator.VALIDATOR_ID);
+ setErrorMessageEnums(messages);
+ }
+
+ public DoubleRangeValidatorTest() {
+ super("META-INF/resources/org.richfaces/double-range-validator.js");
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "1.e10"),
+ @TestData(submittedValue = "1.e-10"),
+ @TestData(submittedValue = ".e10"),
+ @TestData(submittedValue = "0.1e10"),
+ @TestData(submittedValue = "0.1e-10"),
+ @TestData(submittedValue = "-0.1e-10")
+ },
+ failures = {
+ }
+ )
+
+ public void conversionTest() throws Exception {
+ setup();
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "0.9"),
+ @TestData(submittedValue = "1.1"),
+ @TestData(submittedValue = "1.2"),
+ },
+ failures = {
+ @TestData(submittedValue = "1.3"),
+ @TestData(submittedValue = "0.8"),
+ @TestData(submittedValue = "aaa")
+ }
+ )
+
+ public void minMaxTest() throws Exception {
+ setup();
+ setAttribute("maximum", 1.2);
+ setAttribute("minimum", 0.9);
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "1.2"),
+ @TestData(submittedValue = "1.3")
+ },
+ failures = {
+ @TestData(submittedValue = "1.1")
+ }
+ )
+
+ public void minTest() throws Exception {
+ setup();
+ setAttribute("minimum", 1.2);
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "1.1"),
+ @TestData(submittedValue = "0.9")
+ },
+ failures = {
+ @TestData(submittedValue = "1.2")
+ }
+ )
+
+ public void maxTest() throws Exception {
+ setup();
+ setAttribute("maximum", 1.1);
+ }
+}
Added:
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java
===================================================================
---
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java
(rev 0)
+++
branches/RF-8742-1/ui/validator/ui/src/test/java/org/richfaces/convert/LongRangeValidatorTest.java 2010-11-24
13:31:12 UTC (rev 20158)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt 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.richfaces.convert;
+
+import javax.faces.validator.LongRangeValidator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.appplication.FacesMessages;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+(a)RunWith(ValidatorTestRunner.class)
+public class LongRangeValidatorTest extends BaseTest {
+
+ private Enum<?>[] messages = { FacesMessages.LONG_RANGE_VALIDATOR_MAXIMUM,
FacesMessages.LONG_RANGE_VALIDATOR_MINIMUM,
FacesMessages.LONG_RANGE_VALIDATOR_NOT_IN_RANGE, FacesMessages.LONG_RANGE_VALIDATOR_TYPE
};
+
+ private void setup() {
+ setClientFunction("RichFaces.csv.getValidator('long-range')");
+ setObjectId(LongRangeValidator.VALIDATOR_ID);
+ setErrorMessageEnums(messages);
+ }
+
+ public LongRangeValidatorTest() {
+ super("META-INF/resources/org.richfaces/long-range-validator.js");
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "5"),
+ @TestData(submittedValue = "7"),
+ @TestData(submittedValue = "10"),
+ },
+ failures = {
+ @TestData(submittedValue = "4"),
+ @TestData(submittedValue = "11"),
+ @TestData(submittedValue = "aaa")
+ }
+ )
+
+ public void minMaxTest() throws Exception {
+ setup();
+ setAttribute("maximum", 10);
+ setAttribute("minimum", 5);
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "10"),
+ @TestData(submittedValue = "11")
+ },
+ failures = {
+ @TestData(submittedValue = "9")
+ }
+ )
+
+ public void minTest() throws Exception {
+ setup();
+ setAttribute("minimum", 10);
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "10"),
+ @TestData(submittedValue = "9")
+ },
+ failures = {
+ @TestData(submittedValue = "11")
+ }
+ )
+
+ public void maxTest() throws Exception {
+ setup();
+ setAttribute("maximum", 10);
+ }
+}