Author: lfryc(a)redhat.com
Date: 2011-02-03 17:16:10 -0500 (Thu, 03 Feb 2011)
New Revision: 21440
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/RecursiveModelRepresentation.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorLazyLoading.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSelection.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSimple.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorToggling.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.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/TestTreeSelection.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
Log:
treeNode adaptors (RFPL-1053)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java 2011-02-03
21:22:09 UTC (rev 21439)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/RichTreeModelRecursiveAdaptorBean.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -24,7 +24,9 @@
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.PostConstruct;
@@ -54,6 +56,7 @@
private AtomicReference<Boolean> leafChildrenNullable = new
AtomicReference<Boolean>(true);
private boolean useMapModel;
private transient List<RecursiveNode> rootNodes;
+ private Map<String, Boolean> expanded = new TreeMap<String, Boolean>();
/*
* Nodes which was loaded lazily in the current request
@@ -119,4 +122,8 @@
public void setUseMapModel(boolean useMapModel) {
this.useMapModel = useMapModel;
}
+
+ public Map<String, Boolean> getExpanded() {
+ return expanded;
+ }
}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml 2011-02-03
21:22:09 UTC (rev 21439)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/treeAdaptors.xhtml 2011-02-03
22:16:10 UTC (rev 21440)
@@ -91,6 +91,9 @@
toggleNodeEvent="#{richTreeBean.attributes['toggleNodeEvent'].value}"
toggleType="#{richTreeBean.attributes['toggleType'].value}"
+ <rich:treeNode
expanded="#{richTreeModelRecursiveAdaptorBean.expanded[node.label]}">
+ #{node.label}
+ </rich:treeNode>
<rich:treeModelRecursiveAdaptor
roots="#{richTreeModelRecursiveAdaptorBean.rootNodes}"
@@ -99,6 +102,7 @@
<rich:treeNode
+
expanded="#{richTreeModelRecursiveAdaptorBean.expanded[node.label]}"
rendered="#{richTreeNodeBean.attributes[0]['rendered'].value
|| node.number != 1}"
iconLeaf="#{richTreeNodeBean.attributes[0]['iconLeaf'].value}"
iconExpanded="#{richTreeNodeBean.attributes[0]['iconExpanded'].value}"
@@ -137,6 +141,7 @@
rendered="#{richTreeModelRecursiveAdaptorBean.attributes['rendered'].value}">
<rich:treeNode
+
expanded="#{richTreeModelRecursiveAdaptorBean.expanded[node.label]}"
rendered="#{richTreeNodeBean.attributes[1]['rendered'].value
|| node.number != 1}"
iconLeaf="#{richTreeNodeBean.attributes[1]['iconLeaf'].value}"
iconExpanded="#{richTreeNodeBean.attributes[1]['iconExpanded'].value}"
@@ -162,7 +167,7 @@
<a4j:outputPanel ajaxRendered="true">
<h:panelGrid id="selectionOutput" columns="2">
<h:outputLabel value="Test Loading Facet:" />
- <h:selectBooleanCheckbox
value="#{richTreeBean.testLoadingFacet}">
+ <h:selectBooleanCheckbox id="loadingFacet"
value="#{richTreeBean.testLoadingFacet}">
<a4j:ajax render="#{nestedComponentId}" />
</h:selectBooleanCheckbox>
@@ -172,46 +177,46 @@
</h:selectBooleanCheckbox>
<h:outputLabel value="Recursive Leaf Children Nullable:" />
- <h:selectBooleanCheckbox
value="#{richTreeModelRecursiveAdaptorBean.leafChildrenNullable}">
- <a4j:ajax render="commonGrid" />
+ <h:selectBooleanCheckbox id="recursiveLeafChildrenNullable"
value="#{richTreeModelRecursiveAdaptorBean.leafChildrenNullable}">
+ <a4j:ajax render="#{nestedComponentId}" />
</h:selectBooleanCheckbox>
<h:outputLabel value="Recursive Model Representation:" />
- <h:selectOneRadio
value="#{richTreeModelRecursiveAdaptorBean.useMapModel}">
+ <h:selectOneRadio id="recursiveModelRepresentation"
value="#{richTreeModelRecursiveAdaptorBean.useMapModel}">
<f:selectItem itemLabel="List<RecursiveNode>"
itemValue="false" />
<f:selectItem itemLabel="Map<Integer,
RecursiveNode>" itemValue="true" />
- <a4j:ajax render="commonGrid" />
+ <a4j:ajax render="#{nestedComponentId}" />
</h:selectOneRadio>
<h:outputLabel value="Selection:" />
- <h:outputText value="#{richTreeBean.selection}" />
+ <h:outputText id="selection"
value="#{richTreeBean.selection}" />
<h:outputLabel value="Lazy Initialized:" />
- <h:outputText
value="#{richTreeModelRecursiveAdaptorBean.lazyInitializedNodes}" />
+ <h:outputText id="lazyInitialized"
value="#{richTreeModelRecursiveAdaptorBean.lazyInitializedNodes}" />
<h:outputLabel value="Selection Change Event:"
rendered="#{not empty richTreeListenerBean.treeSelectionChangeEvent}" />
<h:panelGrid columns="2" rendered="#{not empty
richTreeListenerBean.treeSelectionChangeEvent}">
<h:outputLabel value="Client ID:" />
- <h:outputText
value="#{richTreeListenerBean.treeSelectionChangeEvent.component.id}" />
+ <h:outputText id="selectionEventClientId"
value="#{richTreeListenerBean.treeSelectionChangeEvent.component.id}" />
<h:outputLabel value="New Selection:" />
- <h:outputText
value="#{richTreeListenerBean.treeSelectionChangeEvent.newSelection}" />
+ <h:outputText id="selectionEventNewSelection"
value="#{richTreeListenerBean.treeSelectionChangeEvent.newSelection}" />
<h:outputLabel value="Old Selection:" />
- <h:outputText
value="#{richTreeListenerBean.treeSelectionChangeEvent.oldSelection}" />
+ <h:outputText id="selectionEventOldSelection"
value="#{richTreeListenerBean.treeSelectionChangeEvent.oldSelection}" />
</h:panelGrid>
<h:outputLabel value="Tree Toggle Event:" rendered="#{not
empty richTreeListenerBean.treeToggleEvent}" />
<h:panelGrid columns="2" rendered="#{not empty
richTreeListenerBean.treeToggleEvent}">
<h:outputLabel value="Client ID:" />
- <h:outputText
value="#{richTreeListenerBean.treeToggleEvent.component.id}" />
+ <h:outputText id="toggleEventClientId"
value="#{richTreeListenerBean.treeToggleEvent.component.id}" />
<h:outputLabel value="Collapsed:" />
- <h:outputText
value="#{richTreeListenerBean.treeToggleEvent.collapsed}" />
+ <h:outputText id="toggleEventCollapsed"
value="#{richTreeListenerBean.treeToggleEvent.collapsed}" />
<h:outputLabel value="Expanded:" />
- <h:outputText
value="#{richTreeListenerBean.treeToggleEvent.expanded}" />
+ <h:outputText id="toggleEventExpanded"
value="#{richTreeListenerBean.treeToggleEvent.expanded}" />
</h:panelGrid>
</h:panelGrid>
</a4j:outputPanel>
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java 2011-02-03
21:22:09 UTC (rev 21439)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -62,6 +62,10 @@
public ExtendedLocator<JQueryLocator> getRoot() {
return root.getLocator();
}
+
+ public void setRoot(ExtendedLocator<JQueryLocator> root) {
+ this.root.setLocator(root);
+ }
protected String getProperty(String propertyName) {
final ElementLocator<?> locator = propertyLocator.format(propertyName,
"");
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.java 2011-02-03
21:22:09 UTC (rev 21439)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/MatrixConfigurator.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -353,14 +353,14 @@
Pattern pattern = Pattern.compile(namePattern);
if (pattern.matcher(field.getName()).matches()) {
boolean isArray = field.getType().isArray();
- Class<?> representedType;
- if (isArray) {
+ Class<?> representedType = field.getType();
+ if (!parameterType.isAssignableFrom(representedType) &&
isArray) {
representedType = field.getType().getComponentType();
} else {
- representedType = field.getType();
+ isArray = false;
}
if (parameterType.isAssignableFrom(representedType)) {
- Object[] assignments = getDeclaredFieldValues(testInstance,
field);
+ Object[] assignments = getDeclaredFieldValues(testInstance,
field, isArray);
for (Object assignment : assignments) {
result.add(assignment);
}
@@ -410,14 +410,14 @@
field.setAccessible(isAccessible);
}
- private Object[] getDeclaredFieldValues(Object testInstance, Field field) {
+ private Object[] getDeclaredFieldValues(Object testInstance, Field field, boolean
isArray) {
try {
boolean isAccessible = field.isAccessible();
if (!isAccessible) {
field.setAccessible(true);
}
Object[] result;
- if (field.getType().isArray()) {
+ if (isArray) {
result = (Object[]) field.get(testInstance);
} else {
result = new Object[] { field.get(testInstance) };
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-02-03
21:22:09 UTC (rev 21439)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -50,6 +50,7 @@
static JQueryLocator treeNodeSelected = jq("div.rf-tr-nd:has(> .rf-trn >
.rf-trn-sel)");
ReferencedLocator<JQueryLocator> nodes = ref(root, "> " +
treeNode.getRawLocator());
+ ReferencedLocator<JQueryLocator> anyNodes = ref(root,
treeNode.getRawLocator());
ReferencedLocator<JQueryLocator> nodesCollapsed = ref(root, "> " +
treeNodeCollapsed.getRawLocator());
ReferencedLocator<JQueryLocator> nodesExpanded = ref(root, "> " +
treeNodeExpanded.getRawLocator());
ReferencedLocator<JQueryLocator> anyNodesSelected = ref(root,
treeNodeSelected.getRawLocator());
@@ -60,6 +61,12 @@
return result;
}
+ public Iterable<TreeNodeModel> getAnyNodes() {
+ Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(anyNodes.getAllOccurrences(),
+ TreeNodeModel.class, new Class[] { TreeModel.class }, new Object[] { tree
});
+ return result;
+ }
+
public TreeNodeModel getNode(int index) {
TreeNodeModel trn = new TreeNodeModel(nodes.getNthOccurence(index), tree);
return trn;
@@ -78,13 +85,17 @@
new Object[] { tree });
return result;
}
-
+
public Iterable<TreeNodeModel> getAnySelectedNodes() {
Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(
anyNodesSelected.getAllOccurrences(), TreeNodeModel.class, new Class[] {
TreeModel.class },
new Object[] { tree });
return result;
}
+
+ public int getNodesCount() {
+ return selenium.getCount(nodes);
+ }
public int getExpandedNodesCount() {
return selenium.getCount(nodesExpanded);
@@ -93,7 +104,7 @@
public int getCollapsedNodesCount() {
return selenium.getCount(nodesCollapsed);
}
-
+
public int getAnySelectedNodesCount() {
return selenium.getCount(anyNodesSelected);
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java 2011-02-03
21:22:09 UTC (rev 21439)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -45,23 +45,24 @@
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
+@Use(field = "selectionPaths", value = "")
public class TestTreeSelection extends AbstractMetamerTest {
- Integer[][] SUBNODE_SELECTION_PATHS = new Integer[][] { { 2, 3 }, { 3, 4 }, { 4, 1, 1
}, { 4 }, { 4, 1 }, { 1, 5 },
- { 2, 3, 3 } };
+ protected Integer[][] selectionPaths = new Integer[][] { { 2, 3 }, { 3, 4 }, { 4, 1,
1 }, { 4 }, { 4, 1 },
+ { 1, 5 }, { 2, 3, 3 } };
@Override
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/richTree/simple.xhtml");
}
- private TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=attributes]"));
- private TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
- private TreeNodeModel treeNode;
+ protected TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=attributes]"));
+ protected TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
+ protected TreeNodeModel treeNode;
@Inject
@Use(value = "selectionTypes")
- SwitchType selectionType = SwitchType.ajax;
+ SwitchType selectionType = SwitchType.client;
SwitchType[] selectionTypes = new SwitchType[] { SwitchType.ajax, SwitchType.client
};
SwitchType[] eventEnabledSelectionTypes = new SwitchType[] { SwitchType.ajax };
@@ -94,10 +95,10 @@
@Test
public void testSubNodesSelection() {
- guardXhr(selenium).click(expandAll);
+ expandAll();
assertEquals(tree.getAnySelectedNodesCount(), 0);
- for (Integer[] path : SUBNODE_SELECTION_PATHS) {
+ for (Integer[] path : selectionPaths) {
treeNode = null;
for (int index : path) {
treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
@@ -112,10 +113,9 @@
@Test
@Use(field = "selectionType", value =
"eventEnabledSelectionTypes")
public void testSubNodesSelectionEvents() {
- guardXhr(selenium).click(expandAll);
-
+ expandAll();
Integer[] old = null;
- for (Integer[] path : SUBNODE_SELECTION_PATHS) {
+ for (Integer[] path : selectionPaths) {
treeNode = null;
for (int index : path) {
treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
@@ -133,6 +133,24 @@
}
}
+ protected void expandAll() {
+ guardXhr(selenium).click(expandAll);
+ }
+
+ protected Integer[] getIntsFromString(String string) {
+ Pattern pattern = Pattern.compile(".*\\[((?:(?:\\d+)(?:, )?)+)\\].*");
+ Matcher matcher = pattern.matcher(string);
+ if (matcher.find()) {
+ String[] strings = StringUtils.split(matcher.group(1), ", ");
+ Integer[] numbers = new Integer[strings.length];
+ for (int i = 0; i < strings.length; i++) {
+ numbers[i] = Integer.valueOf(strings[i]) + 1;
+ }
+ return numbers;
+ }
+ throw new IllegalStateException("pattern does not match");
+ }
+
private Integer[] getSelection() {
String string = selenium.getText(selection);
return getIntsFromString(string);
@@ -151,18 +169,4 @@
private String getClientId() {
return selenium.getText(clientId);
}
-
- private Integer[] getIntsFromString(String string) {
- Pattern pattern = Pattern.compile(".*\\[((?:(?:\\d+)(?:, )?)+)\\].*");
- Matcher matcher = pattern.matcher(string);
- if (matcher.find()) {
- String[] strings = StringUtils.split(matcher.group(1), ", ");
- Integer[] numbers = new Integer[strings.length];
- for (int i = 0; i < strings.length; i++) {
- numbers[i] = Integer.valueOf(strings[i]) + 1;
- }
- return numbers;
- }
- throw new IllegalStateException("pattern does not match");
- }
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java 2011-02-03
21:22:09 UTC (rev 21439)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -44,11 +44,10 @@
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 } };
+ int[][] PATHS = new int[][] { { 3, 2, 1, 2 }, { 2, 4, 6 } };
- private TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=attributes]"));
+ protected TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=attributes]"));
private TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
private TreeNodeModel treeNode;
@@ -95,11 +94,14 @@
@Test
public void testDeepExpansion() {
for (int[] path : PATHS) {
+ int depth = path.length;
+
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) {
+ if (d < depth) {
assertNodeState(NodeState.COLLAPSED);
treeNode.expand();
assertNodeState(NodeState.EXPANDED);
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/RecursiveModelRepresentation.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/RecursiveModelRepresentation.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/RecursiveModelRepresentation.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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.treeModelAdaptor;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public enum RecursiveModelRepresentation {
+ MAP, LIST;
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorLazyLoading.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorLazyLoading.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorLazyLoading.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * 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.treeModelAdaptor;
+
+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 java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.richTree.TreeAttributes;
+import org.richfaces.tests.metamer.ftest.richTree.TreeModel;
+import org.richfaces.tests.metamer.ftest.richTree.TreeNodeModel;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestTreeModelAdaptorLazyLoading extends AbstractMetamerTest {
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richTree/treeAdaptors.xhtml");
+ }
+
+ protected TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=treeAttributes]"));
+ protected TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
+ protected TreeNodeModel treeNode;
+
+ JQueryLocator lazyInitialized = pjq("span[id$=lazyInitialized]");
+
+ protected Integer[][] paths = new Integer[][] { { 1, 1, 1, 8, 1 }, { 4, 4, 11, 4 }
};
+
+ @Test
+ public void testLazyLoading() {
+ List<String> expected = getListOfVisibleNodes();
+ List<String> actual = getLazyInitialized();
+
+ assertEquals(actual, expected);
+
+ for (Integer[] path : paths) {
+ treeNode = null;
+ for (int i = 0; i < path.length; i++) {
+ int index = path[i];
+ treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
+ if (i < path.length - 1) {
+ treeNode.expand();
+
+ expected = getListOfVisibleNodes();
+ actual = getLazyInitialized();
+
+ assertEquals(actual, expected);
+ }
+ }
+ }
+ }
+
+ private List<String> getListOfVisibleNodes() {
+ // takes only recursive nodes + model node (representing leaves)
+ Pattern pattern = Pattern.compile("([RM\\-\\.0-9]+)(?:-.*)?");
+ SortedSet<String> result = new TreeSet<String>();
+ for (TreeNodeModel treeNode : tree.getAnyNodes()) {
+ String labelText = treeNode.getLabelText();
+
+ Matcher matcher = pattern.matcher(labelText);
+
+ if (matcher.matches()) {
+ String node = matcher.group(1);
+ result.add(node);
+ }
+ }
+ return new LinkedList<String>(result);
+ }
+
+ private List<String> getLazyInitialized() {
+ String unseparated = selenium.getText(lazyInitialized);
+ String[] separated = StringUtils.split(unseparated, "[], ");
+ List<String> result = Arrays.asList(separated);
+ Collections.sort(result);
+ return result;
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSelection.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSelection.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSelection.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * 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.treeModelAdaptor;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.annotations.Uses;
+import org.richfaces.tests.metamer.ftest.richTree.TestTreeSelection;
+import org.richfaces.tests.metamer.ftest.richTree.TreeAttributes;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestTreeModelAdaptorSelection extends TestTreeSelection {
+
+ @Inject
+ PathsCrate paths;
+ PathsCrate pathsForListModel = new PathsCrate("listModel", new Integer[][]
{ { 2, 1, 3 }, { 3, 3, 2, 2 } });
+ PathsCrate pathsForMapModel = new PathsCrate("mapModel", new Integer[][] {
{ 2, 1, 5 }, { 3, 3, 2, 6 } });
+ PathsCrate pathsForRecursiveModel = new PathsCrate("recursiveModel", new
Integer[][] { { 4, 1, 10, 2 },
+ { 1, 4, 3, 11, 4, 1 } });
+
+ @Inject
+ @Use(enumeration = true)
+ public RecursiveModelRepresentation representation =
RecursiveModelRepresentation.LIST;
+
+ @Inject
+ @Use(booleans = { true, false })
+ public boolean recursiveLeafChildrenNullable;
+
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"http://localhost:8080/metamer/faces/components/richTree/treeAdaptors.xhtml");
+ }
+
+ @BeforeClass
+ public void initTreeAttributes() {
+ treeAttributes = new TreeAttributes(jq("span[id*=treeAttributes]"));
+ }
+
+ @BeforeMethod
+ public void initPathsAndModelRepresentation() {
+ if (paths != null) {
+ selectionPaths = paths.paths;
+ }
+ if (representation == RecursiveModelRepresentation.MAP) {
+
guardXhr(selenium).click(pjq(":radio[id*=recursiveModelRepresentation]").getNthOccurence(2));
+ }
+ if (recursiveLeafChildrenNullable) {
+
guardXhr(selenium).click(pjq(":checkbox[id$=recursiveLeafChildrenNullable]"));
+ }
+ }
+
+ @Test
+ @Override
+ @Use(field = "paths", empty = true)
+ public void testTopLevelSelection() {
+ super.testTopLevelSelection();
+ }
+
+ @Test
+ @Override
+ @Use(field = "paths", value = "paths*")
+ public void testSubNodesSelection() {
+ super.testSubNodesSelection();
+ }
+
+ @Test
+ @Override
+ @Uses({ @Use(field = "paths", value = "paths*"),
+ @Use(field = "selectionType", value =
"eventEnabledSelectionTypes") })
+ public void testSubNodesSelectionEvents() {
+ super.testSubNodesSelectionEvents();
+ }
+
+ @Override
+ protected void expandAll() {
+ for (Integer[] path : selectionPaths) {
+ treeNode = null;
+ for (int i = 0; i < path.length; i++) {
+ int index = path[i];
+ treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
+ if (i < path.length - 1) {
+ treeNode.expand();
+ }
+ }
+ }
+ }
+
+ @Override
+ protected Integer[] getIntsFromString(String string) {
+ Pattern pattern = Pattern.compile("(?:\\{[^}]+modelKey=(\\d+)\\})");
+ Matcher matcher = pattern.matcher(string);
+ List<Integer> list = new LinkedList<Integer>();
+ while (matcher.find()) {
+ int integer = Integer.valueOf(matcher.group(1)) + 1;
+ integer = fixShiftWhenModelPresent(list, integer);
+ list.add(integer);
+ }
+ if (list.isEmpty()) {
+ throw new IllegalStateException("pattern does not match");
+ }
+ return list.toArray(new Integer[list.size()]);
+ }
+
+ private Integer fixShiftWhenModelPresent(List<Integer> list, int integer) {
+ if (paths.toString().equals(pathsForRecursiveModel.toString())) {
+ if (!list.isEmpty()) {
+ if (list.get(0) % 2 == 0) {
+ if (list.size() == 2) {
+ return integer + 7;
+ }
+ } else {
+ if (list.size() == 3) {
+ return integer + 7;
+ }
+ }
+ }
+ }
+ return integer;
+ }
+
+ private class PathsCrate {
+ String name;
+ Integer[][] paths;
+
+ public PathsCrate(String name, Integer[][] paths) {
+ this.name = name;
+ this.paths = paths;
+ }
+
+ public String toString() {
+ return name;
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSimple.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSimple.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorSimple.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.treeModelAdaptor;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.ExtendedLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.richTree.TreeAttributes;
+import org.richfaces.tests.metamer.ftest.richTree.TreeModel;
+import org.richfaces.tests.metamer.ftest.richTree.TreeNodeModel;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestTreeModelAdaptorSimple extends AbstractMetamerTest {
+
+ protected TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=treeAttributes]"));
+ protected TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
+ protected TreeNodeModel treeNode;
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richTree/treeAdaptors.xhtml");
+ }
+
+ @Test
+ public void testModelAdaptorRendered() {
+ tree.getNode(2).expand();
+ tree.getNode(2).getNode(2).expand();
+ treeNode = tree.getNode(2).getNode(2).getNode(1);
+
+ assertTrue(treeNode.isLeaf());
+
+ modelAdaptorAttributes.setRendered(false);
+
+ assertFalse(treeNode.isLeaf());
+ }
+
+ @Test
+ public void testRecursiveModelAdaptorRendered() {
+ tree.getNode(2).expand();
+ tree.getNode(2).getNode(2).expand();
+
+ boolean subnodePresent = false;
+ for (TreeNodeModel treeNode : tree.getNode(2).getNode(2).getNodes()) {
+ if (!treeNode.isLeaf()) {
+ subnodePresent = true;
+ }
+ }
+ assertTrue(subnodePresent, "there should be at least one subnode (not leaf)
in expanded branch");
+
+ recursiveModelAdaptorAttributes.setRendered(false);
+
+ for (TreeNodeModel treeNode : tree.getNode(2).getNode(2).getNodes()) {
+ if (!treeNode.isLeaf()) {
+ fail("there should be no subnode (not leaf) in expanded
branch");
+ }
+ }
+ }
+
+ private ModelAdaptorAttributes modelAdaptorAttributes = new ModelAdaptorAttributes(
+ pjq("span[id$=:listAttributes:panel]"));
+ private RecursiveModelAdaptorAttributes recursiveModelAdaptorAttributes = new
RecursiveModelAdaptorAttributes(
+ pjq("span[id$=:recursiveAttributes:panel]"));
+
+ private class ModelAdaptorAttributes extends AbstractComponentAttributes {
+
+ public <T extends ExtendedLocator<JQueryLocator>>
ModelAdaptorAttributes(T root) {
+ super(root);
+ }
+
+ public void setRendered(Boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+ }
+
+ private class RecursiveModelAdaptorAttributes extends AbstractComponentAttributes {
+
+ public <T extends ExtendedLocator<JQueryLocator>>
RecursiveModelAdaptorAttributes(T root) {
+ super(root);
+ }
+
+ public void setRendered(Boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorToggling.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorToggling.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/treeModelAdaptor/TestTreeModelAdaptorToggling.java 2011-02-03
22:16:10 UTC (rev 21440)
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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.treeModelAdaptor;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.richTree.TestTreeToggling;
+import org.richfaces.tests.metamer.ftest.richTree.TreeAttributes;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestTreeModelAdaptorToggling extends TestTreeToggling {
+
+ @Inject
+ @Use(enumeration = true)
+ public RecursiveModelRepresentation representation;
+
+ @Inject
+ @Use(booleans = { true, false })
+ public boolean recursiveLeafChildrenNullable;
+
+ @BeforeClass
+ public void initTreeAttributes() {
+ treeAttributes = new TreeAttributes(jq("span[id*=treeAttributes]"));
+ }
+
+ @BeforeMethod
+ public void initPathsAndModelRepresentation() {
+ if (representation == RecursiveModelRepresentation.MAP) {
+
guardXhr(selenium).click(pjq(":radio[id*=recursiveModelRepresentation]").getNthOccurence(2));
+ }
+ if (recursiveLeafChildrenNullable) {
+
guardXhr(selenium).click(pjq(":checkbox[id$=recursiveLeafChildrenNullable]"));
+ }
+ }
+
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"http://localhost:8080/metamer/faces/components/richTree/treeAdaptors.xhtml");
+ }
+
+ @Test
+ @Override
+ public void testTopLevelNodesExpansion() {
+ super.testTopLevelNodesExpansion();
+ }
+
+ @Test
+ @Override
+ public void testTopLevelNodesCollapsion() {
+ super.testTopLevelNodesCollapsion();
+ }
+
+ @Test
+ @Override
+ public void testDeepExpansion() {
+ super.testDeepExpansion();
+ }
+
+ @Test
+ @Override
+ public void testDeepCollapsion() {
+ super.testDeepCollapsion();
+ }
+}