[richfaces-svn-commits] JBoss Rich Faces SVN: r4669 - branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Mon Dec 10 13:48:52 EST 2007
Author: sergeyhalipov
Date: 2007-12-10 13:48:52 -0500 (Mon, 10 Dec 2007)
New Revision: 4669
Modified:
branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java
Log:
http://jira.jboss.com/jira/browse/RF-1178
Modified: branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java
===================================================================
--- branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java 2007-12-10 17:37:02 UTC (rev 4668)
+++ branches/3.1.x/ui/listShuttle/src/test/java/org/richfaces/component/ListShuttleComponentTest.java 2007-12-10 18:48:52 UTC (rev 4669)
@@ -23,15 +23,21 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import javax.faces.application.FacesMessage;
import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
import javax.faces.el.EvaluationException;
import javax.faces.el.PropertyNotFoundException;
import javax.faces.el.ValueBinding;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
@@ -44,6 +50,7 @@
public class ListShuttleComponentTest extends AbstractAjax4JsfTestCase {
private UIForm form = null;
private UIListShuttle listShuttle = null;
+ private UIListShuttle listShuttle2 = null;
private ListShuttleBean sourceBean = null;
private ListShuttleBean targetBean = null;
private UICommand command = null;
@@ -128,11 +135,14 @@
});
form.getChildren().add(listShuttle);
+
+ listShuttle2 = (UIListShuttle)application.createComponent(UIListShuttle.COMPONENT_TYPE);
}
public void tearDown() throws Exception {
form = null;
listShuttle = null;
+ listShuttle2 = null;
sourceBean = null;
targetBean = null;
command = null;
@@ -153,15 +163,113 @@
HtmlAnchor anchor = (HtmlAnchor)view.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
anchor.click();
- externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "1sa,0");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "sa1:2");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "0:1");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), ":");
listShuttle.processDecodes(facesContext);
Object submittedValue = listShuttle.getSubmittedValue();
assertNotNull(submittedValue);
- assertTrue(submittedValue instanceof Object[]);
- assertEquals(2, ((Object[])submittedValue).length);
+ assertTrue(submittedValue instanceof UIListShuttle.SubmittedValue);
+ assertFalse(((UIListShuttle.SubmittedValue)submittedValue).isNull());
}
+ public void testDecodeImmediate() throws Exception {
+ listShuttle.setImmediate(true);
+ listShuttle.addValidator(new Validator() {
+
+ public void validate(FacesContext arg0, UIComponent arg1,
+ Object arg2) throws ValidatorException {
+ FacesMessage mess = new FacesMessage("Fake test message.");
+ throw new ValidatorException(mess);
+
+ }
+ });
+
+ HtmlPage view = renderView();
+ HtmlAnchor anchor = (HtmlAnchor)view.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
+ anchor.click();
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "sa1:2");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "0:1");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), ":");
+ listShuttle.processDecodes(facesContext);
+ assertTrue(facesContext.getMessages().hasNext());
+ }
+
+ /**
+ * Tests if component handles value bindings correctly
+ *
+ * @throws Exception
+ */
+ public void testUpdate() throws Exception {
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ HtmlAnchor anchor = (HtmlAnchor)page.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
+ anchor.click();
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "sa1:2");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), ":");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "0:1");
+ listShuttle.processDecodes(facesContext);
+ listShuttle.processValidators(facesContext);
+ listShuttle.processUpdates(facesContext);
+
+ assertNotNull(targetBean.getValue());
+ assertEquals(1, targetBean.getValue().size());
+ assertEquals("1", targetBean.getValue().get(0));
+ }
+
+ /**
+ * Tests if component handles validation correctly
+ *
+ * @throws Exception
+ */
+ public void testValidate() throws Exception {
+ listShuttle.addValidator(new Validator() {
+
+ public void validate(FacesContext arg0, UIComponent arg1,
+ Object arg2) throws ValidatorException {
+ FacesMessage mess = new FacesMessage("Fake test message.");
+ throw new ValidatorException(mess);
+
+ }
+
+ });
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+
+ HtmlAnchor anchor = (HtmlAnchor)page.getDocumentElement().getHtmlElementById(command.getClientId(facesContext));
+ anchor.click();
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "sa1:2");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), ":");
+ externalContext.addRequestParameterMap(listShuttle.getClientId(facesContext), "0:1");
+ listShuttle.processDecodes(facesContext);
+ listShuttle.processValidators(facesContext);
+ assertTrue(facesContext.getMessages().hasNext());
+
+ Object submittedValue = listShuttle.getSubmittedValue();
+ assertNotNull(submittedValue);
+ assertTrue(submittedValue instanceof UIListShuttle.SubmittedValue);
+ assertFalse(((UIListShuttle.SubmittedValue)submittedValue).isNull());
+ }
+
+ public void testSaveRestore() throws Exception {
+ List value = new ArrayList();
+ value.add("1");
+ listShuttle.setValueBinding("sourceValue", null);
+ listShuttle.setSourceValue(value);
+ assertEquals(value, listShuttle.getSourceValue());
+ assertNull(listShuttle.getValueBinding("value"));
+
+ Object state = listShuttle.saveState(facesContext);
+
+ listShuttle2.restoreState(facesContext, state);
+ Object value2 = listShuttle2.getSourceValue();
+ assertNotNull(value2);
+ assertEquals(value, value2);
+ }
+
protected class ListShuttleBean {
private List value = null;
More information about the richfaces-svn-commits
mailing list