Author: lfryc(a)redhat.com
Date: 2011-01-13 09:43:10 -0500 (Thu, 13 Jan 2011)
New Revision: 20989
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/ColumnModel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnFiltering.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnModelTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnSortingTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnSimple.java
Log:
rich:column - Filtering sample automated (RFPL-729)
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnModelTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnModelTest.java 2011-01-13
14:42:00 UTC (rev 20988)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnModelTest.java 2011-01-13
14:43:10 UTC (rev 20989)
@@ -21,11 +21,8 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richColumn;
-import static org.jboss.test.selenium.locator.LocatorFactory.jq;
-
import java.util.List;
-import org.jboss.test.selenium.locator.JQueryLocator;
import org.richfaces.tests.metamer.bean.Model;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.richfaces.tests.metamer.model.Capital;
@@ -37,16 +34,8 @@
*/
public abstract class AbstractColumnModelTest extends AbstractMetamerTest {
- JQueryLocator table = pjq("table.rf-dt[id$=richDataTable]");
- JQueryLocator header = table.getChild(jq("thead.rf-dt-thd"));
-
- JQueryLocator headerRow = header.getChild(jq("tr.rf-dt-hdr"));
- JQueryLocator headerCell = jq("th.rf-dt-hdr-c");
-
- JQueryLocator bodyRow =
table.getChild(jq("tbody.rf-dt-b")).getChild(jq("tr.rf-dt-r"));
- JQueryLocator bodyCell = jq("td.rf-dt-c");
-
ColumnAttributes attributes = new ColumnAttributes();
+ ColumnModel model = new ColumnModel("richDataTable",
pjq("table.rf-dt[id$=richDataTable]"));
List<Capital> capitals;
@@ -54,17 +43,4 @@
public void prepareModel() {
capitals = Model.unmarshallCapitals();
}
-
- public Capital getCapital(int index) {
- String state = selenium.getText(bodyCell(index + 1, 1));
- String name = selenium.getText(bodyCell(index + 1, 2));
- Capital result = new Capital();
- result.setName(name);
- result.setState(state);
- return result;
- }
-
- public JQueryLocator bodyCell(int row, int column) {
- return
bodyRow.getNthChildElement(row).getChild(bodyCell).getNthChildElement(column);
- }
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnSortingTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnSortingTest.java 2011-01-13
14:42:00 UTC (rev 20988)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/AbstractColumnSortingTest.java 2011-01-13
14:43:10 UTC (rev 20989)
@@ -58,7 +58,7 @@
}
for (int i = 0; i < capitals.size(); i++) {
- Capital actualCapital = getCapital(i);
+ Capital actualCapital = model.getCapital(i);
Capital expectedCapital = capitals.get(i);
assertEquals(actualCapital.getName(), expectedCapital.getName());
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/ColumnModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/ColumnModel.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/ColumnModel.java 2011-01-13
14:43:10 UTC (rev 20989)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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.richColumn;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.reference.ReferencedLocator;
+import org.richfaces.tests.metamer.ftest.model.AbstractModel;
+import org.richfaces.tests.metamer.model.Capital;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class ColumnModel extends AbstractModel<JQueryLocator> {
+
+ AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ private ReferencedLocator<JQueryLocator> tableHeader = ref(root, ">
thead.rf-dt-thd");
+ private ReferencedLocator<JQueryLocator> tableBody = ref(root, ">
tbody.rf-dt-b");
+
+ private ReferencedLocator<JQueryLocator> headerRow = ref(tableHeader,
"> tr.rf-dt-hdr");
+ private ReferencedLocator<JQueryLocator> bodyRow = ref(tableBody, ">
tr.rf-dt-r");
+
+ private JQueryLocator headerCell = jq("th.rf-dt-hdr-c");
+ private JQueryLocator bodyCell = jq("td.rf-dt-c");
+
+ public ColumnModel(String name, JQueryLocator root) {
+ super(name, root);
+ }
+
+ public int getBodyRowCellCount(int row) {
+ return selenium.getCount(bodyRow.getNthChildElement(row).getChild(bodyCell));
+ }
+
+ public int getHeaderRowCellCount(int row) {
+ return
selenium.getCount(headerRow.getNthChildElement(row).getChild(headerCell));
+ }
+
+ public JQueryLocator getBodyCell(int row, int column) {
+ return
bodyRow.getNthChildElement(row).getChild(bodyCell).getNthChildElement(column);
+ }
+
+ public JQueryLocator getHeaderCell(int row, int column) {
+ return
headerRow.getNthChildElement(row).getChild(headerCell).getNthChildElement(column);
+ }
+
+ public Capital getCapital(int index) {
+ String state = selenium.getText(getBodyCell(index + 1, 1));
+ String name = selenium.getText(getBodyCell(index + 1, 2));
+ Capital result = new Capital();
+ result.setName(name);
+ result.setState(state);
+ return result;
+ }
+
+ public Collection<Capital> getCapitals() {
+ int count = getBodyRowCount();
+ List<Capital> capitals = new LinkedList<Capital>();
+ for (int i = 0; i < count; i++) {
+ capitals.add(getCapital(i));
+ }
+ return capitals;
+ }
+
+ public int getBodyRowCount() {
+ return selenium.getCount(bodyRow.getChild(bodyCell).getNthChildElement(1));
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnFiltering.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnFiltering.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnFiltering.java 2011-01-13
14:43:10 UTC (rev 20989)
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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.richColumn;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.bean.RichColumnBean;
+import org.richfaces.tests.metamer.model.Capital;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestColumnFiltering extends AbstractColumnModelTest {
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richColumn/filtering.xhtml");
+ }
+
+ JQueryLocator stateNameToFilter =
pjq("input:text[id$=stateNameToFilter]");
+ private final static String stateName = "Maryland";
+
+ JQueryLocator tableWithFilter = pjq("table.rf-dt[id$=richDataTable1]");
+ JQueryLocator tableWithFilterExpression =
pjq("table.rf-dt[id$=richDataTable2]");
+
+ @Test
+ public void testFilterAttribute() {
+ model.setRoot(tableWithFilter);
+ testFiltering();
+ }
+
+ @Test
+ public void testFilterExpressionAttribute() {
+ model.setRoot(tableWithFilterExpression);
+ testFiltering();
+ }
+
+ public void testFiltering() {
+ for (int i = 1; i <= stateName.length(); i++) {
+ String namePart = stateName.substring(0, i);
+
+ selenium.type(stateNameToFilter, namePart);
+ guardXhr(selenium).fireEvent(stateNameToFilter, Event.KEYUP);
+
+ Collection<Capital> actualCapitals = model.getCapitals();
+
+ richColumnBean.setStateNameToFilter(namePart);
+ Collection<Capital> expectedCapitals = Collections2.filter(capitals,
new Predicate<Capital>() {
+ @Override
+ public boolean apply(Capital capital) {
+ return richColumnBean.getStateNameFilter().accept(capital);
+ }
+
+ });
+
+ assertEqualsCapitals(actualCapitals, expectedCapitals);
+ }
+ }
+
+ RichColumnBean richColumnBean = new RichColumnBean();
+
+ private void assertEqualsCapitals(Collection<Capital> actualCapitals,
Collection<Capital> expectedCapitals) {
+ assertEquals(actualCapitals.size(), expectedCapitals.size());
+
+ Iterator<Capital> actualIterator = actualCapitals.iterator();
+ Iterator<Capital> expectedIterator = expectedCapitals.iterator();
+
+ while (actualIterator.hasNext()) {
+ Capital actual = actualIterator.next();
+ Capital expected = expectedIterator.next();
+
+ assertEquals(actual.getName(), expected.getName());
+ assertEquals(actual.getState(), actual.getState());
+ }
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnSimple.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnSimple.java 2011-01-13
14:42:00 UTC (rev 20988)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richColumn/TestColumnSimple.java 2011-01-13
14:43:10 UTC (rev 20989)
@@ -119,16 +119,16 @@
assertEquals(selenium.getAttribute(headerCell(2, 2).getAttribute(ROWSPAN)),
"2");
}
- public JQueryLocator headerCell(int iRow, int iColumn) {
- return
headerRow.getNthChildElement(iRow).getChild(headerCell).getNthChildElement(iColumn);
+ public JQueryLocator headerCell(int row, int column) {
+ return model.getHeaderCell(row, column);
}
- public int headerCount(int iRow) {
- return
selenium.getCount(headerRow.getNthChildElement(iRow).getChild(headerCell));
+ public int headerCount(int row) {
+ return model.getHeaderRowCellCount(row);
}
- public int bodyCount(int iRow) {
- return selenium.getCount(bodyRow.getNthChildElement(iRow).getChild(bodyCell));
+ public int bodyCount(int row) {
+ return model.getBodyRowCellCount(row);
}
}