Author: lfryc(a)redhat.com
Date: 2011-01-23 15:29:41 -0500 (Sun, 23 Jan 2011)
New Revision: 21160
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
Removed:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeExpansion.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeModel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java
Log:
rich:tree - automated Simple sample - toggling capabilities (RFPL-935)
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java 2011-01-22
22:48:17 UTC (rev 21159)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java 2011-01-23
20:29:41 UTC (rev 21160)
@@ -3,17 +3,27 @@
import java.lang.reflect.Constructor;
import java.util.Iterator;
+import org.apache.commons.lang.ArrayUtils;
import org.jboss.test.selenium.locator.ExtendedLocator;
public class ModelIterable<E extends ExtendedLocator<E>, T extends
AbstractModel<E>> implements Iterable<T> {
Iterable<E> iterable;
Class<T> classT;
+ Class[] constructorParamTypes = new Class[] {};
+ Object[] constructorParams = new Object[] {};
public ModelIterable(Iterable<E> iterable, Class<T> classT) {
this.iterable = iterable;
this.classT = classT;
}
+
+ public ModelIterable(Iterable<E> iterable, Class<T> classT, Class[]
constructorParamTypes, Object[] constructorParams) {
+ this.iterable = iterable;
+ this.classT = classT;
+ this.constructorParamTypes = constructorParamTypes;
+ this.constructorParams = constructorParams;
+ }
@Override
public Iterator<T> iterator() {
@@ -34,10 +44,20 @@
ExtendedLocator<E> locator = iterator.next();
try {
- for (Constructor<?> constructor : classT.getConstructors()) {
+ constructorLoop: for (Constructor<?> constructor :
classT.getConstructors()) {
if
(ExtendedLocator.class.isAssignableFrom(constructor.getParameterTypes()[0])) {
- T newInstance = (T) constructor.newInstance(locator);
- return newInstance;
+ if (constructorParamTypes.length ==
constructor.getParameterTypes().length - 1) {
+ Object[] params = new Object[constructorParamTypes.length +
1];
+ for (int i = 0; i < constructorParamTypes.length; i++) {
+ if (constructorParamTypes[i] !=
constructor.getParameterTypes()[i+1]) {
+ continue constructorLoop;
+ }
+ params[i+1] = constructorParams[i];
+ }
+ params[0] = locator;
+ T newInstance = (T) constructor.newInstance(params);
+ return newInstance;
+ }
}
}
} catch (Exception e) {
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java 2011-01-22
22:48:17 UTC (rev 21159)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java 2011-01-23
20:29:41 UTC (rev 21160)
@@ -40,10 +40,6 @@
public AbstractTreeNodeModel(JQueryLocator root) {
super(root);
}
-
- public void setTree(TreeModel tree) {
- this.tree = tree;
- }
private AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
protected TreeModel tree;
@@ -57,32 +53,27 @@
ReferencedLocator<JQueryLocator> nodesExpanded = ref(root, "> " +
treeNodeExpanded.getRawLocator());
public Iterable<TreeNodeModel> getNodes() {
- Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(nodes.getAllOccurrences(), TreeNodeModel.class);
- for (TreeNodeModel trn : result) {
- trn.setTree(tree);
- }
+ Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(nodes.getAllOccurrences(),
+ TreeNodeModel.class, new Class[] { TreeModel.class }, new Object[] { tree
});
return result;
}
public TreeNodeModel getNode(int index) {
- TreeNodeModel trn = new TreeNodeModel(nodes.getNthOccurence(index));
- trn.setTree(tree);
+ TreeNodeModel trn = new TreeNodeModel(nodes.getNthOccurence(index), tree);
return trn;
}
public Iterable<TreeNodeModel> getExpandedNodes() {
- Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(nodesExpanded.getAllOccurrences(), TreeNodeModel.class);
- for (TreeNodeModel trn : result) {
- trn.setTree(tree);
- }
+ Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(
+ nodesExpanded.getAllOccurrences(), TreeNodeModel.class, new Class[] {
TreeModel.class },
+ new Object[] { tree });
return result;
}
public Iterable<TreeNodeModel> getCollapsedNodes() {
- Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(nodesCollapsed.getAllOccurrences(), TreeNodeModel.class);
- for (TreeNodeModel trn : result) {
- trn.setTree(tree);
- }
+ Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(
+ nodesCollapsed.getAllOccurrences(), TreeNodeModel.class, new Class[] {
TreeModel.class },
+ new Object[] { tree });
return result;
}
Deleted:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeExpansion.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeExpansion.java 2011-01-22
22:48:17 UTC (rev 21159)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeExpansion.java 2011-01-23
20:29:41 UTC (rev 21160)
@@ -1,135 +0,0 @@
-/*******************************************************************************
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- *******************************************************************************/
-package org.richfaces.tests.metamer.ftest.richTree;
-
-import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URL;
-import java.util.Deque;
-import java.util.LinkedList;
-
-import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
-import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
- * @version $Revision$
- */
-public class TestTreeExpansion extends AbstractMetamerTest {
-
- private static final int TOP_LEVEL_NODES = 4;
- private static final int DEPTH = 3;
-
- int[][] PATHS = new int[][] { { 3, 2, 1 }, { 2, 4, 1 } };
-
- private TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
- private TreeNodeModel treeNode;
-
- @Override
- public URL getTestUrl() {
- return buildUrl(contextPath,
"faces/components/richTree/simple.xhtml");
- }
-
- @BeforeMethod
- public void verifyInitialState() {
- assertEquals(tree.getCollapsedNodesCount(), TOP_LEVEL_NODES);
- assertEquals(tree.getExpandedNodesCount(), 0);
- }
-
- @Test
- public void testTopLevelNodesExpansion() {
- for (int i = 1; i <= TOP_LEVEL_NODES; i++) {
- treeNode = tree.getNode(i);
- treeNode.expand();
- assertEquals(tree.getCollapsedNodesCount(), TOP_LEVEL_NODES - i);
- assertEquals(tree.getExpandedNodesCount(), i);
- assertTrue(treeNode.isExpanded());
- }
- }
-
- @Test
- public void testTopLevelNodesCollapsion() {
- testTopLevelNodesExpansion();
- for (int i = 1; i <= TOP_LEVEL_NODES; i++) {
- treeNode = tree.getNode(i);
- treeNode.expand();
- assertEquals(tree.getCollapsedNodesCount(), i);
- assertEquals(tree.getExpandedNodesCount(), TOP_LEVEL_NODES - i);
- assertTrue(treeNode.isCollapsed());
- }
- }
-
- @Test
- @IssueTracking("https://issues.jboss.org/browse/RF-10264")
- public void testDeepExpansion() {
- for (int[] path : PATHS) {
- for (int d = 1; d <= path.length; d++) {
- int number = path[d - 1];
- treeNode = (d == 1) ? tree.getNode(number) : treeNode.getNode(number);
-
- if (d < DEPTH) {
- assertNodeState(NodeState.COLLAPSED);
- treeNode.expand();
- assertNodeState(NodeState.EXPANDED);
- } else {
- assertNodeState(NodeState.LEAF);
- }
- }
- }
- }
-
- @Test
- @IssueTracking("https://issues.jboss.org/browse/RF-10264")
- public void testDeepCollapsion() {
- Deque<TreeNodeModel> stack = new LinkedList<TreeNodeModel>();
-
- testDeepExpansion();
-
- for (TreeNodeModel treeNode1 : tree.getExpandedNodes()) {
- stack.push(treeNode1);
- for (TreeNodeModel treeNode2 : treeNode1.getExpandedNodes()) {
- stack.push(treeNode2);
- }
- }
-
- while ((treeNode = stack.poll()) != null) {
- treeNode.expand();
- }
- }
-
- public void assertNodeState(NodeState state) {
- assertEquals(treeNode.isLeaf() && treeNode.getIcon().isLeaf() &&
treeNode.getHandle().isLeaf(),
- state == NodeState.LEAF);
- assertEquals(treeNode.isCollapsed() && treeNode.getIcon().isCollapsed()
&& treeNode.getHandle().isCollapsed(),
- state == NodeState.COLLAPSED);
- assertEquals(treeNode.isExpanded() && treeNode.getIcon().isExpanded()
&& treeNode.getHandle().isExpanded(),
- state == NodeState.EXPANDED);
- }
-
- public enum NodeState {
- LEAF, COLLAPSED, EXPANDED;
- }
-}
Copied:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
(from rev 21159,
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeExpansion.java)
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java 2011-01-23
20:29:41 UTC (rev 21160)
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richTree;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URL;
+import java.util.Deque;
+import java.util.LinkedList;
+
+import org.richfaces.component.SwitchType;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestTreeToggling extends AbstractMetamerTest {
+
+ private static final int TOP_LEVEL_NODES = 4;
+ private static final int DEPTH = 3;
+
+ int[][] PATHS = new int[][] { { 3, 2, 1 }, { 2, 4, 1 } };
+
+ private TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=attributes]"));
+ private TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
+ private TreeNodeModel treeNode;
+
+ @Inject
+ @Use(enumeration = true)
+ SwitchType toggleType = SwitchType.ajax;
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richTree/simple.xhtml");
+ }
+
+ @BeforeMethod
+ public void verifyInitialState() {
+ treeAttributes.setToggleType(toggleType);
+ tree.setToggleType(toggleType);
+ assertEquals(tree.getCollapsedNodesCount(), TOP_LEVEL_NODES);
+ assertEquals(tree.getExpandedNodesCount(), 0);
+ }
+
+ @Test
+ public void testTopLevelNodesExpansion() {
+ for (int i = 1; i <= TOP_LEVEL_NODES; i++) {
+ treeNode = tree.getNode(i);
+ treeNode.expand();
+ assertEquals(tree.getCollapsedNodesCount(), TOP_LEVEL_NODES - i);
+ assertEquals(tree.getExpandedNodesCount(), i);
+ assertTrue(treeNode.isExpanded());
+ }
+ }
+
+ @Test
+ public void testTopLevelNodesCollapsion() {
+ testTopLevelNodesExpansion();
+ for (int i = 1; i <= TOP_LEVEL_NODES; i++) {
+ treeNode = tree.getNode(i);
+ treeNode.expand();
+ assertEquals(tree.getCollapsedNodesCount(), i);
+ assertEquals(tree.getExpandedNodesCount(), TOP_LEVEL_NODES - i);
+ assertTrue(treeNode.isCollapsed());
+ }
+ }
+
+ @Test
+ @IssueTracking("https://issues.jboss.org/browse/RF-10264")
+ public void testDeepExpansion() {
+ for (int[] path : PATHS) {
+ for (int d = 1; d <= path.length; d++) {
+ int number = path[d - 1];
+ treeNode = (d == 1) ? tree.getNode(number) : treeNode.getNode(number);
+
+ if (d < DEPTH) {
+ assertNodeState(NodeState.COLLAPSED);
+ treeNode.expand();
+ assertNodeState(NodeState.EXPANDED);
+ } else {
+ assertNodeState(NodeState.LEAF);
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testDeepCollapsion() {
+ Deque<TreeNodeModel> stack = new LinkedList<TreeNodeModel>();
+
+ testDeepExpansion();
+
+ for (TreeNodeModel treeNode1 : tree.getExpandedNodes()) {
+ stack.push(treeNode1);
+ for (TreeNodeModel treeNode2 : treeNode1.getExpandedNodes()) {
+ stack.push(treeNode2);
+ }
+ }
+
+ while ((treeNode = stack.poll()) != null) {
+ treeNode.expand();
+ }
+ }
+
+ public void assertNodeState(NodeState state) {
+ assertEquals(treeNode.isLeaf() && treeNode.getIcon().isLeaf() &&
treeNode.getHandle().isLeaf(),
+ state == NodeState.LEAF);
+ assertEquals(treeNode.isCollapsed() && treeNode.getIcon().isCollapsed()
&& treeNode.getHandle().isCollapsed(),
+ state == NodeState.COLLAPSED);
+ assertEquals(treeNode.isExpanded() && treeNode.getIcon().isExpanded()
&& treeNode.getHandle().isExpanded(),
+ state == NodeState.EXPANDED);
+ }
+
+ public enum NodeState {
+ LEAF, COLLAPSED, EXPANDED;
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeModel.java 2011-01-22
22:48:17 UTC (rev 21159)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeModel.java 2011-01-23
20:29:41 UTC (rev 21160)
@@ -30,12 +30,12 @@
*/
public class TreeModel extends AbstractTreeNodeModel {
- SwitchType toggleType;
- SwitchType selectionType;
+ SwitchType toggleType = SwitchType.ajax;
+ SwitchType selectionType = SwitchType.ajax;
public TreeModel(JQueryLocator root) {
super(root);
- this.setTree(this);
+ this.tree = this;
}
public void setToggleType(SwitchType toggleType) {
@@ -55,6 +55,6 @@
}
public TreeNodeModel getAnyNode() {
- return new TreeNodeModel(root.getLocator().getDescendant(treeNode));
+ return new TreeNodeModel(root.getLocator().getDescendant(treeNode), tree);
}
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java 2011-01-22
22:48:17 UTC (rev 21159)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java 2011-01-23
20:29:41 UTC (rev 21160)
@@ -21,6 +21,7 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richTree;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guard;
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
@@ -31,7 +32,9 @@
import org.jboss.test.selenium.locator.ExtendedLocator;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.locator.reference.ReferencedLocator;
+import org.jboss.test.selenium.request.RequestType;
import org.junit.Assert;
+import org.richfaces.component.SwitchType;
import org.richfaces.tests.metamer.ftest.model.AbstractModel;
import org.richfaces.tests.metamer.ftest.model.ModelIterable;
@@ -56,8 +59,9 @@
private ReferencedLocator<JQueryLocator> icon = ref(content, ">
.rf-trn-ico");
private ReferencedLocator<JQueryLocator> label = ref(content, ">
.rf-trn-lbl");
- public TreeNodeModel(JQueryLocator root) {
+ public TreeNodeModel(JQueryLocator root, TreeModel tree) {
super(root);
+ this.tree = tree;
}
public ExtendedLocator<JQueryLocator> getTreeNode() {
@@ -97,10 +101,21 @@
}
public void expand() {
- guardXhr(selenium).click(getHandle());
+ guard(selenium, getRequestType(tree.getToggleType())).click(getHandle());
}
public void select() {
guardXhr(selenium).clickAt(getLabel(), new Point(0,0));
}
+
+ private RequestType getRequestType(SwitchType switchType) {
+ switch (switchType) {
+ case ajax:
+ return RequestType.XHR;
+ case server:
+ return RequestType.HTTP;
+ default:
+ return RequestType.NONE;
+ }
+ }
}