Author: ppitonak(a)redhat.com
Date: 2012-01-05 13:17:39 -0500 (Thu, 05 Jan 2012)
New Revision: 23132
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTreeSelection.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTree.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/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java
Log:
tests for rich:tree refactored
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTree.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTree.java 2012-01-05
15:07:31 UTC (rev 23131)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTree.java 2012-01-05
18:17:39 UTC (rev 23132)
@@ -1,6 +1,6 @@
/*******************************************************************************
* JBoss, Home of Professional Open Source
- * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * Copyright 2010-2012, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -32,15 +32,14 @@
/**
* @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
*/
-public class AbstractTestTree extends AbstractMetamerTest {
+public abstract class AbstractTestTree extends AbstractMetamerTest {
@Inject
- @Use(strings = {"simpleSwingTreeNode", "simpleRichFacesTreeNode",
"simpleRichFacesTreeDataModel"})
+ @Use(strings = { "simpleSwingTreeNode",
"simpleRichFacesTreeNode", "simpleRichFacesTreeDataModel" })
private String sample;
@Override
public URL getTestUrl() {
return buildUrl(contextPath, "faces/components/richTree/" + sample +
".xhtml");
}
-
}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTreeSelection.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTreeSelection.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTestTreeSelection.java 2012-01-05
18:17:39 UTC (rev 23132)
@@ -0,0 +1,174 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2012, 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.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.richfaces.tests.metamer.ftest.attributes.AttributeList.treeAttributes;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Arrays;
+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.jboss.test.selenium.utils.text.SimplifiedFormat;
+import org.richfaces.component.SwitchType;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.testng.annotations.BeforeMethod;
+
+/**
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ */
+public abstract class AbstractTestTreeSelection extends AbstractTestTree {
+
+ @Inject
+ @Use(value = "selectionTypes")
+ protected SwitchType selectionType;
+
+ protected SwitchType[] selectionTypes = new SwitchType[] { SwitchType.ajax,
SwitchType.client };
+ protected SwitchType[] selectionTypeAjax = new SwitchType[] { SwitchType.ajax };
+ protected SwitchType[] selectionTypeClient = new SwitchType[] { SwitchType.client };
+ protected SwitchType[] eventEnabledSelectionTypes = new SwitchType[] {
SwitchType.ajax };
+
+ protected TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
+ protected TreeNodeModel treeNode;
+
+ protected Integer[][] selectionPaths = new Integer[][] { { 4, 3 }, { 2, 1, 1 }, { 2
}, { 4, 10, 3 } };
+
+ private JQueryLocator expandAll = jq("input:submit[id$=expandAll]");
+ private JQueryLocator selection = jq("span[id$=selection]");
+ private JQueryLocator clientId = jq("span[id$=selectionEventClientId]");
+ private JQueryLocator newSelection =
jq("span[id$=selectionEventNewSelection]");
+ private JQueryLocator oldSelection =
jq("span[id$=selectionEventOldSelection]");
+
+ @BeforeMethod
+ public void testInitialize() {
+ treeAttributes.set(TreeAttributes.selectionType, selectionType);
+ tree.setSelectionType(selectionType);
+ }
+
+ protected void testTopLevelSelection() {
+ assertEquals(tree.getAnySelectedNodesCount(), 0);
+
+ for (TreeNodeModel treeNode : tree.getNodes()) {
+ assertFalse(treeNode.isSelected());
+ assertTrue(treeNode.isCollapsed());
+ treeNode.select();
+ assertTrue(treeNode.isSelected());
+ assertTrue(treeNode.isCollapsed());
+
+ assertEquals(tree.getAnySelectedNodesCount(), 1);
+ }
+ }
+
+ protected void testSubNodesSelection() {
+ expandAll();
+ assertEquals(tree.getAnySelectedNodesCount(), 0);
+
+ for (Integer[] path : selectionPaths) {
+ treeNode = null;
+ for (int index : path) {
+ treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
+ }
+ assertFalse(treeNode.isSelected());
+ treeNode.select();
+ assertTrue(treeNode.isSelected());
+ assertEquals(tree.getAnySelectedNodesCount(), 1);
+ }
+ }
+
+ protected void testSubNodesSelectionEvents() {
+ expandAll();
+ Integer[] old = null;
+ for (Integer[] path : selectionPaths) {
+ treeNode = null;
+ for (int index : path) {
+ treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
+ }
+ treeNode.select();
+ assertEquals(getClientId(), "richTree");
+ assertEquals(
+ getSelection(),
+ path,
+ SimplifiedFormat.format("Actual Selection ({0}) doesn't
correspond to expected ({1})",
+ Arrays.deepToString(getSelection()), Arrays.deepToString(path)));
+ assertEquals(
+ getNewSelection(),
+ path,
+ SimplifiedFormat.format("Actual New selection ({0}) doesn't
correspond to expected ({1})",
+ Arrays.deepToString(getNewSelection()), Arrays.deepToString(path)));
+ if (old != null) {
+ assertEquals(
+ getOldSelection(),
+ old,
+ SimplifiedFormat.format("Actual Old selection ({0}) doesn't
correspond to expected ({1})",
+ Arrays.deepToString(getOldSelection()),
Arrays.deepToString(old)));
+ } else {
+ assertEquals(selenium.getText(oldSelection), "[]");
+ }
+ old = getNewSelection();
+ }
+ }
+
+ protected Integer[] getSelection() {
+ String string = selenium.getText(selection);
+ return getIntsFromString(string);
+ }
+
+ protected Integer[] getNewSelection() {
+ String string = selenium.getText(newSelection);
+ return getIntsFromString(string);
+ }
+
+ protected Integer[] getOldSelection() {
+ String string = selenium.getText(oldSelection);
+ return getIntsFromString(string);
+ }
+
+ protected String getClientId() {
+ return selenium.getText(clientId);
+ }
+
+ 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");
+ }
+
+ protected void expandAll() {
+ guardXhr(selenium).click(expandAll);
+ }
+}
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 2012-01-05
15:07:31 UTC (rev 23131)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java 2012-01-05
18:17:39 UTC (rev 23132)
@@ -21,209 +21,78 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richTree;
-import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
-import static org.jboss.test.selenium.locator.LocatorFactory.jq;
import static org.richfaces.tests.metamer.ftest.attributes.AttributeList.treeAttributes;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import java.util.Arrays;
-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.jboss.test.selenium.utils.text.SimplifiedFormat;
import org.richfaces.component.SwitchType;
+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.richfaces.tests.metamer.ftest.annotations.Uses;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
- * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a> *
@author <a href="mailto:ppitonak@redhat.com">Pavol
+ * Pitonak</a>
* @version $Revision$
*/
-@Use(field = "selectionPaths", value = "")
-public class TestTreeSelection extends AbstractTestTree {
+public class TestTreeSelection extends AbstractTestTreeSelection {
- protected Integer[][] selectionPaths = new Integer[][] { { 4, 3 }, { 2, 1, 1 }, { 2
}, { 4, 10, 3 } };
-
- protected TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
- protected TreeNodeModel treeNode;
-
- JQueryLocator expandAll = jq("input:submit[id$=expandAll]");
- JQueryLocator selection = jq("span[id$=selection]");
- JQueryLocator clientId = jq("span[id$=selectionEventClientId]");
- JQueryLocator newSelection = jq("span[id$=selectionEventNewSelection]");
- JQueryLocator oldSelection = jq("span[id$=selectionEventOldSelection]");
-
- public void testInitialize(SwitchType selectionType) {
- treeAttributes.set(TreeAttributes.selectionType, selectionType);
- tree.setSelectionType(selectionType);
- }
-
- public void testTopLevelSelection() {
- assertEquals(tree.getAnySelectedNodesCount(), 0);
-
- for (TreeNodeModel treeNode : tree.getNodes()) {
- assertFalse(treeNode.isSelected());
- assertTrue(treeNode.isCollapsed());
- treeNode.select();
- assertTrue(treeNode.isSelected());
- assertTrue(treeNode.isCollapsed());
-
- assertEquals(tree.getAnySelectedNodesCount(), 1);
- }
- }
-
@Test
+ @Use(field = "selectionType", value = "selectionTypeClient")
public void testTopLevelSelectionClient() {
- testInitialize(SwitchType.client);
testTopLevelSelection();
}
@Test
- @Use(field = "sample", strings = { "simpleSwingTreeNode",
"simpleRichFacesTreeDataModel" })
+ @Uses({ @Use(field = "selectionType", value =
"selectionTypeAjax"),
+ @Use(field = "sample", strings = { "simpleSwingTreeNode",
"simpleRichFacesTreeDataModel" }) })
public void testTopLevelSelectionAjax() {
- testInitialize(SwitchType.ajax);
testTopLevelSelection();
}
@Test(groups = { "4.2" })
@IssueTracking("https://issues.jboss.org/browse/RF-11766")
- @Use(field = "sample", strings = { "simpleRichFacesTreeNode" })
+ @Uses({ @Use(field = "selectionType", value =
"selectionTypeAjax"),
+ @Use(field = "sample", strings = { "simpleRichFacesTreeNode"
}) })
public void testTopLevelSelectionAjaxWithSimpleTreeNode() {
- testInitialize(SwitchType.ajax);
testTopLevelSelection();
}
- public void testSubNodesSelection() {
- expandAll();
- assertEquals(tree.getAnySelectedNodesCount(), 0);
-
- for (Integer[] path : selectionPaths) {
- treeNode = null;
- for (int index : path) {
- treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
- }
- assertFalse(treeNode.isSelected());
- treeNode.select();
- assertTrue(treeNode.isSelected());
- assertEquals(tree.getAnySelectedNodesCount(), 1);
- }
- }
-
@Test
+ @Use(field = "selectionType", value = "selectionTypeClient")
public void testSubNodesSelectionClient() {
- testInitialize(SwitchType.client);
testSubNodesSelection();
}
@Test
- @Use(field = "sample", strings = { "simpleSwingTreeNode",
"simpleRichFacesTreeDataModel" })
+ @Uses({ @Use(field = "selectionType", value =
"selectionTypeAjax"),
+ @Use(field = "sample", strings = { "simpleSwingTreeNode",
"simpleRichFacesTreeDataModel" }) })
public void testSubNodesSelectionAjax() {
- testInitialize(SwitchType.ajax);
testSubNodesSelection();
}
@Test(groups = { "4.2" })
@IssueTracking("https://issues.jboss.org/browse/RF-11766")
- @Use(field = "sample", strings = { "simpleRichFacesTreeNode" })
+ @Uses({ @Use(field = "selectionType", value =
"selectionTypeAjax"),
+ @Use(field = "sample", strings = { "simpleRichFacesTreeNode"
}) })
public void testSubNodesSelectionAjaxWithSimpleTreeNode() {
- testInitialize(SwitchType.ajax);
testSubNodesSelection();
}
- public void testSubNodesSelectionEvents() {
- expandAll();
- Integer[] old = null;
- for (Integer[] path : selectionPaths) {
- treeNode = null;
- for (int index : path) {
- treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
- }
- treeNode.select();
- assertEquals(getClientId(), "richTree");
- assertEquals(
- getSelection(),
- path,
- SimplifiedFormat.format("Actual Selection ({0}) doesn't
correspond to expected ({1})",
- Arrays.deepToString(getSelection()), Arrays.deepToString(path)));
- assertEquals(
- getNewSelection(),
- path,
- SimplifiedFormat.format("Actual New selection ({0}) doesn't
correspond to expected ({1})",
- Arrays.deepToString(getNewSelection()), Arrays.deepToString(path)));
- if (old != null) {
- assertEquals(
- getOldSelection(),
- old,
- SimplifiedFormat.format("Actual Old selection ({0}) doesn't
correspond to expected ({1})",
- Arrays.deepToString(getOldSelection()),
Arrays.deepToString(old)));
- } else {
- assertEquals(selenium.getText(oldSelection), "[]");
- }
- old = getNewSelection();
- }
- }
-
- @Test(groups = { "4.2" })
- @IssueTracking("https://issues.jboss.org/browse/RF-11766")
- public void testSubNodesSelectionEventsClient() {
- testInitialize(SwitchType.client);
- testSubNodesSelectionEvents();
- }
-
@Test
- @Use(field = "sample", strings = { "simpleSwingTreeNode",
"simpleRichFacesTreeDataModel" })
+ @Uses({ @Use(field = "selectionType", value =
"eventEnabledSelectionTypes"),
+ @Use(field = "sample", strings = { "simpleSwingTreeNode",
"simpleRichFacesTreeDataModel" }) })
public void testSubNodesSelectionEventsAjax() {
- testInitialize(SwitchType.ajax);
testSubNodesSelectionEvents();
}
@Test(groups = { "4.2" })
@IssueTracking("https://issues.jboss.org/browse/RF-11766")
- @Use(field = "sample", strings = { "simpleRichFacesTreeNode" })
+ @Uses({ @Use(field = "selectionType", value =
"eventEnabledSelectionTypes"),
+ @Use(field = "sample", strings = { "simpleRichFacesTreeNode"
}) })
public void testSubNodesSelectionEventsAjaxWithSimpleTreeNode() {
- testInitialize(SwitchType.ajax);
testSubNodesSelectionEvents();
}
- 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);
- }
-
- private Integer[] getNewSelection() {
- String string = selenium.getText(newSelection);
- return getIntsFromString(string);
- }
-
- private Integer[] getOldSelection() {
- String string = selenium.getText(oldSelection);
- return getIntsFromString(string);
- }
-
- private String getClientId() {
- return selenium.getText(clientId);
- }
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java 2012-01-05
15:07:31 UTC (rev 23131)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTreeModelAdaptor/TestTreeModelAdaptorSelection.java 2012-01-05
18:17:39 UTC (rev 23132)
@@ -1,6 +1,6 @@
/*******************************************************************************
* JBoss, Home of Professional Open Source
- * Copyright 2010-2011, Red Hat, Inc. and individual contributors
+ * Copyright 2010-2012, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
@@ -33,7 +33,7 @@
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.AbstractTestTreeSelection;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -41,15 +41,15 @@
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
-public class TestTreeModelAdaptorSelection extends TestTreeSelection {
-
+public class TestTreeModelAdaptorSelection extends AbstractTestTreeSelection {
+
@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 } });
-
+ 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 } });
+
@Inject
@Use(enumeration = true)
private RecursiveModelRepresentation representation;
@@ -76,23 +76,23 @@
}
@Test
+ @Use(field = "paths", empty = true)
@Override
- @Use(field = "paths", empty = true)
public void testTopLevelSelection() {
super.testTopLevelSelection();
}
@Test
+ @Use(field = "paths", value = "paths*")
@Override
- @Use(field = "paths", value = "paths*")
public void testSubNodesSelection() {
super.testSubNodesSelection();
}
@Test
- @Override
@Uses({ @Use(field = "paths", value = "paths*"),
@Use(field = "selectionType", value =
"eventEnabledSelectionTypes") })
+ @Override
public void testSubNodesSelectionEvents() {
super.testSubNodesSelectionEvents();
}