[richfaces-svn-commits] JBoss Rich Faces SVN: r321 - in trunk/richfaces/tree/src/test/java/org/richfaces/component: events and 1 other directory.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Sun Apr 8 18:19:53 EDT 2007
Author: nbelaevski
Date: 2007-04-08 18:19:52 -0400 (Sun, 08 Apr 2007)
New Revision: 321
Added:
trunk/richfaces/tree/src/test/java/org/richfaces/component/events/
trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java
Log:
Tests for TreeEvents class
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java 2007-04-08 22:19:52 UTC (rev 321)
@@ -0,0 +1,167 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.component.events;
+
+import javax.faces.application.Application;
+import javax.faces.component.UIViewRoot;
+import javax.faces.event.FacesEvent;
+
+import org.ajax4jsf.dnd.event.DragEvent;
+import org.ajax4jsf.dnd.event.DropEvent;
+import org.ajax4jsf.framework.ajax.AjaxViewRoot;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.ajax4jsf.tests.MockMethodBinding;
+import org.ajax4jsf.tests.MockViewRoot;
+import org.apache.commons.collections.Buffer;
+import org.richfaces.component.UITree;
+import org.richfaces.component.UITreeNode;
+
+/**
+ * @author Nick - mailto:nbelaevski at exadel.com
+ * created 08.04.2007
+ *
+ */
+public class TreeEventsTest extends AbstractAjax4JsfTestCase {
+
+ private static final String NODE = "node";
+ private UITree tree;
+ private UITreeNode treeNode;
+
+ public TreeEventsTest(String name) {
+ super(name);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+
+ tree = (UITree) application.createComponent(UITree.COMPONENT_TYPE);
+ tree.setNodeFace(NODE);
+ viewRoot.getChildren().add(tree);
+
+ treeNode = (UITreeNode) application.createComponent(UITreeNode.COMPONENT_TYPE);
+ treeNode.setType(NODE);
+
+ tree.getChildren().add(treeNode);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ this.tree = null;
+ this.treeNode = null;
+ }
+
+ public void testAjaxSelectedEvent() {
+ MockViewRoot mockViewRoot = (MockViewRoot) facesContext.getViewRoot();
+ tree.setAjaxSubmitSelection(true);
+ treeNode.setAjaxSubmitSelection("inherit");
+
+ MockMethodBinding binding = new MockMethodBinding();
+ treeNode.setNodeSelectListener(binding);
+
+ Buffer events = mockViewRoot.getAjaxEventsQueue(facesContext);
+ assertNotNull(events);
+ assertEquals(0, events.size());
+
+ AjaxSelectedEvent event = new AjaxSelectedEvent(treeNode);
+ TreeEvents.invokeListenerBindings(treeNode, event, facesContext);
+
+ assertEquals(1, events.size());
+
+ Object[][] args = binding.getInvocationArgs();
+ assertEquals(1, args.length);
+ assertEquals(1, args[0].length);
+ assertSame(event, args[0][0]);
+
+ events.clear();
+ binding.clear();
+
+ //now ajax events switched off
+ tree.setAjaxSubmitSelection(false);
+ assertNotNull(events);
+ assertEquals(0, events.size());
+ assertEquals(0, binding.getInvocationArgs().length);
+
+ event = new AjaxSelectedEvent(treeNode);
+ TreeEvents.invokeListenerBindings(treeNode, event, facesContext);
+
+ assertEquals(0, events.size());
+
+ args = binding.getInvocationArgs();
+ assertEquals(0, args.length);
+
+ }
+
+ public void testNodeExpansionEvent() {
+ MockMethodBinding binding = new MockMethodBinding();
+ treeNode.setChangeExpandListener(binding);
+
+ NodeExpandedEvent event = new NodeExpandedEvent(treeNode);
+ TreeEvents.invokeListenerBindings(treeNode, event, facesContext);
+
+ Object[][] args = binding.getInvocationArgs();
+ assertEquals(1, args.length);
+ assertEquals(1, args[0].length);
+ assertSame(event, args[0][0]);
+ }
+
+ public void testNodeSelectionEvent() {
+ MockMethodBinding binding = new MockMethodBinding();
+ treeNode.setNodeSelectListener(binding);
+
+ NodeSelectedEvent event = new NodeSelectedEvent(treeNode);
+ TreeEvents.invokeListenerBindings(treeNode, event, facesContext);
+
+ Object[][] args = binding.getInvocationArgs();
+ assertEquals(1, args.length);
+ assertEquals(1, args[0].length);
+ assertSame(event, args[0][0]);
+ }
+
+ public void testDropEvent() {
+ MockMethodBinding binding = new MockMethodBinding();
+ treeNode.setDropListener(binding);
+
+ DropEvent event = new DropEvent(treeNode);
+ TreeEvents.invokeListenerBindings(treeNode, event, facesContext);
+
+ Object[][] args = binding.getInvocationArgs();
+ assertEquals(1, args.length);
+ assertEquals(1, args[0].length);
+ assertSame(event, args[0][0]);
+ }
+
+ public void testDragEvent() {
+ MockMethodBinding binding = new MockMethodBinding();
+ treeNode.setDragListener(binding);
+
+ DragEvent event = new DragEvent(treeNode);
+ TreeEvents.invokeListenerBindings(treeNode, event, facesContext);
+
+ Object[][] args = binding.getInvocationArgs();
+ assertEquals(1, args.length);
+ assertEquals(1, args[0].length);
+ assertSame(event, args[0][0]);
+ }
+}
+
More information about the richfaces-svn-commits
mailing list