Author: alexsmirnov
Date: 2010-11-01 15:50:05 -0400 (Mon, 01 Nov 2010)
New Revision: 19862
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java
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/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/ConverterTestRunner.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/LengthValidatorTest.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/convert/TestDataHolder.java
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/renderkit/html/RendererGetComponentScriptTest.java
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java
Log:
CODING IN PROGRESS - issue RF-9593: CSV - create tests and implementation for AJAX
transport.
https://jira.jboss.org/browse/RF-9593
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/UIAjaxValidator.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -128,7 +128,7 @@
public void encodeAjax(FacesContext context) throws IOException {
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
Set<String> renderedAreas = ajaxContext.getAjaxRenderedAreas();
- for (UIComponent message : getMessages(context)) {
+ for (UIComponent message : getMessages(context, this)) {
if (message.isRendered()) {
message.encodeAll(context);
renderedAreas.add(message.getClientId(context));
@@ -138,9 +138,9 @@
// AjaxRendererUtils.encodeAreas(context, this);
}
- public Set<UIComponent> getMessages(FacesContext context) {
+ public Set<UIComponent> getMessages(FacesContext context, UIComponent
component) {
Set<UIComponent> messages = new HashSet<UIComponent>();
- findMessages(this.getParent(), this, messages, false);
+ findMessages(component.getParent(), component, messages, false);
findRichMessages(context, context.getViewRoot(), messages);
return messages;
}
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorBehavior.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -48,5 +48,11 @@
Class<?>[] getGroups();
void setGroups(Class<?> ...groups);
+
+ boolean isDisabled();
+
+ boolean isImmediateSet();
+
+ boolean isImmediate();
}
\ No newline at end of file
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/component/behavior/ClientValidatorImpl.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -23,22 +23,32 @@
package org.richfaces.component.behavior;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
import javax.el.ValueExpression;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.component.ActionSource;
import javax.faces.component.EditableValueHolder;
+import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
+import javax.faces.component.UIMessage;
+import javax.faces.component.UIMessages;
import javax.faces.component.behavior.AjaxBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.context.FacesContext;
+import javax.faces.context.PartialViewContext;
import javax.faces.convert.Converter;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.BehaviorEvent;
import javax.faces.render.ClientBehaviorRenderer;
import javax.faces.render.RenderKit;
import javax.faces.validator.Validator;
import org.richfaces.application.ServiceTracker;
+import org.richfaces.component.UIRichMessages;
import org.richfaces.log.Logger;
import org.richfaces.log.RichfacesLogger;
import org.richfaces.renderkit.html.ClientValidatorRenderer;
@@ -86,18 +96,92 @@
}
@Override
- public void decode(FacesContext context, UIComponent component) {
- if (null == context || null == component) {
- throw new NullPointerException();
+ public void broadcast(BehaviorEvent event) throws AbortProcessingException {
+ // Add message components to re-render list ( if any )
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ PartialViewContext partialViewContext = facesContext.getPartialViewContext();
+ if(partialViewContext.isAjaxRequest()){
+ UIComponent component = event.getComponent();
+ if(component instanceof EditableValueHolder){
+ EditableValueHolder input = (EditableValueHolder) component;
+ Set<UIComponent> messages = getMessages(facesContext, component);
+ Collection<String> renderIds = partialViewContext.getRenderIds();
+ for (UIComponent uiComponent : messages) {
+ renderIds.add(uiComponent.getClientId(facesContext));
+ }
+ }
}
- ClientBehaviorRenderer renderer = getRenderer(context,
AjaxBehavior.BEHAVIOR_ID);
- if (null != renderer) {
- renderer.decode(context, component, this);
- // TODO - setup phase and render area to rerender.
+ super.broadcast(event);
+ }
+
+ public Set<UIComponent> getMessages(FacesContext context, UIComponent
component) {
+ Set<UIComponent> messages = new HashSet<UIComponent>();
+ findMessages(component.getParent(),component, messages,
false,component.getId());
+ // TODO - enable then UIRichMessages will be done
+// findRichMessages(context, context.getViewRoot(), messages);
+ return messages;
+ }
+
+ /**
+ * Find all instances of the {@link UIRichMessages} and update list of the rendered
messages.
+ *
+ * @param context
+ * @param component
+ * @param messages
+ */
+ protected void findRichMessages(FacesContext context, UIComponent component, String
id, Set<UIComponent> messages) {
+ Iterator<UIComponent> facetsAndChildren =
component.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = (UIComponent) facetsAndChildren.next();
+ if (child instanceof UIRichMessages) {
+ UIRichMessages richMessage = (UIRichMessages) child;
+ if (null == richMessage.getFor()) {
+ richMessage.updateMessages(context, id);
+ messages.add(richMessage);
+ }
+ } else {
+ findRichMessages(context, child, id, messages);
+ }
}
}
/**
+ * Recursive search messages for the parent component.
+ *
+ * @param parent
+ * @param component
+ * @param messages
+ * @param id
+ * @return
+ */
+ protected boolean findMessages(UIComponent parent, UIComponent component,
Set<UIComponent> messages, boolean found, Object id) {
+ Iterator<UIComponent> facetsAndChildren = parent.getFacetsAndChildren();
+ while (facetsAndChildren.hasNext()) {
+ UIComponent child = (UIComponent) facetsAndChildren.next();
+ if (child != component) {
+ if (child instanceof UIMessage || child instanceof UIMessages) {
+ UIComponent message = (UIComponent) child;
+ Object targetId = message.getAttributes().get("for");
+ if (null != targetId && targetId.equals(id)) {
+ messages.add(message);
+ found = true;
+ }
+ } else {
+ found |= findMessages(child, null, messages, found,id);
+ }
+ }
+ }
+ if (!(found && parent instanceof NamingContainer) && component !=
null) {
+ UIComponent newParent = parent.getParent();
+ if (null != newParent) {
+ found = findMessages(newParent, parent, messages, found,id);
+ }
+ }
+ return found;
+ }
+
+
+ /**
* <p class="changed_added_4_0">
* Look up for {@link ClientBehaviorRenderer} instence
* </p>
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ClientValidatorRenderer.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -7,11 +7,15 @@
import java.util.List;
import javax.faces.FacesException;
+import javax.faces.component.ActionSource;
+import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.behavior.ClientBehavior;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.context.FacesContext;
+import javax.faces.event.AjaxBehaviorEvent;
+import javax.faces.event.PhaseId;
import javax.faces.render.ClientBehaviorRenderer;
import org.ajax4jsf.javascript.JSLiteral;
@@ -22,10 +26,10 @@
import org.richfaces.component.behavior.ConverterNotFoundException;
import org.richfaces.validator.ClientScriptService;
import org.richfaces.validator.ConverterDescriptor;
+import org.richfaces.validator.FacesObjectDescriptor;
import org.richfaces.validator.LibraryFunction;
import org.richfaces.validator.LibraryScriptString;
import org.richfaces.validator.ScriptNotFoundException;
-import org.richfaces.validator.FacesObjectDescriptor;
import org.richfaces.validator.ValidatorDescriptor;
import com.google.common.collect.Lists;
@@ -69,9 +73,56 @@
@Override
public void decode(FacesContext context, UIComponent component, ClientBehavior
behavior) {
- // TODO - properly set phase and re-render.
+ if (null == context || null == component || null == behavior) {
+ throw new NullPointerException();
+ }
+
+ if (!(behavior instanceof ClientValidatorBehavior)) {
+ throw new IllegalArgumentException(
+ "Instance of
org.ruchvaces.component.behaviot.ClientValidatorBehavior required: " + behavior);
+ }
+ ClientValidatorBehavior ajaxBehavior = (ClientValidatorBehavior)behavior;
+
+ // First things first - if AjaxBehavior is disabled, we are done.
+ if (!ajaxBehavior.isDisabled()) {
+ component.queueEvent(createEvent(component, ajaxBehavior));
+ }
}
- /**
+
+ // Creates an AjaxBehaviorEvent for the specified component/behavior
+ private static AjaxBehaviorEvent createEvent(UIComponent component,
+ ClientValidatorBehavior ajaxBehavior) {
+
+ AjaxBehaviorEvent event = new AjaxBehaviorEvent(component, ajaxBehavior);
+
+ PhaseId phaseId = isImmediate(component, ajaxBehavior) ?
+ PhaseId.APPLY_REQUEST_VALUES :
+ PhaseId.PROCESS_VALIDATIONS;
+
+ event.setPhaseId(phaseId);
+
+ return event;
+ }
+
+
+ // Tests whether we should perform immediate processing. Note
+ // that we "inherit" immediate from the parent if not specified
+ // on the behavior.
+ private static boolean isImmediate(UIComponent component,
+ ClientValidatorBehavior ajaxBehavior) {
+
+ boolean immediate = false;
+
+ if (ajaxBehavior.isImmediateSet()) {
+ immediate = ajaxBehavior.isImmediate();
+ } else if (component instanceof EditableValueHolder) {
+ immediate = ((EditableValueHolder)component).isImmediate();
+ } else if (component instanceof ActionSource) {
+ immediate = ((ActionSource)component).isImmediate();
+ }
+
+ return immediate;
+ } /**
* <p class="changed_added_4_0">
* This method builds client-side validation script and stores it in View resource
component
* </p>
@@ -86,7 +137,7 @@
FacesContext facesContext = behaviorContext.getFacesContext();
UIValidatorScript scriptResource =
getOrCreateValidatorScriptResource(facesContext);
validatorScript = scriptResource.addOrFindScript(validatorScript);
- return
validatorScript.createCallScript(behaviorContext.getComponent().getClientId(facesContext));
+ return
validatorScript.createCallScript(behaviorContext.getComponent().getClientId(facesContext),behaviorContext.getSourceId());
} else {
return null;
}
@@ -186,11 +237,17 @@
String ajaxScript = behavior.getAjaxScript(behaviorContext);
ajaxScript=ajaxScript.replace("this", "element");
String clientId = getComponentClientId(behaviorContext);
-
ajaxScript=ajaxScript.replace("'"+clientId+"'",ValidatorScriptBase.CLIENT_ID);
-
ajaxScript=ajaxScript.replace("\""+clientId+"\"",ValidatorScriptBase.CLIENT_ID);
+ ajaxScript = replaceTextToVariable(ajaxScript, clientId,
ValidatorScriptBase.CLIENT_ID);
+ ajaxScript = replaceTextToVariable(ajaxScript, behaviorContext.getSourceId(),
ValidatorScriptBase.SOURCE_ID);
return ajaxScript;
}
+ private String replaceTextToVariable(String ajaxScript, String clientId, String
variableName) {
+
ajaxScript=ajaxScript.replace("'"+clientId+"'",variableName);
+
ajaxScript=ajaxScript.replace("\""+clientId+"\"",variableName);
+ return ajaxScript;
+ }
+
/**
* <p class="changed_added_4_0">
* Build client-side function call for Server-side component descriptor.
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ComponentValidatorScript.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -14,9 +14,10 @@
/**
* <p class="changed_added_4_0">Creates JavasCript that calls
validator function.</p>
* @param clientId
+ * @param sourceId
* @return
*/
- String createCallScript(String clientId);
+ String createCallScript(String clientId, String sourceId);
}
Modified:
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/main/java/org/richfaces/renderkit/html/ValidatorScriptBase.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -13,6 +13,8 @@
protected static final String EOL = "\n;";
protected static final String CLIENT_ID = "clientId";
protected static final JSLiteral CLIENT_ID_LITERAL = new JSLiteral(CLIENT_ID);
+ protected static final String SOURCE_ID = "sourceId";
+ protected static final JSLiteral SOURCE_ID_LITERAL = new JSLiteral(SOURCE_ID);
protected static final NullConverterScript NULL_CONVERTER_SCRIPT = new
NullConverterScript();
protected static final String CSV_NAMESPACE = "RichFaces.csv.";
protected static final String VALUE_FUNCTION_NAME =
CSV_NAMESPACE+"getValue";
@@ -23,7 +25,7 @@
private boolean bodyProcessed = false;
public ValidatorScriptBase() {
- super(CLIENT_ID,"element",EVENT,DISABLE_AJAX);
+ super(CLIENT_ID,SOURCE_ID,"element",EVENT,DISABLE_AJAX);
}
public void appendScript(StringBuffer functionString) {
@@ -37,8 +39,8 @@
protected abstract Object buildBody();
- public String createCallScript(String clientId) {
- JSFunction callFunction = new JSFunction(getName(),clientId,THIS,EVENT_LITERAL);
+ public String createCallScript(String clientId,String sourceId) {
+ JSFunction callFunction = new
JSFunction(getName(),clientId,sourceId,THIS,EVENT_LITERAL);
return callFunction.toScript();
}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/component/TestBean.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -48,7 +48,7 @@
return FOO;
}
- public String createCallScript(String clientId) {
+ public String createCallScript(String clientId,String sourceId) {
return FOO+"("+clientId+")";
}
};
Modified:
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/BaseTest.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -69,356 +69,355 @@
*/
public abstract class BaseTest {
- public static final String TEST_COMPONENT_LABEL = "input";
+ public static final String TEST_COMPONENT_LABEL = "input";
- public class TestBean {
+ public class TestBean {
- private static final String CONVERTER_VAR = "__converter";
+ private static final String CONVERTER_VAR = "__converter";
- private static final String VALIDATOR_VAR = "__validator";
+ private static final String VALIDATOR_VAR = "__validator";
- private String objectId;
+ private String objectId;
- private String clientFunction;
+ private String clientFunction;
- private String valueAsScript;
+ private String valueAsScript;
- private String errorMessage;
+ private String errorMessage;
- private Enum<?>[] errorMessageEnums;
+ private Enum<?>[] errorMessageEnums;
- private Exception resultException;
+ private Exception resultException;
- private Map<String, Object> attributes = new HashMap<String, Object>();
+ 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;
- }
+ private String parametersString;
- public void setClientFunction(String clientFunction) {
- this.clientFunction = clientFunction;
- }
+ private String componentLabel;
- public String getClientFunction() {
- return clientFunction;
- }
+ public String getComponentLabel() {
+ return this.componentLabel;
+ }
- public void setObjectId(String objectId) {
- this.objectId = objectId;
- }
+ public void setComponentLabel(String componentLabel) {
+ this.componentLabel = componentLabel;
+ }
- public String getSubmittedValue() {
- return submittedValue;
- }
+ public void setClientFunction(String clientFunction) {
+ this.clientFunction = clientFunction;
+ }
- public String getSubmittedValueAsScript() {
- return ScriptUtils.toScript(submittedValue);
- }
+ public String getClientFunction() {
+ return clientFunction;
+ }
- 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 setObjectId(String objectId) {
+ this.objectId = objectId;
+ }
- public void setErrorMessage(String errorMessage) {
- this.errorMessage = errorMessage;
- }
+ public String getSubmittedValue() {
+ return submittedValue;
+ }
- public void setAttribute(String name, Object value) {
- attributes.put(name, value);
- }
+ public String getSubmittedValueAsScript() {
+ return ScriptUtils.toScript(submittedValue);
+ }
- public String getParametersString() {
- return parametersString;
- }
+ public String getErrorMessagesAsScript() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ final Map<Object, Object> result = Maps.newHashMap();
- public Exception getResultException() {
- return resultException;
- }
+ if (errorMessageEnums != null) {
+ for (Enum<?> errorMessageEnum : errorMessageEnums) {
+ MessageFactory messageFactory =
ServiceTracker.getService(MessageFactory.class);
+ String errorMessage = messageFactory.getMessageFormat(facesContext,
errorMessageEnum);
- public void setErrorMessageEnums(
- Enum<?>[] errorMessageEnums) {
- this.errorMessageEnums = errorMessageEnums;
- }
+ result.put(errorMessageEnum.name(),
MessageFormat.format(errorMessage, "{0}"));
+ }
+ }
+ return ScriptUtils.toScript(result);
+ }
- private void configure(FacesContext facesContext, Object object, String bindingVarName)
{
- ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
+ public String getErrorMessage() {
+ return errorMessage;
+ }
- VariableMapper varMapper = facesContext.getELContext().getVariableMapper();
- ValueExpression originalExpr = varMapper.resolveVariable(bindingVarName);
- try {
- varMapper.setVariable(bindingVarName, expressionFactory.createValueExpression(object,
Object.class));
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
- for (Entry<String, Object> mapEntry: attributes.entrySet()) {
+ public void setAttribute(String name, Object value) {
+ attributes.put(name, value);
+ }
- String exprString = MessageFormat.format("#'{'{0}.{1}'}'",
bindingVarName, mapEntry.getKey());
- ValueExpression ve =
expressionFactory.createValueExpression(facesContext.getELContext(), exprString,
Object.class);
+ public String getParametersString() {
+ return parametersString;
+ }
- ve.setValue(facesContext.getELContext(), mapEntry.getValue());
- }
- } finally {
- varMapper.setVariable(bindingVarName, originalExpr);
- }
- }
+ public Exception getResultException() {
+ return resultException;
+ }
- 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;
- }
+ public void setErrorMessageEnums(Enum<?>[] errorMessageEnums) {
+ this.errorMessageEnums = errorMessageEnums;
+ }
- private UIComponent createTestComponent() {
- HtmlInputText testComponent = new HtmlInputText();
- testComponent.setLabel(TEST_COMPONENT_LABEL);
- testBean.componentLabel = TEST_COMPONENT_LABEL;
- return testComponent;
- }
+ private void configure(FacesContext facesContext, Object object, String
bindingVarName) {
+ ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
- public String getConvertedValueAsScript() {
- return valueAsScript != null ? valueAsScript : "null";
- }
+ VariableMapper varMapper = facesContext.getELContext().getVariableMapper();
+ ValueExpression originalExpr = varMapper.resolveVariable(bindingVarName);
+ try {
+ varMapper.setVariable(bindingVarName,
expressionFactory.createValueExpression(object, Object.class));
- 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;
- }
+ for (Entry<String, Object> mapEntry : attributes.entrySet()) {
- init();
- }
-
- public void initValidator() {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- Validator validator = createValidator(facesContext);
- try {
- validator.validate(facesContext, createTestComponent(), submittedValue);
- } catch (ValidatorException e) {
- this.resultException = e;
- }
+ String exprString =
MessageFormat.format("#'{'{0}.{1}'}'", bindingVarName,
mapEntry.getKey());
+ ValueExpression ve =
+
expressionFactory.createValueExpression(facesContext.getELContext(), exprString,
Object.class);
- init();
- }
-
- protected void init() {
- if (objectId == null || clientFunction == null) {
- throw new NullPointerException();
- }
+ ve.setValue(facesContext.getELContext(), mapEntry.getValue());
+ }
+ } finally {
+ varMapper.setVariable(bindingVarName, originalExpr);
+ }
+ }
- 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}"));
- }
+ private Converter createConverter(FacesContext facesContext) {
+ Converter converter =
facesContext.getApplication().createConverter(objectId);
+ configure(facesContext, converter, CONVERTER_VAR);
+ return converter;
+ }
- parametersString = ScriptUtils.toScript(map);
- }
- }
+ private Validator createValidator(FacesContext facesContext) {
+ Validator validator =
facesContext.getApplication().createValidator(objectId);
+ configure(facesContext, validator, VALIDATOR_VAR);
+ return validator;
+ }
- private TestBean testBean;
+ private UIComponent createTestComponent() {
+ HtmlInputText testComponent = new HtmlInputText();
+ testComponent.setLabel(TEST_COMPONENT_LABEL);
+ testBean.componentLabel = TEST_COMPONENT_LABEL;
+ return testComponent;
+ }
- private HtmlUnitEnvironment environment;
+ public String getConvertedValueAsScript() {
+ return valueAsScript != null ? valueAsScript : "null";
+ }
- private String converterScriptName;
+ 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;
+ }
- private String submittedValue;
+ init();
+ }
- private String failureMessage;
+ public void initValidator() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ Validator validator = createValidator(facesContext);
+ try {
+ validator.validate(facesContext, createTestComponent(), submittedValue);
+ } catch (ValidatorException e) {
+ this.resultException = e;
+ }
- public BaseTest(String converterScriptName) {
- this.converterScriptName = converterScriptName;
- }
+ init();
+ }
- @Before
- public void setUp() throws Exception {
- testBean = new TestBean();
+ protected void init() {
+ if (objectId == null || clientFunction == null) {
+ throw new NullPointerException();
+ }
- 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() {
+ 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}"));
+ }
- public void requestInitialized(ServletRequestEvent sre) {
- sre.getServletRequest().setAttribute("testBean", testBean);
- }
+ parametersString = ScriptUtils.toScript(map);
+ }
+ }
- public void requestDestroyed(ServletRequestEvent sre) {
- }
- });
+ private TestBean testBean;
- environment.start();
- }
+ private HtmlUnitEnvironment environment;
- @After
- public void tearDown() throws Exception {
- submittedValue = null;
- failureMessage = null;
+ private String converterScriptName;
- testBean = null;
- if (environment!=null) {
- environment.release();
- environment = null;
- }
- }
+ private String submittedValue;
- protected String serializeObjectToScript(Object object) {
- if (object instanceof Date) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime((Date) object);
- calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
+ private String failureMessage;
- 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();
- }
+ public BaseTest(String converterScriptName) {
+ this.converterScriptName = converterScriptName;
+ }
- return ScriptUtils.toScript(object);
- }
+ @Before
+ public void setUp() throws Exception {
+ testBean = new TestBean();
- public void setErrorMessage(String errorMessage) {
- testBean.setErrorMessage(errorMessage);
- }
+ 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 setObjectId(String objectId) {
- testBean.setObjectId(objectId);
- }
+ public void requestInitialized(ServletRequestEvent sre) {
+ sre.getServletRequest().setAttribute("testBean", testBean);
+ }
- public void setClientFunction(String clientFunction) {
- testBean.setClientFunction(clientFunction);
- }
+ public void requestDestroyed(ServletRequestEvent sre) {
+ }
+ });
- public void setAttribute(String name, Object value) {
- testBean.setAttribute(name, value);
- }
+ environment.start();
+ }
- public void setSubmittedValue(String submittedValue) {
- this.submittedValue = submittedValue;
- }
+ @After
+ public void tearDown() throws Exception {
+ submittedValue = null;
+ failureMessage = null;
- public void setFailureMessage(String failureMessage) {
- this.failureMessage = failureMessage;
- }
+ testBean = null;
+ if (environment != null) {
+ environment.release();
+ environment = null;
+ }
+ }
- public void setErrorMessageEnums(
- Enum<?>... errorMessageEnums) {
- testBean.setErrorMessageEnums(errorMessageEnums);
- }
+ protected String serializeObjectToScript(Object object) {
+ if (object instanceof Date) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime((Date) object);
+ calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
- 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());
- }
- }
+ 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();
+ }
- public void assertConversionFailure() throws Exception {
- HtmlPage page = environment.getPage("/testConverter.jsf");
+ return ScriptUtils.toScript(object);
+ }
- assertNotNull(testBean.getResultException());
+ public void setErrorMessage(String errorMessage) {
+ testBean.setErrorMessage(errorMessage);
+ }
- assertTrue(page.getWebClient().isJavaScriptEnabled());
- ScriptResult conversionErrorResult =
page.executeJavaScript("window.conversionError");
+ public void setObjectId(String objectId) {
+ testBean.setObjectId(objectId);
+ }
- if (ScriptResult.isUndefined(conversionErrorResult)) {
- fail("converter has not thrown an error");
- return;
- }
+ public void setClientFunction(String clientFunction) {
+ testBean.setClientFunction(clientFunction);
+ }
- Object conversionErrorMessage;
+ public void setAttribute(String name, Object value) {
+ testBean.setAttribute(name, value);
+ }
- Object scriptResult = conversionErrorResult.getJavaScriptResult();
- if (scriptResult instanceof Scriptable) {
- Scriptable scriptable = (Scriptable) scriptResult;
- conversionErrorMessage = scriptable.get("message", scriptable);
- } else {
- conversionErrorMessage = scriptResult;
- }
+ public void setSubmittedValue(String submittedValue) {
+ this.submittedValue = submittedValue;
+ }
- if (failureMessage != null) {
- assertEquals(failureMessage, conversionErrorMessage);
- } else {
- assertEquals(testBean.getResultException().getMessage(), conversionErrorMessage);
- }
- }
-
- public void assertValidationFailure() throws Exception {
- HtmlPage page = environment.getPage("/testValidator.jsf");
+ public void setFailureMessage(String failureMessage) {
+ this.failureMessage = failureMessage;
+ }
- assertNotNull(testBean.getResultException());
+ public void setErrorMessageEnums(Enum<?>... errorMessageEnums) {
+ testBean.setErrorMessageEnums(errorMessageEnums);
+ }
- assertTrue(page.getWebClient().isJavaScriptEnabled());
- ScriptResult validationErrorResult =
page.executeJavaScript("window.validationError");
+ 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());
+ }
+ }
- if (ScriptResult.isUndefined(validationErrorResult)) {
- fail("validator has not thrown an error");
- return;
- }
+ 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());
+ }
+ }
- Object validationErrorMessage;
+ public void assertConversionFailure() throws Exception {
+ HtmlPage page = environment.getPage("/testConverter.jsf");
- Object scriptResult = validationErrorResult.getJavaScriptResult();
- if (scriptResult instanceof Scriptable) {
- Scriptable scriptable = (Scriptable) scriptResult;
- validationErrorMessage = scriptable.get("message", scriptable);
- } else {
- validationErrorMessage = scriptResult;
- }
+ assertNotNull(testBean.getResultException());
- if (failureMessage != null) {
- assertEquals(failureMessage, validationErrorMessage);
- } else {
- assertEquals(testBean.getResultException().getMessage(), validationErrorMessage);
- }
- }
+ assertTrue(page.getWebClient().isJavaScriptEnabled());
+ ScriptResult conversionErrorResult =
page.executeJavaScript("window.conversionError");
- public void setup(TestData testData) {
- setSubmittedValue(testData.submittedValue());
- setFailureMessage(testData.failureMessage());
- }
+ 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());
+ }
+
}
Modified:
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 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BaseTestRunner.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -47,11 +47,11 @@
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;
@@ -62,7 +62,7 @@
if (testData == null) {
return "no test data";
}
-
+
StringBuilder sb = new StringBuilder();
if (failure) {
@@ -70,57 +70,56 @@
} 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;
+ 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 {
+ 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()) {
@@ -149,10 +148,10 @@
protected String testName(final FrameworkMethod method) {
if (method instanceof ParameterizedFrameworkMethod) {
String formattedParamsString = ((ParameterizedFrameworkMethod)
method).getFormattedParameters();
-
+
return String.format("%s %s", testMethodName,
formattedParamsString);
}
-
+
return testMethodName;
}
@@ -165,12 +164,12 @@
protected Statement classBlock(RunNotifier notifier) {
return childrenInvoker(notifier);
}
-
+
@Override
protected List<FrameworkMethod> getChildren() {
return children;
}
-
+
}
private final ArrayList<Runner> runners = new ArrayList<Runner>();
@@ -179,11 +178,11 @@
* Only called reflectively. Do not use programmatically.
*/
public BaseTestRunner(Class<?> klass) throws Throwable {
- super(klass, Collections.<Runner>emptyList());
-
+ super(klass, Collections.<Runner> emptyList());
+
TestClass testClass = getTestClass();
List<FrameworkMethod> testMethods =
testClass.getAnnotatedMethods(Test.class);
- for (FrameworkMethod testMethod: testMethods) {
+ for (FrameworkMethod testMethod : testMethods) {
runners.add(new ParameterizedTestRunner(klass, testMethod));
}
}
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
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/BooleanConverterTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -39,18 +39,9 @@
}
@Test
- @TestDataHolder(
- successes = {
- @TestData(submittedValue = "true"),
- @TestData(submittedValue = "True"),
- @TestData(submittedValue = "TRUE"),
- @TestData(submittedValue = "false"),
- @TestData(submittedValue = "0"),
- @TestData(submittedValue = "1"),
- @TestData(submittedValue = "")
- },
- failures = {}
- )
+ @TestDataHolder(successes = { @TestData(submittedValue = "true"),
@TestData(submittedValue = "True"),
+ @TestData(submittedValue = "TRUE"), @TestData(submittedValue =
"false"), @TestData(submittedValue = "0"),
+ @TestData(submittedValue = "1"), @TestData(submittedValue =
"") }, failures = {})
public void testSuccess() throws Exception {
setClientFunction("RichFaces.csv.getConverter('boolean')");
setObjectId(BooleanConverter.CONVERTER_ID);
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
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ByteConverterTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -39,22 +39,10 @@
}
@Test
- @TestDataHolder(
- successes = {
- @TestData(submittedValue = "-128"),
- @TestData(submittedValue = "0"),
- @TestData(submittedValue = "127")
- },
- failures = {
- @TestData(submittedValue = "-129"),
- @TestData(submittedValue = "128"),
- @TestData(submittedValue = "1.0"),
- @TestData(submittedValue = "1.2"),
- @TestData(submittedValue = "1a"),
- @TestData(submittedValue = "aaa"),
- @TestData(submittedValue = "- 127")
- }
- )
+ @TestDataHolder(successes = { @TestData(submittedValue = "-128"),
@TestData(submittedValue = "0"),
+ @TestData(submittedValue = "127") }, failures = {
@TestData(submittedValue = "-129"),
+ @TestData(submittedValue = "128"), @TestData(submittedValue =
"1.0"), @TestData(submittedValue = "1.2"),
+ @TestData(submittedValue = "1a"), @TestData(submittedValue =
"aaa"), @TestData(submittedValue = "- 127") })
public void testSuccess() throws Exception {
setClientFunction("RichFaces.csv.getConverter('byte')");
setObjectId(ByteConverter.CONVERTER_ID);
Modified:
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/ConverterTestRunner.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ConverterTestRunner.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -27,15 +27,15 @@
*/
public class ConverterTestRunner extends BaseTestRunner {
- public ConverterTestRunner(Class<?> klass) throws Throwable {
- super(klass);
- }
+ public ConverterTestRunner(Class<?> klass) throws Throwable {
+ super(klass);
+ }
- protected void checkResult (BaseTest baseTest, boolean failure) throws Throwable {
- if (failure) {
- baseTest.assertConversionFailure();
- } else {
- baseTest.assertConversionOk();
- }
- }
+ 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
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/DateTimeConverterTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -36,25 +36,21 @@
public DateTimeConverterTest() {
super("org/richfaces/convert/testConverter.js");
}
-
+
@Test
- @TestDataHolder(
- successes = {
- @TestData(submittedValue = "18-10-2010"),
- //@TestData(submittedValue = "17-10-2010")
- },
- failures = {
- //@TestData(submittedValue = "10/17/2010")
- }
- )
+ @TestDataHolder(successes = { @TestData(submittedValue = "18-10-2010"),
+ // @TestData(submittedValue = "17-10-2010")
+ }, failures = {
+ // @TestData(submittedValue = "10/17/2010")
+ })
public void testPattern() throws Exception {
setClientFunction("org.rf.DateTimeConverter");
setObjectId(DateTimeConverter.CONVERTER_ID);
setAttribute("pattern", "dd-MM-yyyy");
}
-
+
@Test
public void testNoPattern() throws Exception {
-
+
}
}
Modified:
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 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/LengthValidatorTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -39,18 +39,11 @@
}
@Test
- @TestDataHolder(
- successes = {
- @TestData(submittedValue = "dddd")
- },
- failures = {
- @TestData(submittedValue = "1234567890A")
- }
- )
+ @TestDataHolder(successes = { @TestData(submittedValue = "dddd") },
failures = { @TestData(submittedValue = "1234567890A") })
public void testSuccess() throws Exception {
- setClientFunction("RichFaces.csv.getValidator('length')");
+ setClientFunction("RichFaces.csv.getValidator('length')");
setObjectId(LengthValidator.VALIDATOR_ID);
- Enum<?>[] messages = {FacesMessages.LENGTH_VALIDATOR_MAXIMUM,
FacesMessages.LENGTH_VALIDATOR_MINIMUM};
+ 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
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/NumberConverterTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -39,18 +39,11 @@
}
@Test
- @TestDataHolder(
- successes = {
- @TestData(submittedValue = "111")
- },
- failures = {
- @TestData(submittedValue = "aaa")
- }
- )
+ @TestDataHolder(successes = { @TestData(submittedValue = "111") }, failures
= { @TestData(submittedValue = "aaa") })
public void testSuccess() throws Exception {
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
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ShortConverterTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -39,22 +39,10 @@
}
@Test
- @TestDataHolder(
- successes = {
- @TestData(submittedValue = "-32768"),
- @TestData(submittedValue = "0"),
- @TestData(submittedValue = "32767")
- },
- failures = {
- @TestData(submittedValue = "-32769"),
- @TestData(submittedValue = "32768"),
- @TestData(submittedValue = "1.0"),
- @TestData(submittedValue = "1.2"),
- @TestData(submittedValue = "1a"),
- @TestData(submittedValue = "aaa"),
- @TestData(submittedValue = "- 10")
- }
- )
+ @TestDataHolder(successes = { @TestData(submittedValue = "-32768"),
@TestData(submittedValue = "0"),
+ @TestData(submittedValue = "32767") }, failures = {
@TestData(submittedValue = "-32769"),
+ @TestData(submittedValue = "32768"), @TestData(submittedValue =
"1.0"), @TestData(submittedValue = "1.2"),
+ @TestData(submittedValue = "1a"), @TestData(submittedValue =
"aaa"), @TestData(submittedValue = "- 10") })
public void testSuccess() throws Exception {
setClientFunction("RichFaces.csv.getConverter('short')");
setObjectId(ShortConverter.CONVERTER_ID);
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
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestData.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -28,6 +28,7 @@
/**
* Test data annotation for {@link BaseTest}
+ *
* @author Nick Belaevski
*
*/
@@ -36,7 +37,7 @@
public @interface TestData {
public String submittedValue();
-
+
public String failureMessage() default "";
}
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestDataHolder.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestDataHolder.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/TestDataHolder.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -28,6 +28,7 @@
/**
* Holder element for multiple {@link TestData} elements
+ *
* @author Nick Belaevski
*
*/
@@ -36,7 +37,7 @@
public @interface TestDataHolder {
public TestData[] successes();
-
+
public TestData[] failures();
-
+
}
Modified:
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 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/convert/ValidatorTestRunner.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -27,15 +27,15 @@
*/
public class ValidatorTestRunner extends BaseTestRunner {
- public ValidatorTestRunner(Class<?> klass) throws Throwable {
- super(klass);
- }
+ public ValidatorTestRunner(Class<?> klass) throws Throwable {
+ super(klass);
+ }
- protected void checkResult (BaseTest baseTest, boolean failure) throws Throwable {
- if (failure) {
- baseTest.assertValidationFailure();
- } else {
- baseTest.assertValidationOk();
- }
- }
+ 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
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetComponentScriptTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -40,7 +40,7 @@
@RunWith(MockTestRunner.class)
public class RendererGetComponentScriptTest extends RendererTestBase {
- private static final String JSF_AJAX_REQUEST =
"jsf.ajax.request(this,event)";
+ private static final String JSF_AJAX_REQUEST =
"jsf.ajax.request(element,event)";
private static final String NUMBER_CONVERTER = "numConverter";
@@ -87,6 +87,7 @@
private void exceptGetAjaxScript() {
expect(mockBehavior.getAjaxScript(behaviorContext)).andReturn(JSF_AJAX_REQUEST);
+
expect(behaviorContext.getSourceId()).andStubReturn("clientValidator");
}
/**
Modified:
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java
===================================================================
---
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java 2010-11-01
19:48:34 UTC (rev 19861)
+++
branches/RF-8742/ui/validator/ui/src/test/java/org/richfaces/renderkit/html/RendererGetOrCreateResourceTest.java 2010-11-01
19:50:05 UTC (rev 19862)
@@ -25,6 +25,8 @@
public class RendererGetOrCreateResourceTest extends RendererTestBase {
private static final String FUNCTION_NAME = "inputValidate";
+
+ private static final String SOURCE_ID ="clientValidator";
@Mock
private UIViewRoot viewRoot;
@@ -105,7 +107,8 @@
};
};
setupBehaviorContext(input);
-
expect(validatorScript.createCallScript(FUNCTION_NAME)).andReturn(FUNCTION_NAME);
+ expect(behaviorContext.getSourceId()).andStubReturn(SOURCE_ID);
+
expect(validatorScript.createCallScript(FUNCTION_NAME,SOURCE_ID)).andReturn(FUNCTION_NAME);
expect(input.getClientId(facesContext)).andReturn(FUNCTION_NAME);
controller.replay();
assertEquals(FUNCTION_NAME,
renderer.buildAndStoreValidatorScript(behaviorContext, mockBehavior));