Author: alexsmirnov
Date: 2011-01-19 18:20:06 -0500 (Wed, 19 Jan 2011)
New Revision: 21102
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/csv.xml
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
Log:
CODING IN PROGRESS - issue RF-9797: CSV: make client code compatible with the current wiki
document
https://issues.jboss.org/browse/RF-9797
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-01-19
19:46:27 UTC (rev 21101)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesServiceBase.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -52,7 +52,7 @@
* @param component
* @return
*/
- protected FacesMessage getMessage(FacesContext context, T component) {
+ public FacesMessage getMessage(FacesContext context, T component) {
String messageId = getMessageId(component);
return MessageFactory.createMessage(context, messageId);
}
Modified:
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-01-19
19:46:27 UTC (rev 21101)
+++
branches/RF-9797/ui/validator/ui/src/main/java/org/richfaces/validator/FacesValidatorServiceImpl.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -38,7 +38,18 @@
// TODO: all messages should be passed to client side using js function
RichFaces.csv.addMessage
String messageId;
if (component instanceof DoubleRangeValidator) {
- messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ DoubleRangeValidator validator = (DoubleRangeValidator) component;
+ if(validator.getMaximum() >0){
+ if(validator.getMinimum()>0){
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.MAXIMUM_MESSAGE_ID;
+ }
+ } else if( validator.getMinimum()>0){
+ messageId = DoubleRangeValidator.MINIMUM_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
+ }
} else if (component instanceof LengthValidator) {
LengthValidator validator = (LengthValidator) component;
if(validator.getMaximum() >0){
@@ -53,7 +64,18 @@
messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
}
} else if (component instanceof LongRangeValidator) {
- messageId = LongRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ LongRangeValidator validator = (LongRangeValidator) component;
+ if(validator.getMaximum() >0){
+ if(validator.getMinimum()>0){
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;
+ } else {
+ messageId = LongRangeValidator.MAXIMUM_MESSAGE_ID;
+ }
+ } else if( validator.getMinimum()>0){
+ messageId = LongRangeValidator.MINIMUM_MESSAGE_ID;
+ } else {
+ messageId = DoubleRangeValidator.NOT_IN_RANGE_MESSAGE_ID;// What to use
for that case ( no min/max set, validator always pass ).
+ }
} else if (component instanceof RegexValidator) {
messageId = RegexValidator.NOT_MATCHED_MESSAGE_ID;
} else if (component instanceof RequiredValidator) {
Modified: branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/csv.xml
===================================================================
--- branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-01-19
19:46:27 UTC (rev 21101)
+++ branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/csv.xml 2011-01-19
23:20:06 UTC (rev 21102)
@@ -9,6 +9,30 @@
<function>RichFaces.csv.convertNumber</function>
</component>
<component>
+ <type>javax.faces.convert.BooleanConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertBoolean</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.ByteConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertByte</function>
+ </component>
+ <component>
+ <type>javax.faces.convert.ShortConverter</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.convertShort</function>
+ </component>
+ <component>
<type>javax.faces.validator.LengthValidator</type>
<resource>
<name>csv.reslib</name>
@@ -16,4 +40,76 @@
</resource>
<function>RichFaces.csv.validateLength</function>
</component>
+ <component>
+ <type>javax.faces.validator.LongRangeValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateLongRange</function>
+ </component>
+ <component>
+ <type>javax.faces.validator.DoubleRangeValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateDoubleRange</function>
+ </component>
+ <component>
+ <type>javax.faces.validator.RegexValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateRegex</function>
+ </component>
+ <component>
+ <type>javax.faces.validator.RequiredValidator</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateRequired</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.NotNull</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateRequired</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Size</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateSize</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Pattern</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validatePattern</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Min</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateMin</function>
+ </component>
+ <component>
+ <type>javax.validation.constraints.Max</type>
+ <resource>
+ <name>csv.reslib</name>
+ <library>org.richfaces</library>
+ </resource>
+ <function>RichFaces.csv.validateMax</function>
+ </component>
</scripts>
\ No newline at end of file
Modified:
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-19
19:46:27 UTC (rev 21101)
+++
branches/RF-9797/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2011-01-19
23:20:06 UTC (rev 21102)
@@ -6,7 +6,7 @@
var _validators = {};
var _converters = {};
- var RE_MESSAGE_PATTERN = /\{(\d+)\}/g;
+ var RE_MESSAGE_PATTERN = /\'?\{(\d+)\}\'?/g;
var __interpolateMessage = function (message, values) {
if (message) {
@@ -135,14 +135,14 @@
"convertByte": function (value,label,params,msg) {
var result; value = $.trim(value);
if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-128 ||
result>127) {
- throw rf.csv.getMessage(msg, 'BYTE_CONVERTER_BYTE', [value, 0,
params.componentId]);
+ throw rf.csv.interpolateMessage(msg, [value, 254, label]);
}
return result;
},
"convertNumber": function (value,label,params,msg) {
var result; value=$.trim(value);
if (isNaN(value)) {
- throw rf.csv.getMessage(msg, 'NUMBER_CONVERTER_NUMBER', [value, 0,
params.componentId]);
+ throw rf.csv.interpolateMessage(msg, [value, 0, label]);
} else {
result = parseInt(value, 10);
}
@@ -151,12 +151,40 @@
"convertShort": function (value,label,params,msg) {
var result; value = $.trim(value);
if (!rf.csv.RE_DIGITS.test(value) || (result=parseInt(value,10))<-32768 ||
result>32767) {
- throw rf.csv.getMessage(msg, 'SHORT_CONVERTER_SHORT', [value, 0,
params.componentId]);
+ throw rf.csv.interpolateMessage(msg, [value, 0, label]);
}
return result;
}
});
+ var validateRange = function(value,label,params,msg) {
+ var isMinSet = typeof params.minimum == "number" ;//&& params.minimum
>0;
+ var isMaxSet = typeof params.maximum == "number" ;//&& params.maximum
>0;
+
+ if (isMaxSet && value > params.maximum) {
+ throw
rf.csv.interpolateMessage(msg,isMinSet?[params.minimum,params.maximum,label]:[params.maximum,label]);
+ }
+ if (isMinSet && value < params.minimum) {
+ throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.minimum,params.maximum,label]:[params.minimum,label]);
+ }
+ };
+
+ var validateRegex = function(value,label,pattern,msg) {
+ if (typeof pattern != "string" || pattern.length == 0) {
+ throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
+ }
+
+ var re;
+ try {
+ re = new RegExp(pattern);
+ } catch (e) {
+ throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
+ }
+ if (!re.test(value)){
+ throw rf.csv.interpolateMessage(msg, [pattern,label]);
+ }
+
+ }
/*
* Validators implementation
*/
@@ -174,23 +202,7 @@
}
}
- var isMinSet = typeof params.minimum == "number";
- var isMaxSet = typeof params.maximum == "number";
-
- if (isMaxSet && value > params.maximum) {
- if (isMinSet) {
- throw rf.csv.getMessage(msg,
'LONG_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
- } else {
- throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
- }
- }
- if (isMinSet && value < params.minimum) {
- if (isMaxSet) {
- throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_NOT_IN_RANGE',
[params.minimum, params.maximum, componentId]);
- } else {
- throw rf.csv.getMessage(msg, 'LONG_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
- }
- }
+ validateRange(value,label,params,msg);
},
"validateDoubleRange": function (value,label,params,msg) {
var type = typeof value;
@@ -205,54 +217,36 @@
}
}
- var isMinSet = typeof params.minimum == "number";
- var isMaxSet = typeof params.maximum == "number";
-
- if (isMaxSet && value > params.maximum) {
- if (isMinSet) {
- throw rf.csv.getMessage(msg,
'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE', [params.minimum, params.maximum,
componentId]);
- } else {
- throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
- }
- }
- if (isMinSet && value < params.minimum) {
- if (isMaxSet) {
- throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_NOT_IN_RANGE',
[params.minimum, params.maximum, componentId]);
- } else {
- throw rf.csv.getMessage(msg, 'DOUBLE_RANGE_VALIDATOR_MINIMUM',
[params.minimum, componentId]);
- }
- }
+ validateRange(value,label,params,msg);
},
"validateLength": function (value,label,params,msg) {
- var isMinSet = typeof params.minimum == "number" && params.minimum
>0;
- var isMaxSet = typeof params.maximum == "number" && params.maximum
>0;
-
- if (isMaxSet && value.length > params.maximum) {
- throw
rf.csv.interpolateMessage(msg,isMinSet?[params.minimum,params.maximum,label]:[params.maximum,label]);
- }
- if (isMinSet && value.length < params.minimum) {
- throw
rf.csv.interpolateMessage(msg,isMaxSet?[params.minimum,params.maximum,label]:[params.minimum,label]);
- }
+ var length = value?value.length:0;
+ validateRange(length,label,params,msg);
},
+ "validateSize": function (value,label,params,msg) {
+ var length = value?value.length:0;
+ validateRange(length,label,{maximum:params.max,minimum:params.min},msg);
+ },
"validateRegex": function (value,label,params,msg) {
- if (typeof params.pattern != "string" || params.pattern.length == 0) {
- throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_PATTERN_NOT_SET', []);
- }
-
- var re;
- try {
- re = new RegExp(params.pattern);
- } catch (e) {
- throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_MATCH_EXCEPTION', []);
- }
- if (!re.test(value)){
- throw rf.csv.getMessage(msg, 'REGEX_VALIDATOR_NOT_MATCHED',
[params.pattern]);
- }
+ validateRegex(value,label,params.pattern,msg);
},
+ "validatePattern": function (value,label,params,msg) {
+ validateRegex(value,label,params.regexp,msg);
+ },
"validateRequired": function (value,label,params,msg) {
- if (value.length==0) {
- throw rf.csv.getMessage(msg, 'UIINPUT_REQUIRED', [componentId]);
+ if (!value ) {
+ throw rf.csv.interpolateMessage(msg, [label]);
}
+ },
+ "validateMax": function (value,label,params,msg) {
+ if (value > params.value ) {
+ throw msg;
+ }
+ },
+ "validateMin": function (value,label,params,msg) {
+ if (value < params.value ) {
+ throw msg;
+ }
}
});
Modified:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-01-19
19:46:27 UTC (rev 21101)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/MockTestBase.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -1,9 +1,14 @@
package org.richfaces.javascript.client;
+import static org.easymock.EasyMock.expect;
+
+import java.util.Collections;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
import org.jboss.test.faces.mock.MockFacesEnvironment;
import org.jboss.test.qunit.Qunit;
@@ -20,6 +25,8 @@
@RunWith(Parameterized.class)
public abstract class MockTestBase {
+ protected static final String TEST_COMPONENT_ID = "testComponent";
+
@Rule
public final Qunit qunit;
@@ -41,8 +48,11 @@
}
protected void recordMocks() {
- // template method to record mock objects
-
+ UIViewRoot viewRoot = facesEnvironment.createMock(UIViewRoot.class);
+ expect(viewRoot.getLocale()).andStubReturn(Locale.ENGLISH);
+
expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(viewRoot);
+ expect(component.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
+
expect(component.getClientId(facesEnvironment.getFacesContext())).andStubReturn(TEST_COMPONENT_ID);
}
@After
@@ -62,11 +72,16 @@
protected org.jboss.test.qunit.Qunit.Builder createQunitPage() {
return
Qunit.builder().loadJsfResource("jquery.js").loadJsfResource("richfaces.js")
-
.loadJsfResource("richfaces-event.js").loadJsfResource("csv.js",
"org.richfaces");
+
.loadJsfResource("richfaces-event.js").loadJsfResource("richfaces-csv.js",
"org.richfaces");
}
protected abstract String getJavaScriptFunctionName();
+ protected Map<String, Object> getOptions() {
+ Map<String, Object> options = criteria.getOptions();
+ return options;
+ }
+
protected static List<RunParameters[]> options(RunParameters ...criterias){
Builder<RunParameters[]> builder = ImmutableList.builder();
for (RunParameters testCriteria : criterias) {
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,45 @@
+package org.richfaces.javascript.client.converter;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.List;
+
+import javax.faces.convert.BooleanConverter;
+import javax.faces.convert.ByteConverter;
+import javax.faces.convert.Converter;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+public class ByteConverterTest extends ConverterTestBase {
+
+ public ByteConverterTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Override
+ protected Converter createConverter() {
+ ByteConverter byteConverter = new ByteConverter();
+ return byteConverter;
+ }
+
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "convertByte";
+ }
+
+ @Override
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ assertTrue(jsConvertedValue instanceof Double);
+ assertTrue(convertedValue instanceof Byte);
+ Double jsDouble = (Double) jsConvertedValue;
+ Double jsfDouble = new Double((Byte)convertedValue);
+ assertEquals(jsfDouble, jsDouble,0.0000001);
+ }
+
+ @Parameters
+ public static List<RunParameters[]> getRunParameterss() {
+ return options(pass("true"), pass("ok"),
pass("123"),pass("0"),pass("1"),pass("255"),pass("-128"),pass("-129"),pass("256"),pass("-0"),pass("0.05"));
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ByteConverterTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-01-19
19:46:27 UTC (rev 21101)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ConverterTestBase.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -1,16 +1,27 @@
package org.richfaces.javascript.client.converter;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.*;
+import javax.faces.application.FacesMessage;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
+import javax.faces.validator.Validator;
+import net.sourceforge.htmlunit.corejs.javascript.JavaScriptException;
+import net.sourceforge.htmlunit.corejs.javascript.NativeObject;
+
import org.ajax4jsf.javascript.JSFunction;
import org.junit.Test;
+import org.richfaces.javascript.Message;
import org.richfaces.javascript.client.MockTestBase;
import org.richfaces.javascript.client.RunParameters;
+import org.richfaces.validator.ConverterServiceImpl;
+import com.gargoylesoftware.htmlunit.ScriptException;
+
public abstract class ConverterTestBase extends MockTestBase {
public ConverterTestBase(RunParameters criteria) {
@@ -24,24 +35,49 @@
Object convertedValue =
converter.getAsObject(facesEnvironment.getFacesContext(), component,
criteria.getValue().toString());
Object jsConvertedValue =
- convertOnClient();
- assertEquals(convertedValue, jsConvertedValue);
+ convertOnClient(converter);
+ if(null != convertedValue || null != jsConvertedValue){
+ compareResult(convertedValue, jsConvertedValue);
+ }
} catch (ConverterException e) {
// JSF conversion error - JavaScript should throw exception too.
try {
- convertOnClient();
+ convertOnClient(converter);
assertFalse("Client-side converted didn't throw exception for
value:"+criteria.getValue(), true);
- } catch (Exception jsException){
+ } catch (ScriptException jsException){
// Test passed
+ Throwable cause = jsException.getCause();
+ assertTrue(cause instanceof JavaScriptException);
+ NativeObject value = (NativeObject) ((JavaScriptException)
cause).getValue();
+ assertEquals(e.getFacesMessage().getDetail(),
value.get("detail"));
+ assertEquals(e.getFacesMessage().getSummary(),
value.get("summary"));
}
}
}
- protected Object convertOnClient() throws ConverterException {
- JSFunction clientSideFunction = new JSFunction("RichFaces.csv." +
getJavaScriptFunctionName(),criteria.getValue(),getErrorMessage(),getJavaScriptOptions());
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ assertEquals(convertedValue, jsConvertedValue);
+ }
+
+ protected Object convertOnClient(Converter converter) throws ConverterException {
+ JSFunction clientSideFunction = new JSFunction("RichFaces.csv." +
getJavaScriptFunctionName(),criteria.getValue(),TEST_COMPONENT_ID,getJavaScriptOptions(),
getErrorMessage(converter));
return qunit.runScript(clientSideFunction.toScript());
}
+ private Object getErrorMessage(Converter converter) {
+ ConverterServiceImpl converterService = new ConverterServiceImpl();
+ FacesMessage message =
converterService.getMessage(facesEnvironment.getFacesContext(), converter);
+ return new Message(message);
+ }
+
protected abstract Converter createConverter();
+ protected void compareNumbers(Object convertedValue, Object jsConvertedValue) {
+ assertTrue(jsConvertedValue instanceof Double);
+ assertTrue(convertedValue instanceof Number);
+ Double jsDouble = (Double) jsConvertedValue;
+ Double jsfDouble = Double.valueOf(((Number)convertedValue).doubleValue());
+ assertEquals(jsfDouble, jsDouble,0.0000001);
+ }
+
}
\ No newline at end of file
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,46 @@
+package org.richfaces.javascript.client.converter;
+
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.convert.BooleanConverter;
+import javax.faces.convert.NumberConverter;
+import javax.faces.convert.Converter;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+public class NumberConverterTest extends ConverterTestBase {
+
+ private static final String TYPE = "type";
+
+ public NumberConverterTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Override
+ protected Converter createConverter() {
+ NumberConverter converter = new NumberConverter();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(TYPE)){
+ converter.setType((String) options.get(TYPE));
+ }
+ return converter;
+ }
+
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "convertNumber";
+ }
+
+ @Override
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ compareNumbers(convertedValue, jsConvertedValue);
+ }
+
+ @Parameters
+ public static List<RunParameters[]> getRunParameterss() {
+ return options(pass("true"),
pass("123"),pass("0"),pass("1"),pass("255"),pass("-128"),pass("-129"),pass("256"),pass("-0"),pass("0.05"));
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/NumberConverterTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,41 @@
+package org.richfaces.javascript.client.converter;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.List;
+
+import javax.faces.convert.BooleanConverter;
+import javax.faces.convert.ShortConverter;
+import javax.faces.convert.Converter;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+public class ShortConverterTest extends ConverterTestBase {
+
+ public ShortConverterTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Override
+ protected Converter createConverter() {
+ ShortConverter byteConverter = new ShortConverter();
+ return byteConverter;
+ }
+
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "convertShort";
+ }
+
+ @Override
+ protected void compareResult(Object convertedValue, Object jsConvertedValue) {
+ compareNumbers(convertedValue, jsConvertedValue);
+ }
+
+ @Parameters
+ public static List<RunParameters[]> getRunParameterss() {
+ return options(pass("true"),
pass("123"),pass("0"),pass("1"),pass(Long.toString(Long.MAX_VALUE)),pass(Short.toString(Short.MIN_VALUE)),pass(Short.toString(Short.MAX_VALUE)),pass("-129"),pass("256"),pass("-0"),pass("0.05"));
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/converter/ShortConverterTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,56 @@
+package org.richfaces.javascript.client.validator;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
+import javax.validation.Validation;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+
+import net.sourceforge.htmlunit.corejs.javascript.JavaScriptException;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.junit.Test;
+import org.richfaces.javascript.client.MockTestBase;
+import org.richfaces.javascript.client.RunParameters;
+
+import com.gargoylesoftware.htmlunit.ScriptException;
+
+public abstract class BeanValidatorTestBase extends MockTestBase {
+
+ protected static final String PROP = "property";
+
+ public BeanValidatorTestBase(RunParameters criteria) {
+ super(criteria);
+ }
+
+ @Test
+ public void testValidator() throws Exception {
+ Validator validator = createValidator();
+ Set<?> constrains = validator.validateValue(getBeanType(), (String)
getOptions()
+ .get(PROP), criteria.getValue());
+ try {
+ validateOnClient(validator);
+ assertTrue("Bean validator found error for value: " +
criteria.getValue() + ", validator options: "
+ + getOptions(), constrains.isEmpty());
+ } catch (ScriptException e2) {
+ // both methods throws exceptions - it's ok.
+ Throwable cause = e2.getCause();
+ assertTrue(cause instanceof JavaScriptException);
+ }
+ }
+
+ protected abstract Class<?> getBeanType();
+
+ protected Object validateOnClient(Validator validator) throws ValidationException {
+ JSFunction clientSideFunction = new JSFunction("RichFaces.csv." +
getJavaScriptFunctionName(),
+ criteria.getValue(), TEST_COMPONENT_ID, getJavaScriptOptions(),
getErrorMessage());
+ return qunit.runScript(clientSideFunction.toScript());
+ }
+
+ protected Validator createValidator() {
+ return Validation.buildDefaultValidatorFactory().usingContext().getValidator();
+ }
+
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/BeanValidatorTestBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,61 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.DoubleRangeValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class DoubleRangeValidatorTest extends ValidatorTestBase {
+
+ private static final String MINIMUM = "minimum";
+ private static final String MAXIMUM = "maximum";
+ /**
+ * @param criteria
+ */
+ public DoubleRangeValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ DoubleRangeValidator validator = new DoubleRangeValidator();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(MINIMUM)){
+ validator.setMinimum((Double) options.get(MINIMUM));
+ }
+ if(options.containsKey(MAXIMUM)){
+ validator.setMaximum((Double) options.get(MAXIMUM));
+ }
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateDoubleRange";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(pass(0L),pass(3L),pass(Double.MAX_VALUE),
+
pass(0.0D,MINIMUM,2.0D),pass(2.0D,MINIMUM,2.0D),pass(3.0D,MINIMUM,2.0D),pass(-3.0D,MINIMUM,2.0D),
+
pass(0.0D,MAXIMUM,2.0D),pass(2.0D,MAXIMUM,2.0D),pass(3.0D,MAXIMUM,2.0D),pass(-3.0D,MAXIMUM,2.0D),
+
pass(0.0D,MINIMUM,3.0D,MAXIMUM,5.0D),pass(3.0D,MINIMUM,3.0D,MAXIMUM,5.0D),pass(4.0D,MINIMUM,3.0D,MAXIMUM,5.0D),pass(7.0D,MINIMUM,3.0D,MAXIMUM,5.0D));
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/DoubleRangeValidatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-01-19
19:46:27 UTC (rev 21101)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LengthValidatorTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -33,7 +33,7 @@
@Override
protected Validator createValidator() {
LengthValidator validator = new LengthValidator();
- Map<String, Object> options = criteria.getOptions();
+ Map<String, Object> options = getOptions();
if(options.containsKey(MINIMUM)){
validator.setMinimum((Integer) options.get(MINIMUM));
}
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,61 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.LongRangeValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class LongRangeValidatorTest extends ValidatorTestBase {
+
+ private static final String MINIMUM = "minimum";
+ private static final String MAXIMUM = "maximum";
+ /**
+ * @param criteria
+ */
+ public LongRangeValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ LongRangeValidator validator = new LongRangeValidator();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(MINIMUM)){
+ validator.setMinimum((Long) options.get(MINIMUM));
+ }
+ if(options.containsKey(MAXIMUM)){
+ validator.setMaximum((Long) options.get(MAXIMUM));
+ }
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateLongRange";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(pass(0L),pass(3L),pass(Long.MAX_VALUE),
+
pass(0L,MINIMUM,2L),pass(2L,MINIMUM,2L),pass(3L,MINIMUM,2L),pass(-3L,MINIMUM,2L),
+
pass(0L,MAXIMUM,2L),pass(2L,MAXIMUM,2L),pass(3L,MAXIMUM,2L),pass(-3L,MAXIMUM,2L),
+
pass(0L,MINIMUM,3L,MAXIMUM,5L),pass(3L,MINIMUM,3L,MAXIMUM,5L),pass(4L,MINIMUM,3L,MAXIMUM,5L),pass(7L,MINIMUM,3L,MAXIMUM,5L));
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/LongRangeValidatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,59 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.LengthValidator;
+import javax.faces.validator.Validator;
+import javax.validation.constraints.Max;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class MaxValidatorTest extends BeanValidatorTestBase {
+
+ private static final String MAXIMUM = "value";
+ /**
+ * @param criteria
+ */
+ public MaxValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateMax";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(
+
pass(0,PROP,"number",MAXIMUM,2),pass(2,PROP,"number",MAXIMUM,2),pass(123,PROP,"number",MAXIMUM,2)
+ );
+ }
+
+ public static final class Bean {
+
+ @Max(2)
+ public int getNumber() {
+ return 0;
+ }
+
+ }
+
+ @Override
+ protected Class<?> getBeanType() {
+ return Bean.class;
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/MaxValidatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,56 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.RegexValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class RegexValidatorTest extends ValidatorTestBase {
+
+ private static final String PATTERN = "pattern";
+ /**
+ * @param criteria
+ */
+ public RegexValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ RegexValidator validator = new RegexValidator();
+ Map<String, Object> options = getOptions();
+ if(options.containsKey(PATTERN)){
+ validator.setPattern((String) options.get(PATTERN));
+ }
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateRegex";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(pass(""),pass("aaa"),pass("123"),
+
pass("",PATTERN,".*"),pass("vv",PATTERN,"\\S*"),pass("123",PATTERN,"\\d+")
+ );
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RegexValidatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java
(rev 0)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -0,0 +1,52 @@
+/**
+ *
+ */
+package org.richfaces.javascript.client.validator;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.validator.RequiredValidator;
+import javax.faces.validator.Validator;
+
+import org.junit.runners.Parameterized.Parameters;
+import org.richfaces.javascript.client.RunParameters;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class RequiredValidatorTest extends ValidatorTestBase {
+
+ /**
+ * @param criteria
+ */
+ public RequiredValidatorTest(RunParameters criteria) {
+ super(criteria);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.richfaces.javascript.client.validator.ValidatorTestBase#createValidator()
+ */
+ @Override
+ protected Validator createValidator() {
+ RequiredValidator validator = new RequiredValidator();
+ Map<String, Object> options = getOptions();
+ return validator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.javascript.client.MockTestBase#getJavaScriptFunctionName()
+ */
+ @Override
+ protected String getJavaScriptFunctionName() {
+ return "validateRequired";
+ }
+
+ @Parameters
+ public static List<RunParameters[]> parameters() {
+ return options(pass(""),pass("aaa"),pass("123"),
+ pass(null)
+ );
+ }
+}
Property changes on:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/RequiredValidatorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified:
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java
===================================================================
---
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-01-19
19:46:27 UTC (rev 21101)
+++
branches/RF-9797/ui/validator/ui/src/test/java/org/richfaces/javascript/client/validator/ValidatorTestBase.java 2011-01-19
23:20:06 UTC (rev 21102)
@@ -5,6 +5,7 @@
import java.util.Collections;
+import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
@@ -17,12 +18,15 @@
import org.ajax4jsf.javascript.JSFunction;
import org.junit.Test;
+import org.richfaces.javascript.Message;
import org.richfaces.javascript.client.MockTestBase;
import org.richfaces.javascript.client.RunParameters;
+import org.richfaces.validator.FacesValidatorServiceImpl;
import com.gargoylesoftware.htmlunit.ScriptException;
public abstract class ValidatorTestBase extends MockTestBase {
+
private static final Converter NUMBER_CONVERTER = new Converter() {
@@ -45,38 +49,42 @@
Validator validator = createValidator();
try {
validator.validate(facesEnvironment.getFacesContext(), component,
criteria.getValue());
- validateOnClient();
+ validateOnClient(validator);
} catch (ValidatorException e) {
// client-side script has to throw exception too.
try {
- validateOnClient();
- assertFalse("JSF validator throws exception for value: " +
criteria.getValue(), true);
+ validateOnClient(validator);
+ assertFalse("JSF validator throws exception for value: " +
criteria.getValue()+ ", validator options: "+getOptions(), true);
} catch (ScriptException e2) {
// both methods throws exceptions - it's ok.
- e2.printStackTrace();
Throwable cause = e2.getCause();
assertTrue(cause instanceof JavaScriptException);
NativeObject value = (NativeObject) ((JavaScriptException)
cause).getValue();
- assertEquals(getErrorMessage().getDetail(),
value.get("detail"));
+ assertEquals(e.getFacesMessage().getDetail(),
value.get("detail"));
+ assertEquals(e.getFacesMessage().getSummary(),
value.get("summary"));
}
}
}
- protected Object validateOnClient() throws ValidationException {
+ protected Object validateOnClient(Validator validator) throws ValidationException {
JSFunction clientSideFunction =
- new JSFunction("RichFaces.csv." + getJavaScriptFunctionName(),
criteria.getValue(), getErrorMessage(),
- getJavaScriptOptions());
+ new JSFunction("RichFaces.csv." + getJavaScriptFunctionName(),
criteria.getValue(), TEST_COMPONENT_ID,
+ getJavaScriptOptions(),getErrorMessage(validator));
return qunit.runScript(clientSideFunction.toScript());
}
+ private Object getErrorMessage(Validator validator) {
+ FacesValidatorServiceImpl validatorService = new FacesValidatorServiceImpl();
+ FacesMessage message =
validatorService.getMessage(facesEnvironment.getFacesContext(), validator);
+ return new Message(message);
+ }
+
protected abstract Validator createValidator();
@Override
protected void recordMocks() {
super.recordMocks();
- expect(component.getAttributes()).andStubReturn(Collections.EMPTY_MAP);
-
expect(component.getClientId(facesEnvironment.getFacesContext())).andStubReturn("testComponent");
expect(facesEnvironment.getApplication().createConverter("javax.faces.Number")).andStubReturn(NUMBER_CONVERTER);
}
}