[richfaces-svn-commits] JBoss Rich Faces SVN: r330 - 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
Mon Apr 9 16:02:27 EDT 2007
Author: nbelaevski
Date: 2007-04-09 16:02:27 -0400 (Mon, 09 Apr 2007)
New Revision: 330
Added:
trunk/richfaces/tree/src/test/java/org/richfaces/component/ListRowKeyTest.java
trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsListenersTest.java
Modified:
trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java
Log:
Tree unit tests updated & created
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/ListRowKeyTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/ListRowKeyTest.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/ListRowKeyTest.java 2007-04-09 20:02:27 UTC (rev 330)
@@ -0,0 +1,134 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski at exadel.com
+ * created 09.04.2007
+ *
+ */
+public class ListRowKeyTest extends TestCase {
+
+ public void testConstructors() {
+ ListRowKey key = new ListRowKey();
+
+ assertEquals(0, key.depth());
+ assertEquals(0, key.getPath().length());
+
+ List list = new LinkedList();
+ list.add(new Long(2));
+ list.add(new Long(4));
+
+ key = new ListRowKey(list);
+
+ assertEquals(2, key.depth());
+ Iterator iterator = key.iterator();
+ assertTrue(iterator.hasNext());
+ assertEquals(new Long(2), iterator.next());
+
+ assertTrue(iterator.hasNext());
+ assertEquals(new Long(4), iterator.next());
+
+ assertFalse(iterator.hasNext());
+
+ key = new ListRowKey(new Long(5));
+ assertEquals(1, key.depth());
+ iterator = key.iterator();
+ assertTrue(iterator.hasNext());
+ assertEquals(new Long(5), iterator.next());
+
+ assertFalse(iterator.hasNext());
+
+ key = new ListRowKey(new ListRowKey(new Long(6)), new Long(7));
+ assertEquals(2, key.depth());
+ iterator = key.iterator();
+ assertTrue(iterator.hasNext());
+ assertEquals(new Long(6), iterator.next());
+
+ assertTrue(iterator.hasNext());
+ assertEquals(new Long(7), iterator.next());
+
+ assertFalse(iterator.hasNext());
+
+ key = new ListRowKey(key);
+ assertEquals(2, key.depth());
+ iterator = key.iterator();
+ assertTrue(iterator.hasNext());
+ assertEquals(new Long(6), iterator.next());
+
+ assertTrue(iterator.hasNext());
+ assertEquals(new Long(7), iterator.next());
+
+ assertFalse(iterator.hasNext());
+
+ key = new ListRowKey("12_:34:56__78_:9");
+ assertEquals(2, key.depth());
+ iterator = key.iterator();
+ assertTrue(iterator.hasNext());
+ assertEquals("12:34", iterator.next());
+
+ assertTrue(iterator.hasNext());
+ assertEquals("56_78:9", iterator.next());
+
+ assertFalse(iterator.hasNext());
+
+
+ key = new ListRowKey("12_:34:56__78_:9:");
+ assertEquals(2, key.depth());
+ iterator = key.iterator();
+ assertTrue(iterator.hasNext());
+ assertEquals("12:34", iterator.next());
+
+ assertTrue(iterator.hasNext());
+ assertEquals("56_78:9", iterator.next());
+
+ assertFalse(iterator.hasNext());
+ }
+
+ public void testObjectMethods() {
+ String[] data = new String[] {
+ "test1", "test:2", "test3"
+ };
+
+ ListRowKey key1 = new ListRowKey(Arrays.asList(data));
+
+ ListRowKey key2 = new ListRowKey();
+ for (int i = 0; i < data.length; i++) {
+ String string = data[i];
+
+ key2 = new ListRowKey(key2, string);
+ }
+
+ assertTrue(key1.hashCode() == key2.hashCode());
+ assertTrue(key1.equals(key2));
+ assertTrue(key1.toString().equals(key2.toString()));
+ }
+}
Added: trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsListenersTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsListenersTest.java (rev 0)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsListenersTest.java 2007-04-09 20:02:27 UTC (rev 330)
@@ -0,0 +1,114 @@
+/**
+ * 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.component.UIComponentBase;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Nick Belaevski - nbelaevski at exadel.com
+ * created 09.04.2007
+ *
+ */
+public class TreeEventsListenersTest extends TestCase {
+ private UIComponentBase source;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ source = new UIComponentBase() {
+
+ public String getFamily() {
+ return null;
+ }};
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ this.source = null;
+ }
+
+ public void testNodeExpandedListener() {
+ NodeExpandedEvent event = new NodeExpandedEvent(source);
+
+ ExpandListener listener = new ExpandListener();
+
+ assertTrue(event.isAppropriateListener(listener));
+ assertFalse(event.isAppropriateListener(new FacesListener(){
+
+ }));
+
+ event.processListener(listener);
+
+ assertSame(event, listener.getEvent());
+ }
+
+ public void testNodeSelectedListener() {
+ NodeSelectedEvent event = new NodeSelectedEvent(source);
+
+ SelectListener listener = new SelectListener();
+
+ assertTrue(event.isAppropriateListener(listener));
+ assertFalse(event.isAppropriateListener(new FacesListener(){
+
+ }));
+
+ event.processListener(listener);
+
+ assertSame(event, listener.getEvent());
+ }
+}
+
+class ExpandListener implements NodeExpandedListener {
+
+ private FacesEvent event;
+
+ public void processExpansion(NodeExpandedEvent nodeExpandedEvent)
+ throws AbortProcessingException {
+
+ event = nodeExpandedEvent;
+ }
+
+ public FacesEvent getEvent() {
+ return event;
+ }
+}
+
+class SelectListener implements NodeSelectedListener {
+
+ private FacesEvent event;
+
+ public void processSelection(NodeSelectedEvent nodeSelectedEvent)
+ throws AbortProcessingException {
+
+ event = nodeSelectedEvent;
+ }
+
+ public FacesEvent getEvent() {
+ return event;
+ }
+}
\ No newline at end of file
Modified: trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java
===================================================================
--- trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java 2007-04-09 20:01:56 UTC (rev 329)
+++ trunk/richfaces/tree/src/test/java/org/richfaces/component/events/TreeEventsTest.java 2007-04-09 20:02:27 UTC (rev 330)
@@ -21,13 +21,13 @@
package org.richfaces.component.events;
-import javax.faces.application.Application;
import javax.faces.component.UIViewRoot;
+import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
+import javax.faces.event.FacesListener;
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;
@@ -71,6 +71,26 @@
this.treeNode = null;
}
+ public void testPassThroughGenericEvent() {
+ //just to be sure generic events pass through ok
+ TreeEvents.invokeListenerBindings(treeNode, new FacesEvent(treeNode) {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 2196096358111753037L;
+
+ public boolean isAppropriateListener(FacesListener listener) {
+ return false;
+ }
+
+ public void processListener(FacesListener listener) {
+ throw new AbortProcessingException();
+ }
+
+ }, facesContext);
+ }
+
public void testAjaxSelectedEvent() {
MockViewRoot mockViewRoot = (MockViewRoot) facesContext.getViewRoot();
tree.setAjaxSubmitSelection(true);
@@ -92,26 +112,31 @@
assertEquals(1, args.length);
assertEquals(1, args[0].length);
assertSame(event, args[0][0]);
+ }
- events.clear();
- binding.clear();
+ public void testAjaxSelectedEventListenersOff() {
+ MockViewRoot mockViewRoot = (MockViewRoot) facesContext.getViewRoot();
+ tree.setAjaxSubmitSelection(false);
+ treeNode.setAjaxSubmitSelection("inherit");
- //now ajax events switched off
- tree.setAjaxSubmitSelection(false);
+ MockMethodBinding binding = new MockMethodBinding();
+ treeNode.setNodeSelectListener(binding);
+
+ Buffer events = mockViewRoot.getAjaxEventsQueue(facesContext);
assertNotNull(events);
assertEquals(0, events.size());
assertEquals(0, binding.getInvocationArgs().length);
- event = new AjaxSelectedEvent(treeNode);
+ AjaxSelectedEvent event = new AjaxSelectedEvent(treeNode);
TreeEvents.invokeListenerBindings(treeNode, event, facesContext);
+ assertNotNull(events);
assertEquals(0, events.size());
-
- args = binding.getInvocationArgs();
- assertEquals(0, args.length);
-
+ assertEquals(0, binding.getInvocationArgs().length);
}
+
+
public void testNodeExpansionEvent() {
MockMethodBinding binding = new MockMethodBinding();
treeNode.setChangeExpandListener(binding);
More information about the richfaces-svn-commits
mailing list