[richfaces-svn-commits] JBoss Rich Faces SVN: r345 - trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Tue Apr 10 11:26:14 EDT 2007
Author: pkotikov
Date: 2007-04-10 11:26:14 -0400 (Tue, 10 Apr 2007)
New Revision: 345
Modified:
trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java
Log:
Update of tests.
Modified: trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java
===================================================================
--- trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java 2007-04-10 15:25:52 UTC (rev 344)
+++ trunk/richfaces/inputnumber-spinner/src/test/java/org/richfaces/component/InputNumberSpinnerComponentTest.java 2007-04-10 15:26:14 UTC (rev 345)
@@ -33,6 +33,10 @@
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlForm;
+import javax.faces.context.FacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.ValueBinding;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.apache.commons.lang.StringUtils;
@@ -163,11 +167,11 @@
//tests if component handles value bindings correctly
HtmlPage renderedView = renderView();
- String maxValue = ((UIInputNumberSpinner)spinner).getMaxValue();
+ String value = "66";
HtmlElement inputContainer = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext)+"Edit");
HtmlInput htmlSliderInput = (HtmlInput) inputContainer.getLastChild();
- htmlSliderInput.setValueAttribute(maxValue);
+ htmlSliderInput.setValueAttribute(value);
HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
htmlLink.click();
@@ -188,32 +192,72 @@
renderedView = renderView();
inputContainer = (HtmlElement) renderedView.getHtmlElementById(spinner.getClientId(facesContext)+"Edit");
htmlSliderInput = (HtmlInput) inputContainer.getLastChild();
- assertTrue( maxValue.equals(((UIInputNumberSpinner)spinner).getValue()) );
+ htmlSliderInput.setValueAttribute(value); assertTrue( value.equals(((UIInputNumberSpinner)spinner).getValue()) );
}
public void testDecode() throws Exception{
//Tests if component accepts request parameters and stores them in submittedValue().
//If component is immediate, validation (possibly with conversion) should occur on that phase.
+ final SpinnerBean bean = new SpinnerBean();
+ ((UIInputNumberSpinner)spinner).setValueBinding("value",
+ new ValueBinding() {
+ public Class getType(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return String.class;
+ }
+ public Object getValue(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return bean.getValue();
+ }
+ public boolean isReadOnly(FacesContext context) throws EvaluationException, PropertyNotFoundException {
+ return false;
+ }
+ public void setValue(FacesContext context, Object value) throws EvaluationException, PropertyNotFoundException {
+ bean.setValue((String)value);
+ }
+ });
HtmlPage renderedView = renderView();
HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
htmlLink.click();
- externalContext.addRequestParameterMap(spinner.getClientId(facesContext),((UIInputNumberSpinner)spinner).getMaxValue());
- UIViewRoot root = facesContext.getViewRoot();
- root.processDecodes(facesContext);
- UIInputNumberSpinner uiSpinner = (UIInputNumberSpinner) spinner;
- if (uiSpinner.isImmediate()){
- uiSpinner.validate(facesContext);
- assertTrue(uiSpinner.isValid());
- }
- assertTrue(externalContext.getRequestParameterMap().get(spinner.getClientId(facesContext)).equals(uiSpinner.getMaxValue()));
+ externalContext.addRequestParameterMap(spinner.getClientId(facesContext),"66");
+ spinner.processDecodes(facesContext);
+ assertTrue(bean.getValue().equals("66"));
+ ((UIInputNumberSpinner)spinner).setImmediate(true);
+ renderedView = renderView();
+ htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(spinner.getClientId(facesContext),"wrong value");
+ spinner.processDecodes(facesContext);
+ assertTrue(facesContext.getMessages().hasNext());
}
- public void testValidate(){
- // tests if component is able to handle submittedValue() correctly (convert & validate)
- UIInputNumberSpinner uispinner = (UIInputNumberSpinner) spinner;
- uispinner.validate(facesContext);
- assertTrue(uispinner.isValid());
+ public void testValidate() throws Exception{
+ HtmlPage renderedView = renderView();
+
+ HtmlAnchor htmlLink = (HtmlAnchor) renderedView.getHtmlElementById(command.getClientId(facesContext));
+ htmlLink.click();
+ externalContext.addRequestParameterMap(spinner.getClientId(facesContext),"wrong value");
+ spinner.processDecodes(facesContext);
+ spinner.processValidators(facesContext);
+
+ assertTrue(facesContext.getMessages().hasNext());
+
}
+
+ private class SpinnerBean {
+
+ private String value;
+
+ SpinnerBean (){
+ this.value = "66";
+ }
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ }
}
More information about the richfaces-svn-commits
mailing list