Author: pyaschenko
Date: 2010-11-01 08:14:59 -0400 (Mon, 01 Nov 2010)
New Revision: 19817
Added:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length-validator.js
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTestRunner.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ConverterTestRunner.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/LengthValidatorTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ValidatorTestRunner.java
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testConverter.xhtml
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testValidator.xhtml
Removed:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length.js
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/validator-length.js
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTestRunner.java
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/test.xhtml
Modified:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/DateTimeConverterTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/NumberConverterTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestData.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
Log:
http://jira.jboss.com/jira/browse/RF-9521
http://jira.jboss.com/jira/browse/RF-9329
http://jira.jboss.com/jira/browse/RF-9215
Copied:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length-validator.js
(from rev 19811,
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length.js)
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length-validator.js
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length-validator.js 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,12 @@
+RichFaces.csv.addValidator({"length":
+ (function(rf) {
+ return function (componentId, value, params) {
+ if (params.maximum && value.length > params.maximum) {
+ throw rf.csv.getMessage(params.customMessage, 'LENGTH_VALIDATOR_MAXIMUM',
[params.maximum, componentId]);
+ }
+ if (params.minimum && value.length < params.minimum) {
+ throw rf.csv.getMessage(params.customMessage, 'LENGTH_VALIDATOR_MINIMUM',
[params.maximum, componentId]);
+ }
+ }
+ })(window.RichFaces || (window.RichFaces={}))
+});
\ No newline at end of file
Deleted:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length.js 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/length.js 2010-11-01
12:14:59 UTC (rev 19817)
@@ -1,78 +0,0 @@
-(function($, rf) {
-
- rf.csv = rf.csv || {};
-
- var _messages = {};
- var _validators = {};
- var _converters = {};
-
- var RE_MESSAGE_PATTERN = /\{(\d+)\}/g;
-
- $.extend(rf.csv, {
- // Messages API
- addMessage: function (messagesObject) {
- $.extend(_messages, messagesObject);
- },
- getMessage: function(customMessages, id, values) {
- var message = (customMessages && customMessages[id]) || _messages[id] ||
"";
- if (message) {
- var msgObject =
message.replace(RE_MESSAGE_PATTERN,"\n$1\n").split("\n");
- var value;
- for (var i=1; i<msgObject.length; i+=2) {
- value = values[msgObject[i]];
- msgObject[i] = typeof value == "undefined" ? "" : value;
- }
- message = msgObject.join('');
- }
- return message;
- },
- // Validators API
- addValidator: function (validatorFunctions) {
- $.extend(_validators, validatorFunctions);
- },
- validate: function (event, id, validatorList, messageComponentList, options) {
- var value;
- var element = rf.getDomElement(id);
- if (element.value) {
- value = element.value;
- } else {
- var component = rf.$(element);
- value = component && typeof component["getValue"] ==
"function" ? component.getValue() : "";
- }
- var result;
- var messageComponentsUpdated = false;
- var validatorFunction;
- for (var validator in validatorList) {
- validatorFunction = _validators[validator];
- if (validatorFunction) {
- result = validatorFunction(value, validatorList[validator]);
- }
- if (result && result.length>0) {
- messageComponentsUpdated = true;
- //updateMessageComponents(messageElementIds, result);
- alert(result);
- break;
- }
- }
- !messageComponentsUpdated && alert("no message from
validators");//updateMessageComponents(messageElementIds, "");
- },
- addFormValidators: function (formId, callValidatorFunctions) {
-
- }
- });
-})(jQuery, window.RichFaces || (window.RichFaces={}));
-
-
-RichFaces.csv.addValidator({"length":
-(function(rf) {
- return function (value, params) {
- var result = "";
- if (value.length<params.min) {
- result = rf.csv.getMessage(params.customMessages, 'LengthValidator.MINIMUM',
[params.min,value]);
- } else if (value.length>params.max){
- result = rf.csv.getMessage(params.customMessages, 'LengthValidator.MAXIMUM',
[params.max,value]);
- }
- return result;
- }
-})(window.RichFaces || (window.RichFaces={}))
-});
\ No newline at end of file
Modified:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/richfaces-csv.js 2010-11-01
12:14:59 UTC (rev 19817)
@@ -26,7 +26,7 @@
}
message = msgObject.join('');
}
- return message;
+ return {message:message};
},
sendMessage: function (componentId, message) {
rf.Event.fireById(document, MESSAGE_EVENT_NAME, message);
@@ -43,7 +43,10 @@
addValidator: function (validatorFunctions) {
$.extend(_validators, validatorFunctions);
},
- validate: function (event, id, converter, validatorList) {
+ getValidator: function (name) {
+ return _validators[name];
+ },
+ validate: function (event, id, converter, validators) {
var value;
var element = rf.getDomElement(id);
if (element.value) {
@@ -58,20 +61,21 @@
converter.options.componentId = id;
value = getConverter([converter.name])(value, converter.options);
} catch (e){
- sendMessage(id, e);
+ sendMessage(id, e.message);
return false;
}
}
- if (!validatorList) return true;
- var validatorFunction;
- var result;
- for (var validator in validatorList) {
- validatorFunction = _validators[validator];
- if (validatorFunction) {
- result = validatorFunction(value, validatorList[validator]);
- }
- if (result && result.length>0) {
- sendMessage(id, id+":"+result);
+ if (validators) {
+ var validatorFunction;
+ try {
+ for (i=0;i<validators.length;i++) {
+ validatorFunction = getValidator(validators[i].type);
+ if (validatorFunction) {
+ validatorFunction(id, value, validators[i]);
+ }
+ }
+ } catch (e) {
+ sendMessage(id, result);
return false;
}
}
Deleted:
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/validator-length.js
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/validator-length.js 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/main/resources/META-INF/resources/org.richfaces/validator-length.js 2010-11-01
12:14:59 UTC (rev 19817)
@@ -1,13 +0,0 @@
-RichFaces.csv.addValidator({"length":
-(function(rf) {
- return function (value, params) {
- var result = "";
- if (value.length<params.min) {
- result = rf.csv.getMessage(params.customMessages, 'LengthValidator.MINIMUM',
[params.min,value]);
- } else if (value.length>params.max){
- result = rf.csv.getMessage(params.customMessages, 'LengthValidator.MAXIMUM',
[params.max,value]);
- }
- return result;
- }
-})(window.RichFaces || (window.RichFaces={}))
-});
\ No newline at end of file
Deleted:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTest.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -1,334 +0,0 @@
-/*
- * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.text.MessageFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TimeZone;
-
-import javax.el.ExpressionFactory;
-import javax.el.ValueExpression;
-import javax.el.VariableMapper;
-import javax.faces.component.UIComponent;
-import javax.faces.component.html.HtmlInputText;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.servlet.ServletRequestEvent;
-import javax.servlet.ServletRequestListener;
-
-import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
-
-import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.javascript.ScriptUtils;
-import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
-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;
-
-import com.gargoylesoftware.htmlunit.ScriptResult;
-import com.gargoylesoftware.htmlunit.html.HtmlPage;
-import com.google.common.base.Strings;
-
-/**
- * @author Nick Belaevski
- *
- */
-(a)RunWith(BaseConverterTestRunner.class)
-public abstract class BaseConverterTest {
-
- public static final String TEST_COMPONENT_LABEL = "input";
-
- public class TestBean {
-
- private static final String CONVERTER_VAR = "__converter";
-
- private String converterId;
-
- private String clientConverterClassName;
-
- private String convertedValueAsScript;
-
- private String conversionErrorMessage;
-
- private Enum<?> conversionErrorMessageEnum;
-
- private ConverterException converterException;
-
- private Map<String, Object> attributes = new HashMap<String, Object>();
-
- private String converterParametersString;
-
- public void setClientConverterClassName(String clientConverterClassName) {
- this.clientConverterClassName = clientConverterClassName;
- }
-
- public String getClientConverterClassName() {
- return clientConverterClassName;
- }
-
- public void setConverterId(String converterId) {
- this.converterId = converterId;
- }
-
- public String getSubmittedValue() {
- return submittedValue;
- }
-
- public String getSubmittedValueAsScript() {
- return ScriptUtils.toScript(submittedValue);
- }
-
- public String getConversionErrorMessage() {
- return conversionErrorMessage;
- }
-
- public void setConversionErrorMessage(String conversionErrorMessage) {
- this.conversionErrorMessage = conversionErrorMessage;
- }
-
- public void setAttribute(String name, Object value) {
- attributes.put(name, value);
- }
-
- public String getConverterParametersString() {
- return converterParametersString;
- }
-
- public ConverterException getConverterException() {
- return converterException;
- }
-
- public void setConversionErrorMessageEnum(
- Enum<?> conversionErrorMessageEnum) {
- this.conversionErrorMessageEnum = conversionErrorMessageEnum;
- }
-
- private void configure(FacesContext facesContext, Converter converter) {
- ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
-
- VariableMapper varMapper = facesContext.getELContext().getVariableMapper();
- ValueExpression originalExpr = varMapper.resolveVariable(CONVERTER_VAR);
- try {
- varMapper.setVariable(CONVERTER_VAR,
expressionFactory.createValueExpression(converter, Converter.class));
-
- for (Entry<String, Object> mapEntry: attributes.entrySet()) {
-
- String exprString = MessageFormat.format("#'{'{0}.{1}'}'",
CONVERTER_VAR, mapEntry.getKey());
- ValueExpression ve =
expressionFactory.createValueExpression(facesContext.getELContext(), exprString,
Object.class);
-
- ve.setValue(facesContext.getELContext(), mapEntry.getValue());
- }
- } finally {
- varMapper.setVariable(CONVERTER_VAR, originalExpr);
- }
- }
-
- private Converter createConverter(FacesContext facesContext) {
- Converter converter = facesContext.getApplication().createConverter(converterId);
- configure(facesContext, converter);
- return converter;
- }
-
- private UIComponent createTestComponent() {
- HtmlInputText testComponent = new HtmlInputText();
- testComponent.setLabel(TEST_COMPONENT_LABEL);
- return testComponent;
- }
-
- public String getConvertedValueAsScript() {
- return convertedValueAsScript != null ? convertedValueAsScript : "null";
- }
-
- public void init() {
- if (converterId == null || clientConverterClassName == null) {
- throw new NullPointerException();
- }
-
- FacesContext facesContext = FacesContext.getCurrentInstance();
- Converter converter = createConverter(facesContext);
- try {
- Object convertedObject = converter.getAsObject(facesContext, createTestComponent(),
submittedValue);
- convertedValueAsScript = serializeObjectToScript(convertedObject);
- } catch (ConverterException e) {
- this.converterException = e;
- }
-
- if (Strings.isNullOrEmpty(conversionErrorMessage) &&
conversionErrorMessageEnum != null) {
- MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
- conversionErrorMessage = messageFactory.getMessageFormat(facesContext,
conversionErrorMessageEnum);
- }
-
- Map<String,Object> map = new HashMap<String, Object>(attributes);
- map.put("componentId", TEST_COMPONENT_LABEL);
- map.put("customMessage", MessageFormat.format(conversionErrorMessage ,
"{0}"));
-
- converterParametersString = ScriptUtils.toScript(map);
- }
- }
-
- private TestBean testBean;
-
- private HtmlUnitEnvironment environment;
-
- private String converterScriptName;
-
- private String submittedValue;
-
- private String failureMessage;
-
- public BaseConverterTest(String converterScriptName) {
- this.converterScriptName = converterScriptName;
- }
-
- @Before
- public void setUp() throws Exception {
- testBean = new TestBean();
-
- environment = new HtmlUnitEnvironment(new JettyServer());
- environment.getServer().addResource("/test.xhtml",
BaseConverterTest.class.getResource("test.xhtml"));
- environment.getServer().addResource("/resources/converter.js",
converterScriptName);
- environment.getServer().addWebListener(new ServletRequestListener() {
-
- public void requestInitialized(ServletRequestEvent sre) {
- sre.getServletRequest().setAttribute("testBean", testBean);
- }
-
- public void requestDestroyed(ServletRequestEvent sre) {
- }
- });
-
- environment.start();
- }
-
- @After
- public void tearDown() throws Exception {
- submittedValue = null;
- failureMessage = null;
-
- testBean = null;
-
- environment.release();
- environment = null;
- }
-
- protected String serializeObjectToScript(Object object) {
- if (object instanceof Date) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime((Date) object);
- calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- return new JSFunction("new Date", calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
- calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR),
calendar.get(Calendar.MINUTE),
- calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND)).toScript();
- }
-
- return ScriptUtils.toScript(object);
- }
-
- public void setConversionErrorMessage(String conversionErrorMessage) {
- testBean.setConversionErrorMessage(conversionErrorMessage);
- }
-
- public void setConverterId(String converterId) {
- testBean.setConverterId(converterId);
- }
-
- public void setClientConverterClassName(String clientConverterClassName) {
- testBean.setClientConverterClassName(clientConverterClassName);
- }
-
- public void setAttribute(String name, Object value) {
- testBean.setAttribute(name, value);
- }
-
- public void setSubmittedValue(String submittedValue) {
- this.submittedValue = submittedValue;
- }
-
- public void setFailureMessage(String failureMessage) {
- this.failureMessage = failureMessage;
- }
-
- public void setConversionErrorMessageEnum(
- Enum<?> conversionErrorMessageEnum) {
- testBean.setConversionErrorMessageEnum(conversionErrorMessageEnum);
- }
-
- public void assertConversionOk() throws Exception {
- HtmlPage page = environment.getPage("/test.jsf");
- System.out.println(page.asXml());
- assertTrue(page.getWebClient().isJavaScriptEnabled());
- ScriptResult conversionMessageResult =
page.executeJavaScript("verifyConversion()");
- if (!ScriptResult.isUndefined(conversionMessageResult)) {
- fail(conversionMessageResult.getJavaScriptResult().toString());
- }
- }
-
- public void assertConversionFailure() throws Exception {
- HtmlPage page = environment.getPage("/test.jsf");
-
- assertNotNull(testBean.getConverterException());
-
- assertTrue(page.getWebClient().isJavaScriptEnabled());
- ScriptResult conversionErrorResult =
page.executeJavaScript("window.conversionError");
-
- if (ScriptResult.isUndefined(conversionErrorResult)) {
- fail("converter has not thrown an error");
- return;
- }
-
- Object conversionErrorMessage;
-
- Object scriptResult = conversionErrorResult.getJavaScriptResult();
- if (scriptResult instanceof Scriptable) {
- Scriptable scriptable = (Scriptable) scriptResult;
- conversionErrorMessage = scriptable.get("message", scriptable);
- } else {
- conversionErrorMessage = scriptResult;
- }
-
- if (failureMessage != null) {
- assertEquals(failureMessage, conversionErrorMessage);
- } else {
- assertEquals(testBean.getConverterException().getMessage(), conversionErrorMessage);
- }
- }
-
- public void setup(TestData testData) {
- setSubmittedValue(testData.submittedValue());
- setFailureMessage(testData.failureMessage());
- }
-
-}
Deleted:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTestRunner.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTestRunner.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTestRunner.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -1,198 +0,0 @@
-/*
- * 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 java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.Test;
-import org.junit.internal.runners.model.ReflectiveCallable;
-import org.junit.runner.Runner;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.BlockJUnit4ClassRunner;
-import org.junit.runners.Suite;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.Statement;
-import org.junit.runners.model.TestClass;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class BaseConverterTestRunner extends Suite {
-
- private static final class ParameterizedFrameworkMethod extends FrameworkMethod {
-
- private TestData testData;
-
- private boolean failure;
-
- public ParameterizedFrameworkMethod(Method method, TestData testData, boolean
failure) {
- super(method);
- this.testData = testData;
- this.failure = failure;
- }
-
- public String getFormattedParameters() {
- if (testData == null) {
- return "no test data";
- }
-
- StringBuilder sb = new StringBuilder();
-
- if (failure) {
- sb.append("<failure>");
- } else {
- sb.append("<success>");
- }
-
- sb.append(" @TestData {");
-
- sb.append("submittedValue=" + testData.submittedValue());
-
- if (!Strings.isNullOrEmpty(testData.failureMessage())) {
- sb.append(", failureMessage=" + testData.failureMessage());
- }
-
- sb.append("}");
-
- return sb.toString();
- }
-
- @Override
- public Object invokeExplosively(final Object target, final Object... params)
throws Throwable {
- return new ReflectiveCallable() {
- @Override
- protected Object runReflectiveCall() throws Throwable {
- BaseConverterTest baseConverterTest = (BaseConverterTest) target;
-
- baseConverterTest.setSubmittedValue(testData.submittedValue());
-
- if (!Strings.isNullOrEmpty(testData.failureMessage())) {
- baseConverterTest.setFailureMessage(testData.failureMessage());
- }
-
- Object returnValue = getMethod().invoke(target, params);
-
- if (failure) {
- baseConverterTest.assertConversionFailure();
- } else {
- baseConverterTest.assertConversionOk();
- }
-
- return returnValue;
- }
- }.run();
- }
- }
-
- private class ParameterizedTestRunner extends BlockJUnit4ClassRunner {
-
- private String testMethodName;
-
- private List<FrameworkMethod> children = Lists.newArrayList();
-
- public ParameterizedTestRunner(Class<?> klass, FrameworkMethod testMethod)
- throws InitializationError {
-
- super(klass);
-
- this.testMethodName = testMethod.getName();
-
- TestDataHolder testDataHolder =
testMethod.getAnnotation(TestDataHolder.class);
- if (testDataHolder != null) {
- for (TestData testData : testDataHolder.successes()) {
- children.add(new ParameterizedFrameworkMethod(testMethod.getMethod(),
testData, false));
- }
-
- for (TestData testData : testDataHolder.failures()) {
- children.add(new ParameterizedFrameworkMethod(testMethod.getMethod(),
testData, true));
- }
- } else {
- children.add(testMethod);
- }
- }
-
- @Override
- public Object createTest() throws Exception {
- return getTestClass().getOnlyConstructor().newInstance();
- }
-
- @Override
- protected String getName() {
- return testMethodName;
- }
-
- @Override
- protected String testName(final FrameworkMethod method) {
- if (method instanceof ParameterizedFrameworkMethod) {
- String formattedParamsString = ((ParameterizedFrameworkMethod)
method).getFormattedParameters();
-
- return String.format("%s %s", testMethodName,
formattedParamsString);
- }
-
- return testMethodName;
- }
-
- @Override
- protected void validateConstructor(List<Throwable> errors) {
- validateOnlyOneConstructor(errors);
- }
-
- @Override
- protected Statement classBlock(RunNotifier notifier) {
- return childrenInvoker(notifier);
- }
-
- @Override
- protected List<FrameworkMethod> getChildren() {
- return children;
- }
-
- }
-
- private final ArrayList<Runner> runners = new ArrayList<Runner>();
-
- /**
- * Only called reflectively. Do not use programmatically.
- */
- public BaseConverterTestRunner(Class<?> klass) throws Throwable {
- super(klass, Collections.<Runner>emptyList());
-
- TestClass testClass = getTestClass();
- List<FrameworkMethod> testMethods =
testClass.getAnnotatedMethods(Test.class);
- for (FrameworkMethod testMethod: testMethods) {
- runners.add(new ParameterizedTestRunner(klass, testMethod));
- }
- }
-
- @Override
- protected List<Runner> getChildren() {
- return runners;
- }
-}
Copied: branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java
(from rev 19811,
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTest.java)
===================================================================
--- branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,424 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.text.MessageFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.Map.Entry;
+
+import javax.el.ExpressionFactory;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.faces.component.UIComponent;
+import javax.faces.component.html.HtmlInputText;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+
+import net.sourceforge.htmlunit.corejs.javascript.Scriptable;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.ScriptUtils;
+import org.jboss.test.faces.htmlunit.HtmlUnitEnvironment;
+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;
+
+import com.gargoylesoftware.htmlunit.ScriptResult;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.google.common.collect.Maps;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class BaseTest {
+
+ public static final String TEST_COMPONENT_LABEL = "input";
+
+ public class TestBean {
+
+ private static final String CONVERTER_VAR = "__converter";
+
+ private static final String VALIDATOR_VAR = "__validator";
+
+ private String objectId;
+
+ private String clientFunction;
+
+ private String valueAsScript;
+
+ private String errorMessage;
+
+ private Enum<?>[] errorMessageEnums;
+
+ private Exception resultException;
+
+ private Map<String, Object> attributes = new HashMap<String, Object>();
+
+ private String parametersString;
+
+ private String componentLabel;
+
+ public String getComponentLabel() {
+ return this.componentLabel;
+ }
+
+ public void setComponentLabel(String componentLabel) {
+ this.componentLabel = componentLabel;
+ }
+
+ public void setClientFunction(String clientFunction) {
+ this.clientFunction = clientFunction;
+ }
+
+ public String getClientFunction() {
+ return clientFunction;
+ }
+
+ public void setObjectId(String objectId) {
+ this.objectId = objectId;
+ }
+
+ public String getSubmittedValue() {
+ return submittedValue;
+ }
+
+ public String getSubmittedValueAsScript() {
+ return ScriptUtils.toScript(submittedValue);
+ }
+
+ public String getErrorMessagesAsScript() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ final Map<Object, Object> result = Maps.newHashMap();
+
+ if (errorMessageEnums != null) {
+ for (Enum<?> errorMessageEnum : errorMessageEnums) {
+ MessageFactory messageFactory = ServiceTracker.getService(MessageFactory.class);
+ String errorMessage = messageFactory.getMessageFormat(facesContext,
errorMessageEnum);
+
+ result.put(errorMessageEnum.name(), MessageFormat.format(errorMessage ,
"{0}"));
+ }
+ }
+ return ScriptUtils.toScript(result);
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ public void setAttribute(String name, Object value) {
+ attributes.put(name, value);
+ }
+
+ public String getParametersString() {
+ return parametersString;
+ }
+
+ public Exception getResultException() {
+ return resultException;
+ }
+
+ public void setErrorMessageEnums(
+ Enum<?>[] errorMessageEnums) {
+ this.errorMessageEnums = errorMessageEnums;
+ }
+
+ private void configure(FacesContext facesContext, Object object, String bindingVarName)
{
+ ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
+
+ VariableMapper varMapper = facesContext.getELContext().getVariableMapper();
+ ValueExpression originalExpr = varMapper.resolveVariable(bindingVarName);
+ try {
+ varMapper.setVariable(bindingVarName, expressionFactory.createValueExpression(object,
Object.class));
+
+ for (Entry<String, Object> mapEntry: attributes.entrySet()) {
+
+ String exprString = MessageFormat.format("#'{'{0}.{1}'}'",
bindingVarName, mapEntry.getKey());
+ ValueExpression ve =
expressionFactory.createValueExpression(facesContext.getELContext(), exprString,
Object.class);
+
+ ve.setValue(facesContext.getELContext(), mapEntry.getValue());
+ }
+ } finally {
+ varMapper.setVariable(bindingVarName, originalExpr);
+ }
+ }
+
+ private Converter createConverter(FacesContext facesContext) {
+ Converter converter = facesContext.getApplication().createConverter(objectId);
+ configure(facesContext, converter, CONVERTER_VAR);
+ return converter;
+ }
+
+ private Validator createValidator(FacesContext facesContext) {
+ Validator validator = facesContext.getApplication().createValidator(objectId);
+ configure(facesContext, validator, VALIDATOR_VAR);
+ return validator;
+ }
+
+ private UIComponent createTestComponent() {
+ HtmlInputText testComponent = new HtmlInputText();
+ testComponent.setLabel(TEST_COMPONENT_LABEL);
+ testBean.componentLabel = TEST_COMPONENT_LABEL;
+ return testComponent;
+ }
+
+ public String getConvertedValueAsScript() {
+ return valueAsScript != null ? valueAsScript : "null";
+ }
+
+ public void initConverter() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Converter converter = createConverter(facesContext);
+ try {
+ Object convertedObject = converter.getAsObject(facesContext, createTestComponent(),
submittedValue);
+ valueAsScript = serializeObjectToScript(convertedObject);
+ } catch (ConverterException e) {
+ this.resultException = e;
+ }
+
+ init();
+ }
+
+ public void initValidator() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Validator validator = createValidator(facesContext);
+ try {
+ validator.validate(facesContext, createTestComponent(), submittedValue);
+ } catch (ValidatorException e) {
+ this.resultException = e;
+ }
+
+ init();
+ }
+
+ protected void init() {
+ if (objectId == null || clientFunction == null) {
+ throw new NullPointerException();
+ }
+
+ Map<String,Object> map = new HashMap<String, Object>(attributes);
+ map.put("componentId", TEST_COMPONENT_LABEL);
+ if (errorMessage!=null) {
+ map.put("customMessage", MessageFormat.format(errorMessage ,
"{0}"));
+ }
+
+ parametersString = ScriptUtils.toScript(map);
+ }
+ }
+
+ private TestBean testBean;
+
+ private HtmlUnitEnvironment environment;
+
+ private String converterScriptName;
+
+ private String submittedValue;
+
+ private String failureMessage;
+
+ public BaseTest(String converterScriptName) {
+ this.converterScriptName = converterScriptName;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ testBean = new TestBean();
+
+ environment = new HtmlUnitEnvironment(new JettyServer());
+ environment.getServer().addResource("/testConverter.xhtml",
BaseTest.class.getResource("testConverter.xhtml"));
+ environment.getServer().addResource("/testValidator.xhtml",
BaseTest.class.getResource("testValidator.xhtml"));
+ environment.getServer().addResource("/resources/resource.js",
converterScriptName);
+ environment.getServer().addWebListener(new ServletRequestListener() {
+
+ public void requestInitialized(ServletRequestEvent sre) {
+ sre.getServletRequest().setAttribute("testBean", testBean);
+ }
+
+ public void requestDestroyed(ServletRequestEvent sre) {
+ }
+ });
+
+ environment.start();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ submittedValue = null;
+ failureMessage = null;
+
+ testBean = null;
+ if (environment!=null) {
+ environment.release();
+ environment = null;
+ }
+ }
+
+ protected String serializeObjectToScript(Object object) {
+ if (object instanceof Date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime((Date) object);
+ calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+ return new JSFunction("new Date", calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR),
calendar.get(Calendar.MINUTE),
+ calendar.get(Calendar.SECOND), calendar.get(Calendar.MILLISECOND)).toScript();
+ }
+
+ return ScriptUtils.toScript(object);
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ testBean.setErrorMessage(errorMessage);
+ }
+
+ public void setObjectId(String objectId) {
+ testBean.setObjectId(objectId);
+ }
+
+ public void setClientFunction(String clientFunction) {
+ testBean.setClientFunction(clientFunction);
+ }
+
+ public void setAttribute(String name, Object value) {
+ testBean.setAttribute(name, value);
+ }
+
+ public void setSubmittedValue(String submittedValue) {
+ this.submittedValue = submittedValue;
+ }
+
+ public void setFailureMessage(String failureMessage) {
+ this.failureMessage = failureMessage;
+ }
+
+ public void setErrorMessageEnums(
+ Enum<?>... errorMessageEnums) {
+ testBean.setErrorMessageEnums(errorMessageEnums);
+ }
+
+ public void assertConversionOk() throws Exception {
+ HtmlPage page = environment.getPage("/testConverter.jsf");
+ System.out.println(page.asXml());
+ assertTrue(page.getWebClient().isJavaScriptEnabled());
+ ScriptResult conversionMessageResult =
page.executeJavaScript("verifyConversion()");
+ if (!ScriptResult.isUndefined(conversionMessageResult)) {
+ fail(conversionMessageResult.getJavaScriptResult().toString());
+ }
+ }
+
+ public void assertValidationOk() throws Exception {
+ HtmlPage page = environment.getPage("/testValidator.jsf");
+ System.out.println(page.asXml());
+ assertTrue(page.getWebClient().isJavaScriptEnabled());
+ ScriptResult messageResult = page.executeJavaScript("verifyValidation()");
+ if (!ScriptResult.isUndefined(messageResult)) {
+ fail(messageResult.getJavaScriptResult().toString());
+ }
+ }
+
+ public void assertConversionFailure() throws Exception {
+ HtmlPage page = environment.getPage("/testConverter.jsf");
+
+ assertNotNull(testBean.getResultException());
+
+ assertTrue(page.getWebClient().isJavaScriptEnabled());
+ ScriptResult conversionErrorResult =
page.executeJavaScript("window.conversionError");
+
+ if (ScriptResult.isUndefined(conversionErrorResult)) {
+ fail("converter has not thrown an error");
+ return;
+ }
+
+ Object conversionErrorMessage;
+
+ Object scriptResult = conversionErrorResult.getJavaScriptResult();
+ if (scriptResult instanceof Scriptable) {
+ Scriptable scriptable = (Scriptable) scriptResult;
+ conversionErrorMessage = scriptable.get("message", scriptable);
+ } else {
+ conversionErrorMessage = scriptResult;
+ }
+
+ if (failureMessage != null) {
+ assertEquals(failureMessage, conversionErrorMessage);
+ } else {
+ assertEquals(testBean.getResultException().getMessage(), conversionErrorMessage);
+ }
+ }
+
+ public void assertValidationFailure() throws Exception {
+ HtmlPage page = environment.getPage("/testValidator.jsf");
+
+ assertNotNull(testBean.getResultException());
+
+ assertTrue(page.getWebClient().isJavaScriptEnabled());
+ ScriptResult validationErrorResult =
page.executeJavaScript("window.validationError");
+
+ if (ScriptResult.isUndefined(validationErrorResult)) {
+ fail("validator has not thrown an error");
+ return;
+ }
+
+ Object validationErrorMessage;
+
+ Object scriptResult = validationErrorResult.getJavaScriptResult();
+ if (scriptResult instanceof Scriptable) {
+ Scriptable scriptable = (Scriptable) scriptResult;
+ validationErrorMessage = scriptable.get("message", scriptable);
+ } else {
+ validationErrorMessage = scriptResult;
+ }
+
+ if (failureMessage != null) {
+ assertEquals(failureMessage, validationErrorMessage);
+ } else {
+ assertEquals(testBean.getResultException().getMessage(), validationErrorMessage);
+ }
+ }
+
+ public void setup(TestData testData) {
+ setSubmittedValue(testData.submittedValue());
+ setFailureMessage(testData.failureMessage());
+ }
+
+}
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTestRunner.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTestRunner.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTestRunner.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,195 @@
+/*
+ * 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 java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.internal.runners.model.ReflectiveCallable;
+import org.junit.runner.Runner;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.Suite;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+public abstract class BaseTestRunner extends Suite {
+
+ private final class ParameterizedFrameworkMethod extends FrameworkMethod {
+
+ private TestData testData;
+
+ private boolean failure;
+
+ public ParameterizedFrameworkMethod(Method method, TestData testData, boolean
failure) {
+ super(method);
+ this.testData = testData;
+ this.failure = failure;
+ }
+
+ public String getFormattedParameters() {
+ if (testData == null) {
+ return "no test data";
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ if (failure) {
+ sb.append("<failure>");
+ } else {
+ sb.append("<success>");
+ }
+
+ sb.append(" @TestData {");
+
+ sb.append("submittedValue=" + testData.submittedValue());
+
+ if (!Strings.isNullOrEmpty(testData.failureMessage())) {
+ sb.append(", failureMessage=" + testData.failureMessage());
+ }
+
+ sb.append("}");
+
+ return sb.toString();
+ }
+
+ @Override
+ public Object invokeExplosively(final Object target, final Object... params)
throws Throwable {
+ return new ReflectiveCallable() {
+ @Override
+ protected Object runReflectiveCall() throws Throwable {
+ BaseTest baseTest = (BaseTest) target;
+
+ baseTest.setSubmittedValue(testData.submittedValue());
+
+ if (!Strings.isNullOrEmpty(testData.failureMessage())) {
+ baseTest.setFailureMessage(testData.failureMessage());
+ }
+
+ Object returnValue = getMethod().invoke(target, params);
+ checkResult(baseTest, failure);
+
+ return returnValue;
+ }
+ }.run();
+ }
+ }
+
+ protected abstract void checkResult(BaseTest baseTest, boolean failure) throws
Throwable;
+
+ private class ParameterizedTestRunner extends BlockJUnit4ClassRunner {
+
+ private String testMethodName;
+
+ private List<FrameworkMethod> children = Lists.newArrayList();
+
+ public ParameterizedTestRunner(Class<?> klass, FrameworkMethod testMethod)
+ throws InitializationError {
+
+ super(klass);
+
+ this.testMethodName = testMethod.getName();
+
+ TestDataHolder testDataHolder =
testMethod.getAnnotation(TestDataHolder.class);
+ if (testDataHolder != null) {
+ for (TestData testData : testDataHolder.successes()) {
+ children.add(new ParameterizedFrameworkMethod(testMethod.getMethod(),
testData, false));
+ }
+
+ for (TestData testData : testDataHolder.failures()) {
+ children.add(new ParameterizedFrameworkMethod(testMethod.getMethod(),
testData, true));
+ }
+ } else {
+ children.add(testMethod);
+ }
+ }
+
+ @Override
+ public Object createTest() throws Exception {
+ return getTestClass().getOnlyConstructor().newInstance();
+ }
+
+ @Override
+ protected String getName() {
+ return testMethodName;
+ }
+
+ @Override
+ protected String testName(final FrameworkMethod method) {
+ if (method instanceof ParameterizedFrameworkMethod) {
+ String formattedParamsString = ((ParameterizedFrameworkMethod)
method).getFormattedParameters();
+
+ return String.format("%s %s", testMethodName,
formattedParamsString);
+ }
+
+ return testMethodName;
+ }
+
+ @Override
+ protected void validateConstructor(List<Throwable> errors) {
+ validateOnlyOneConstructor(errors);
+ }
+
+ @Override
+ protected Statement classBlock(RunNotifier notifier) {
+ return childrenInvoker(notifier);
+ }
+
+ @Override
+ protected List<FrameworkMethod> getChildren() {
+ return children;
+ }
+
+ }
+
+ private final ArrayList<Runner> runners = new ArrayList<Runner>();
+
+ /**
+ * Only called reflectively. Do not use programmatically.
+ */
+ public BaseTestRunner(Class<?> klass) throws Throwable {
+ super(klass, Collections.<Runner>emptyList());
+
+ TestClass testClass = getTestClass();
+ List<FrameworkMethod> testMethods =
testClass.getAnnotatedMethods(Test.class);
+ for (FrameworkMethod testMethod: testMethods) {
+ runners.add(new ParameterizedTestRunner(klass, testMethod));
+ }
+ }
+
+ @Override
+ protected List<Runner> getChildren() {
+ return runners;
+ }
+}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -24,13 +24,15 @@
import javax.faces.convert.BooleanConverter;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.richfaces.appplication.FacesMessages;
/**
* @author Pavel Yaschenko
*
*/
-public class BooleanConverterTest extends BaseConverterTest {
+(a)RunWith(ConverterTestRunner.class)
+public class BooleanConverterTest extends BaseTest {
public BooleanConverterTest() {
super("META-INF/resources/org.richfaces/boolean-converter.js");
@@ -50,8 +52,8 @@
failures = {}
)
public void testSuccess() throws Exception {
-
setClientConverterClassName("RichFaces.csv.getConverter('boolean')");
- setConverterId(BooleanConverter.CONVERTER_ID);
- setConversionErrorMessageEnum(FacesMessages.BOOLEAN_CONVERTER_BOOLEAN);
+ setClientFunction("RichFaces.csv.getConverter('boolean')");
+ setObjectId(BooleanConverter.CONVERTER_ID);
+ setErrorMessageEnums(FacesMessages.BOOLEAN_CONVERTER_BOOLEAN);
}
}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -24,13 +24,15 @@
import javax.faces.convert.ByteConverter;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.richfaces.appplication.FacesMessages;
/**
* @author Pavel Yaschenko
*
*/
-public class ByteConverterTest extends BaseConverterTest {
+(a)RunWith(ConverterTestRunner.class)
+public class ByteConverterTest extends BaseTest {
public ByteConverterTest() {
super("META-INF/resources/org.richfaces/byte-converter.js");
@@ -54,8 +56,8 @@
}
)
public void testSuccess() throws Exception {
-
setClientConverterClassName("RichFaces.csv.getConverter('byte')");
- setConverterId(ByteConverter.CONVERTER_ID);
- setConversionErrorMessageEnum(FacesMessages.BYTE_CONVERTER_BYTE);
+ setClientFunction("RichFaces.csv.getConverter('byte')");
+ setObjectId(ByteConverter.CONVERTER_ID);
+ setErrorMessageEnums(FacesMessages.BYTE_CONVERTER_BYTE);
}
}
Copied:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ConverterTestRunner.java
(from rev 19811,
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseConverterTestRunner.java)
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ConverterTestRunner.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ConverterTestRunner.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+public class ConverterTestRunner extends BaseTestRunner {
+
+ public ConverterTestRunner(Class<?> klass) throws Throwable {
+ super(klass);
+ }
+
+ protected void checkResult (BaseTest baseTest, boolean failure) throws Throwable {
+ if (failure) {
+ baseTest.assertConversionFailure();
+ } else {
+ baseTest.assertConversionOk();
+ }
+ }
+}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/DateTimeConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/DateTimeConverterTest.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/DateTimeConverterTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -24,12 +24,14 @@
import javax.faces.convert.DateTimeConverter;
import org.junit.Test;
+import org.junit.runner.RunWith;
/**
* @author Nick Belaevski
*
*/
-public class DateTimeConverterTest extends BaseConverterTest {
+(a)RunWith(ConverterTestRunner.class)
+public class DateTimeConverterTest extends BaseTest {
public DateTimeConverterTest() {
super("org/richfaces/convert/testConverter.js");
@@ -39,15 +41,15 @@
@TestDataHolder(
successes = {
@TestData(submittedValue = "18-10-2010"),
- @TestData(submittedValue = "17-10-2010")
+ //@TestData(submittedValue = "17-10-2010")
},
failures = {
- @TestData(submittedValue = "10/17/2010")
+ //@TestData(submittedValue = "10/17/2010")
}
)
public void testPattern() throws Exception {
- setClientConverterClassName("org.rf.DateTimeConverter");
- setConverterId(DateTimeConverter.CONVERTER_ID);
+ setClientFunction("org.rf.DateTimeConverter");
+ setObjectId(DateTimeConverter.CONVERTER_ID);
setAttribute("pattern", "dd-MM-yyyy");
}
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/LengthValidatorTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/LengthValidatorTest.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/LengthValidatorTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,58 @@
+/*
+ * 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.LengthValidator;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.appplication.FacesMessages;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+(a)RunWith(ValidatorTestRunner.class)
+public class LengthValidatorTest extends BaseTest {
+
+ public LengthValidatorTest() {
+ super("META-INF/resources/org.richfaces/length-validator.js");
+ }
+
+ @Test
+ @TestDataHolder(
+ successes = {
+ @TestData(submittedValue = "dddd")
+ },
+ failures = {
+ @TestData(submittedValue = "1234567890A")
+ }
+ )
+ public void testSuccess() throws Exception {
+ setClientFunction("RichFaces.csv.getValidator('length')");
+ setObjectId(LengthValidator.VALIDATOR_ID);
+ Enum<?>[] messages = {FacesMessages.LENGTH_VALIDATOR_MAXIMUM,
FacesMessages.LENGTH_VALIDATOR_MINIMUM};
+ setErrorMessageEnums(messages);
+ setAttribute("maximum", 10);
+ setAttribute("minimum", 0);
+ }
+}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/NumberConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/NumberConverterTest.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/NumberConverterTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -24,13 +24,15 @@
import javax.faces.convert.NumberConverter;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.richfaces.appplication.FacesMessages;
/**
* @author Pavel Yaschenko
*
*/
-public class NumberConverterTest extends BaseConverterTest {
+(a)RunWith(ConverterTestRunner.class)
+public class NumberConverterTest extends BaseTest {
public NumberConverterTest() {
super("META-INF/resources/org.richfaces/number-converter.js");
@@ -46,9 +48,9 @@
}
)
public void testSuccess() throws Exception {
-
setClientConverterClassName("RichFaces.csv.getConverter('number')");
- setConverterId(NumberConverter.CONVERTER_ID);
- setConversionErrorMessageEnum(FacesMessages.NUMBER_CONVERTER_NUMBER);
+ setClientFunction("RichFaces.csv.getConverter('number')");
+ setObjectId(NumberConverter.CONVERTER_ID);
+ setErrorMessageEnums(FacesMessages.NUMBER_CONVERTER_NUMBER);
}
}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -24,13 +24,15 @@
import javax.faces.convert.ShortConverter;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.richfaces.appplication.FacesMessages;
/**
* @author Pavel Yaschenko
*
*/
-public class ShortConverterTest extends BaseConverterTest {
+(a)RunWith(ConverterTestRunner.class)
+public class ShortConverterTest extends BaseTest {
public ShortConverterTest() {
super("META-INF/resources/org.richfaces/short-converter.js");
@@ -54,8 +56,8 @@
}
)
public void testSuccess() throws Exception {
-
setClientConverterClassName("RichFaces.csv.getConverter('short')");
- setConverterId(ShortConverter.CONVERTER_ID);
- setConversionErrorMessageEnum(FacesMessages.SHORT_CONVERTER_SHORT);
+ setClientFunction("RichFaces.csv.getConverter('short')");
+ setObjectId(ShortConverter.CONVERTER_ID);
+ setErrorMessageEnums(FacesMessages.SHORT_CONVERTER_SHORT);
}
}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestData.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestData.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestData.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -27,7 +27,7 @@
import java.lang.annotation.Target;
/**
- * Test data annotation for {@link BaseConverterTest}
+ * Test data annotation for {@link BaseTest}
* @author Nick Belaevski
*
*/
Added:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ValidatorTestRunner.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ValidatorTestRunner.java
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ValidatorTestRunner.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+/**
+ * @author Pavel Yaschenko
+ *
+ */
+public class ValidatorTestRunner extends BaseTestRunner {
+
+ public ValidatorTestRunner(Class<?> klass) throws Throwable {
+ super(klass);
+ }
+
+ protected void checkResult (BaseTest baseTest, boolean failure) throws Throwable {
+ if (failure) {
+ baseTest.assertValidationFailure();
+ } else {
+ baseTest.assertValidationOk();
+ }
+ }
+}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-11-01
12:14:59 UTC (rev 19817)
@@ -241,7 +241,7 @@
@Override
Collection<? extends LibraryScriptString>
getClientSideValidatorScript(FacesContext facesContext,
- Collection<FacesObjectDescriptor> validators) {
+ Collection<ValidatorDescriptor> validators) {
return Lists.newArrayList(validatorFunctions);
}
};
Deleted:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/test.xhtml
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/test.xhtml 2010-11-01
12:00:03 UTC (rev 19816)
+++
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/test.xhtml 2010-11-01
12:14:59 UTC (rev 19817)
@@ -1,54 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:h="http://java.sun.com/jsf/html">
-<f:view>
- <f:metadata>
- <f:event type="preRenderView" listener="#{testBean.init}"/>
- </f:metadata>
-<h:head>
- <h:outputScript name="jquery.js" />
- <h:outputScript name="richfaces.js" />
- <h:outputScript name="richfaces-event.js" />
- <h:outputScript name="richfaces-csv.js"
library="org.richfaces"/>
- <h:outputScript name="converter.js" />
-</h:head>
-<h:body>
- <script type="text/javascript">/* <![CDATA[ */
- window.expected = #{testBean.convertedValueAsScript};
-
- try {
- window.actual =
#{testBean.clientConverterClassName}(#{testBean.submittedValueAsScript},
- #{testBean.converterParametersString});
- } catch (e) {
- window.conversionError = e;
- }
-
- function equals(a, b) {
- if (a === b) {
- return true;
- }
-
- if (a instanceof Date && b instanceof Date) {
- return a.getTime() === b.getTime();
- }
-
- //TODO - implement equality checking for all supported objects in a proper way
- return false;
- }
-
- function verifyConversion() {
- if (window.conversionError) {
- return "conversion error caught: " + window.conversionError.message;
- }
-
- if (!equals(window.actual, window.expected)) {
- return "expected [" + window.expected + "] but was [" +
window.actual + "]";
- }
- }
- /* ]]> */</script>
-</h:body>
-</f:view>
-</html>
\ No newline at end of file
Added:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testConverter.xhtml
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testConverter.xhtml
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testConverter.xhtml 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,55 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html">
+<f:view>
+ <f:metadata>
+ <f:event type="preRenderView"
listener="#{testBean.initConverter}"/>
+ </f:metadata>
+<h:head>
+ <h:outputScript name="jquery.js" />
+ <h:outputScript name="richfaces.js" />
+ <h:outputScript name="richfaces-event.js" />
+ <h:outputScript name="richfaces-csv.js"
library="org.richfaces"/>
+ <h:outputScript name="resource.js" />
+</h:head>
+<h:body>
+ <script type="text/javascript">/* <![CDATA[ */
+ window.expected = #{testBean.convertedValueAsScript};
+ RichFaces.csv.addMessage(#{testBean.errorMessagesAsScript});
+
+ try {
+ window.actual = #{testBean.clientFunction}(#{testBean.submittedValueAsScript},
+ #{testBean.parametersString});
+ } catch (e) {
+ window.conversionError = e;
+ }
+
+ function equals(a, b) {
+ if (a === b) {
+ return true;
+ }
+
+ if (a instanceof Date && b instanceof Date) {
+ return a.getTime() === b.getTime();
+ }
+
+ //TODO - implement equality checking for all supported objects in a proper way
+ return false;
+ }
+
+ function verifyConversion() {
+ if (window.conversionError) {
+ return "conversion error caught: " + window.conversionError.message;
+ }
+
+ if (!equals(window.actual, window.expected)) {
+ return "expected [" + window.expected + "] but was [" +
window.actual + "]";
+ }
+ }
+ /* ]]> */</script>
+</h:body>
+</f:view>
+</html>
\ No newline at end of file
Added:
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testValidator.xhtml
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testValidator.xhtml
(rev 0)
+++
branches/RF-8742/ui/validator/ui/src/test/resources/org/richfaces/convert/testValidator.xhtml 2010-11-01
12:14:59 UTC (rev 19817)
@@ -0,0 +1,37 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html">
+<f:view>
+ <f:metadata>
+ <f:event type="preRenderView"
listener="#{testBean.initValidator}"/>
+ </f:metadata>
+<h:head>
+ <h:outputScript name="jquery.js" />
+ <h:outputScript name="richfaces.js" />
+ <h:outputScript name="richfaces-event.js" />
+ <h:outputScript name="richfaces-csv.js"
library="org.richfaces"/>
+ <h:outputScript name="resource.js" />
+</h:head>
+<h:body>
+ <script type="text/javascript">/* <![CDATA[ */
+
+ RichFaces.csv.addMessage(#{testBean.errorMessagesAsScript});
+ try {
+ #{testBean.clientFunction}('#{testBean.componentLabel}',
#{testBean.submittedValueAsScript},
+ #{testBean.parametersString});
+ } catch (e) {
+ window.validationError = e;
+ }
+
+ function verifyValidation(){
+ if (window.validationError) {
+ return "validation error caught: " + window.validationError.message;
+ }
+ }
+ /* ]]> */</script>
+</h:body>
+</f:view>
+</html>
\ No newline at end of file