Author: lfryc(a)redhat.com
Date: 2010-12-06 12:53:17 -0500 (Mon, 06 Dec 2010)
New Revision: 20412
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/AbstractDataTableTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTable.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacets.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacetsTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFilteringTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableScrollerTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSimpleTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSortingTest.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java
Log:
Added abstract implementation of data table tests as stub for rich:dataTable and
rich:extendedDataTable tests (RFPL-912, RFPL-918)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java 2010-12-06
17:51:19 UTC (rev 20411)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/Model.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -29,7 +29,6 @@
import java.util.List;
import java.util.Set;
-import javax.faces.FacesException;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.model.SelectItem;
@@ -69,11 +68,7 @@
*/
public synchronized List<Capital> getCapitals() {
if (capitalsList == null) {
- try {
- capitalsList = unmarshallCapitals();
- } catch (JAXBException e) {
- throw new FacesException(e.getMessage(), e);
- }
+ capitalsList = unmarshallCapitals();
}
return capitalsList;
@@ -86,11 +81,7 @@
*/
public synchronized List<Employee> getEmployees() {
if (employeesList == null) {
- try {
- employeesList = unmarshallEmployees();
- } catch (JAXBException e) {
- throw new FacesException(e.getMessage(), e);
- }
+ employeesList = unmarshallEmployees();
}
return employeesList;
@@ -103,11 +94,7 @@
*/
public synchronized List<CompactDiscXmlDescriptor> getCompactDiscs() {
if (compactDiscList == null) {
- try {
- compactDiscList = unmarshallCompactDiscs();
- } catch (JAXBException e) {
- throw new FacesException(e.getMessage(), e);
- }
+ compactDiscList = unmarshallCompactDiscs();
}
return compactDiscList;
@@ -120,16 +107,28 @@
* @throws JAXBException
* if any unexpected errors occurs during unmarshalling
*/
- public static final List<Capital> unmarshallCapitals() throws JAXBException {
- return unmarshall(CapitalsHolder.class,
"org/richfaces/tests/metamer/model/capitals.xml");
+ public static final List<Capital> unmarshallCapitals() {
+ try {
+ return unmarshall(CapitalsHolder.class,
"org/richfaces/tests/metamer/model/capitals.xml");
+ } catch (JAXBException e) {
+ throw new IllegalStateException(e);
+ }
}
- public static final List<Employee> unmarshallEmployees() throws JAXBException
{
- return unmarshall(EmployeesHolder.class,
"org/richfaces/tests/metamer/model/employees.xml");
+ public static final List<Employee> unmarshallEmployees() {
+ try {
+ return unmarshall(EmployeesHolder.class,
"org/richfaces/tests/metamer/model/employees.xml");
+ } catch (JAXBException e) {
+ throw new IllegalStateException(e);
+ }
}
- public static final List<CompactDiscXmlDescriptor> unmarshallCompactDiscs()
throws JAXBException {
- return unmarshall(CompactDiscsHolder.class,
"org/richfaces/tests/metamer/model/compact-discs.xml");
+ public static final List<CompactDiscXmlDescriptor> unmarshallCompactDiscs() {
+ try {
+ return unmarshall(CompactDiscsHolder.class,
"org/richfaces/tests/metamer/model/compact-discs.xml");
+ } catch (JAXBException e) {
+ throw new IllegalStateException(e);
+ }
}
@SuppressWarnings("unchecked")
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml 2010-12-06
17:51:19 UTC (rev 20411)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataTable/filtering.xhtml 2010-12-06
17:53:17 UTC (rev 20412)
@@ -81,7 +81,7 @@
</h:panelGroup>
</f:facet>
- <h:graphicImage library="images" name="#{record.sex
== 'MALE' ? 'male.png' : 'female.png'}" />
+ <h:graphicImage library="images" name="#{record.sex
== 'MALE' ? 'male.png' : 'female.png'}"
alt="record.sex" />
<f:facet name="footer">
<h:outputText id="columnFooterSex"
value="Sex" />
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/AbstractDataTableTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/AbstractDataTableTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/AbstractDataTableTest.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import static org.jboss.test.selenium.locator.Attribute.ALT;
+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.ftest.model.AssertingDataScroller;
+import org.richfaces.tests.metamer.ftest.model.DataScroller;
+import org.richfaces.tests.metamer.model.Capital;
+import org.richfaces.tests.metamer.model.Employee;
+import org.richfaces.tests.metamer.model.Employee.Sex;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class AbstractDataTableTest extends AbstractMetamerTest {
+ protected static final List<Capital> CAPITALS = Model.unmarshallCapitals();
+ protected static final List<Employee> EMPLOYEES = Model.unmarshallEmployees();
+ protected static final int ELEMENTS_TOTAL = 50;
+
+ protected static final int COLUMN_STATE = 1;
+ protected static final int COLUMN_CAPITAL = 2;
+
+ protected static final int COLUMN_SEX = 1;
+ protected static final int COLUMN_NAME = 2;
+ protected static final int COLUMN_TITLE = 3;
+ protected static final int COLUMN_NUMBER_OF_KIDS1 = 4;
+ protected static final int COLUMN_NUMBER_OF_KIDS2 = 5;
+
+ protected static final Integer[] COUNTS = new Integer[] { null, 1, 3, 11,
ELEMENTS_TOTAL / 2, ELEMENTS_TOTAL - 1,
+ ELEMENTS_TOTAL, ELEMENTS_TOTAL + 1 };
+
+ protected DataTable model;
+ protected EmployeeTableModel employees;
+ protected DataTableAttributes attributes;
+ protected DataTableFacets facets;
+
+ protected DataScroller dataScroller1 = new
AssertingDataScroller("outside-table",
pjq("span.rf-ds[id$=scroller1]"));
+ protected DataScroller dataScroller2 = new
AssertingDataScroller("inside-table-footer",
+ pjq("span.rf-ds[id$=scroller2]"));
+
+ public class EmployeeTableModel {
+ public Sex getSex(int row) {
+ JQueryLocator element = model.getElement(COLUMN_SEX,
row).getDescendant(jq("img"));
+ String sex = selenium.getAttribute(element.getAttribute(ALT));
+ return Sex.valueOf(sex.toUpperCase());
+ }
+
+ public String getName(int row) {
+ return selenium.getText(model.getElement(COLUMN_NAME, row));
+ }
+
+ public String getTitle(int row) {
+ return selenium.getText(model.getElement(COLUMN_TITLE, row));
+ }
+
+ public int getNumberOfKids(int row) {
+ return
Integer.valueOf(selenium.getText(model.getElement(COLUMN_NUMBER_OF_KIDS1, row)));
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTable.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTable.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTable.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public interface DataTable {
+ int getPages();
+
+ int getCurrentPage();
+
+ int getRows();
+
+ int getColumns();
+
+ boolean isVisible();
+
+ boolean isNoData();
+
+ JQueryLocator getNoData();
+
+ JQueryLocator getElement(int column, int row);
+
+ JQueryLocator getColumnHeader(int column);
+
+ JQueryLocator getColumnFooter(int column);
+
+ JQueryLocator getHeader();
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableAttributes.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.commons.lang.StringUtils;
+import org.richfaces.model.SortMode;
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class DataTableAttributes extends AbstractComponentAttributes {
+ public void setShowData(boolean showData) {
+ setProperty("showData", showData);
+ }
+
+ public void setFirst(Integer first) {
+ setProperty("first", first);
+ }
+
+ public void setNoDataLabel(String noDataLabel) {
+ setProperty("noDataLabel", noDataLabel);
+ }
+
+ public void setRendered(Boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+
+ public void setRows(Integer rows) {
+ setProperty("rows", rows);
+ }
+
+ public int getRows() {
+ return Integer.valueOf(getProperty("rows"));
+ }
+
+ public void setSortMode(SortMode sortMode) {
+ setProperty("sortMode", sortMode);
+ }
+
+ public void setSortPriority(Collection<String> sortPriority) {
+ setProperty("sortPriority", sortPriority);
+ }
+
+ public Collection<String> getSortPriority() {
+ String string = getProperty("sortPriority");
+ return new LinkedList<String>(Arrays.asList(StringUtils.split(string,
"[], ")));
+
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacets.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacets.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacets.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class DataTableFacets extends AbstractComponentAttributes {
+
+ public void setNoData(String noData) {
+ throw new UnsupportedOperationException("not implemeneted yet");
+ }
+
+ public void setHeader(String header) {
+ setProperty("header", header);
+ }
+
+ public void setStateHeader(String stateHeader) {
+ setProperty("stateHeader", stateHeader);
+ }
+
+ public void setStateFooter(String stateFooter) {
+ setProperty("stateFooter", stateFooter);
+ }
+
+ public void setCapitalHeader(String capitalHeader) {
+ setProperty("capitalHeader", capitalHeader);
+ }
+
+ public void setCapitalFooter(String capitalFooter) {
+ setProperty("capitalFooter", capitalFooter);
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacetsTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacetsTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFacetsTest.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class DataTableFacetsTest extends AbstractDataTableTest {
+
+ private static final String SAMPLE_STRING = "Abc123!@#ĚščСам";
+ private static final String EMPTY_STRING = "";
+
+ @Test
+ public void testNoDataInstantChange() {
+ attributes.setShowData(false);
+ facets.setNoData(SAMPLE_STRING);
+ assertEquals(selenium.getText(model.getNoData()), SAMPLE_STRING);
+ }
+
+ @Test
+ public void testNoDataEmpty() {
+ attributes.setShowData(false);
+ facets.setNoData(EMPTY_STRING);
+ assertEquals(selenium.getText(model.getNoData()), EMPTY_STRING);
+ }
+
+ @Test
+ public void testNoDataLabelWithEmptyNoDataFacet() {
+ attributes.setShowData(false);
+ facets.setNoData(EMPTY_STRING);
+ attributes.setNoDataLabel(SAMPLE_STRING);
+ assertEquals(selenium.getText(model.getNoData()), SAMPLE_STRING);
+ }
+
+ @Test
+ public void testHeaderInstantChange() {
+ facets.setHeader(SAMPLE_STRING);
+ assertEquals(selenium.getText(model.getHeader()), SAMPLE_STRING);
+ }
+
+ @Test
+ public void testHeaderEmpty() {
+ facets.setHeader(EMPTY_STRING);
+ assertFalse(selenium.isElementPresent(model.getHeader()));
+ }
+
+ @Test
+ public void testStateHeaderInstantChange() {
+ facets.setStateHeader(SAMPLE_STRING);
+ assertEquals(selenium.getText(model.getColumnHeader(COLUMN_STATE)),
SAMPLE_STRING);
+ }
+
+ @Test
+ public void testStateHeaderEmpty() {
+ facets.setStateHeader(EMPTY_STRING);
+ assertFalse(selenium.isElementPresent(model.getColumnHeader(COLUMN_STATE)));
+ }
+
+ @Test
+ public void testStateFooterInstantChange() {
+ facets.setStateHeader(SAMPLE_STRING);
+ assertEquals(selenium.getText(model.getColumnFooter(COLUMN_STATE)),
SAMPLE_STRING);
+ }
+
+ @Test
+ public void testStateFooterEmpty() {
+ facets.setStateFooter(EMPTY_STRING);
+ assertFalse(selenium.isElementPresent(model.getColumnFooter(COLUMN_STATE)));
+ }
+
+ @Test
+ public void testCapitalHeaderInstantChange() {
+ facets.setCapitalHeader(SAMPLE_STRING);
+ assertEquals(selenium.getText(model.getColumnHeader(COLUMN_CAPITAL)),
SAMPLE_STRING);
+ }
+
+ @Test
+ public void testCapitalHeaderEmpty() {
+ facets.setCapitalHeader(EMPTY_STRING);
+ assertFalse(selenium.isElementPresent(model.getColumnHeader(COLUMN_CAPITAL)));
+ }
+
+ @Test
+ public void testCapitalFooterInstantChange() {
+ facets.setCapitalHeader(SAMPLE_STRING);
+ assertEquals(selenium.getText(model.getColumnFooter(COLUMN_CAPITAL)),
SAMPLE_STRING);
+ }
+
+ @Test
+ public void testCapitalFooterEmpty() {
+ facets.setCapitalFooter(EMPTY_STRING);
+ assertFalse(selenium.isElementPresent(model.getColumnFooter(COLUMN_CAPITAL)));
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFilteringTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFilteringTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableFilteringTest.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+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.locator.option.OptionLocatorFactory.optionValue;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.option.OptionValueLocator;
+import org.richfaces.model.Filter;
+import org.richfaces.tests.metamer.model.Employee;
+import org.richfaces.tests.metamer.model.Employee.Sex;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class DataTableFilteringTest extends AbstractDataTableTest {
+
+ private static final String[] FILTER_NAMES = new String[] { "ivan",
"Гог", null, "Š" };
+ private static final String[] FILTER_TITLES = new String[] { "Director",
null, "CEO" };
+ private static final Integer[] FILTER_NUMBER_OF_KIDS = new Integer[] { 2, 100, null,
5 };
+
+ JQueryLocator selectSex = jq("select");
+ JQueryLocator inputName = jq("input");
+ JQueryLocator inputTitle = jq("input");
+ JQueryLocator inputNumberOfKids1 = jq("input");
+ JQueryLocator inputNumberOfKids2 = jq("input");
+
+ FilteringDataTable filtering = new FilteringDataTable();
+
+ public ExpectedEmployee filterEmployee;
+ public List<Employee> expectedEmployees;
+ public int rows;
+
+ @BeforeMethod
+ public void setup() {
+ filterEmployee = new ExpectedEmployee();
+ }
+
+ @Test
+ public void testFilterSex() {
+ filtering.selectSex(Sex.MALE);
+ filterEmployee.sex = Sex.MALE;
+ verifyFiltering();
+
+ filtering.selectSex(Sex.FEMALE);
+ filterEmployee.sex = Sex.FEMALE;
+ verifyFiltering();
+
+ filtering.selectSex(null);
+ filterEmployee.sex = null;
+ verifyFiltering();
+ }
+
+ @Test
+ public void testFilterName() {
+ for (String filterName : FILTER_NAMES) {
+ filtering.selectName(filterName);
+ filterEmployee.name = filterName;
+ verifyFiltering();
+ }
+ }
+
+ @Test
+ public void testFilterTitle() {
+ for (String filterTitle : FILTER_TITLES) {
+ filtering.selectTitle(filterTitle);
+ filterEmployee.title = filterTitle;
+ verifyFiltering();
+ }
+ }
+
+ @Test
+ public void testFilterNumberOfKids1() {
+ for (Integer filterNumberOfKids : FILTER_NUMBER_OF_KIDS) {
+ filtering.selectNumberOfKids1(filterNumberOfKids);
+ filterEmployee.numberOfKids1 = filterNumberOfKids;
+ verifyFiltering();
+ }
+ }
+
+ @Test
+ public void testFilterCombinations() {
+ filtering.selectTitle("Technology");
+ filterEmployee.title = "Technology";
+ verifyFiltering();
+
+ filtering.selectNumberOfKids1(1);
+ filterEmployee.numberOfKids1 = 1;
+ verifyFiltering();
+
+ filtering.selectSex(Sex.MALE);
+ filterEmployee.sex = Sex.MALE;
+ verifyFiltering();
+
+ filtering.selectName("9");
+ filterEmployee.name = "9";
+ verifyFiltering();
+
+ filtering.selectNumberOfKids1(1);
+ filterEmployee.numberOfKids1 = 1;
+ verifyFiltering();
+
+ filtering.selectSex(Sex.FEMALE);
+ filterEmployee.sex = Sex.FEMALE;
+ verifyFiltering();
+ }
+
+ @Test
+ public void testRefresh() {
+ dataScroller1.gotoFirstPage();
+ rows = model.getRows();
+
+ filtering.selectName("an");
+ filterEmployee.name = "an";
+
+ dataScroller1.gotoLastPage();
+ int lastPage = dataScroller1.getCurrentPage();
+ assertTrue(lastPage > 1);
+
+ rerenderAll();
+ assertEquals(dataScroller1.getCurrentPage(), lastPage);
+ verifyPageContent(lastPage);
+
+ fullPageRefresh();
+ assertEquals(dataScroller1.getCurrentPage(), lastPage);
+ verifyPageContent(lastPage);
+ }
+
+ public void verifyFiltering() {
+ expectedEmployees = filter(EMPLOYEES, getFilter());
+
+ dataScroller1.gotoFirstPage();
+ rows = model.getRows();
+ verifyPageContent(1);
+
+ dataScroller1.gotoPage(2);
+ verifyPageContent(2);
+
+ dataScroller1.gotoLastPage();
+ int lastPage = dataScroller1.getCurrentPage();
+ verifyPageContent(lastPage);
+
+ dataScroller1.gotoPage(lastPage - 1);
+ verifyPageContent(lastPage - 1);
+ }
+
+ public void verifyPageContent(int page) {
+ for (int row = 0; row < model.getRows(); row++) {
+ int index = (page - 1) * rows + row;
+ Employee expectedEmployee = expectedEmployees.get(index);
+ filtering.verifyRow(expectedEmployee, row);
+ }
+ }
+
+ private class ExpectedEmployee {
+ Sex sex;
+ String name;
+ String title;
+ Integer numberOfKids1;
+ }
+
+ private Filter<Employee> getFilter() {
+ return new Filter<Employee>() {
+ @Override
+ public boolean accept(Employee employee) {
+ boolean result = true;
+ if (filterEmployee.sex != null) {
+ result &= employee.getSex() == filterEmployee.sex;
+ }
+ if (filterEmployee.name != null) {
+ result &=
employee.getName().toLowerCase().contains(filterEmployee.name.toLowerCase());
+ }
+ if (filterEmployee.title != null) {
+ result &= employee.getTitle().equals(filterEmployee.title);
+ }
+ if (filterEmployee.numberOfKids1 != null) {
+ result &= employee.getNumberOfKids() >=
filterEmployee.numberOfKids1;
+ }
+ return result;
+ }
+ };
+ }
+
+ @SuppressWarnings("unchecked")
+ private <E, T extends Collection<E>> T filter(T collection,
Filter<E> filter) {
+ T filteredCollection;
+ try {
+ filteredCollection = (T) collection.getClass().newInstance();
+
+ for (E element : collection) {
+ if (filter.accept(element)) {
+ filteredCollection.add(element);
+ }
+ }
+
+ return (T) filteredCollection;
+ } catch (Exception e) {
+ throw new IllegalStateException("Cannot construct new collection",
e);
+ }
+ }
+
+ private class FilteringDataTable {
+ public void verifyRow(Employee expectedEmployee, int row) {
+ verifySex(expectedEmployee.getSex(), row);
+ verifyElement(COLUMN_NAME, row, expectedEmployee.getName());
+ verifyElement(COLUMN_TITLE, row, expectedEmployee.getTitle());
+ verifyElement(COLUMN_NUMBER_OF_KIDS1, row,
expectedEmployee.getNumberOfKids());
+ verifyElement(COLUMN_NUMBER_OF_KIDS2, row,
expectedEmployee.getNumberOfKids());
+ }
+
+ public void selectSex(Sex sex) {
+ JQueryLocator select =
model.getColumnHeader(COLUMN_SEX).getDescendant(selectSex);
+ OptionValueLocator option = sex == null ? optionValue("ALL") :
optionValue(sex.toString());
+ guardXhr(selenium).select(select, option);
+ }
+
+ public void verifySex(Sex expectedSex, int row) {
+ JQueryLocator rowLocator = model.getElement(COLUMN_SEX, row);
+ AttributeLocator<?> sexLocator =
rowLocator.getDescendant(jq("img")).getAttribute(Attribute.ALT);
+ String sexString = selenium.getAttribute(sexLocator);
+ Sex actualSex = Sex.valueOf(sexString);
+ assertEquals(actualSex, expectedSex);
+ }
+
+ public void selectName(String name) {
+ JQueryLocator input =
model.getColumnHeader(COLUMN_NAME).getDescendant(inputName);
+ selenium.type(inputName, name);
+ guardXhr(selenium).fireEvent(input, Event.BLUR);
+ }
+
+ public void selectTitle(String title) {
+ JQueryLocator input =
model.getColumnHeader(COLUMN_TITLE).getDescendant(inputTitle);
+ selenium.type(inputName, title);
+ guardXhr(selenium).fireEvent(input, Event.BLUR);
+ }
+
+ public void selectNumberOfKids1(int numberOfKids) {
+ JQueryLocator input =
model.getColumnHeader(COLUMN_NUMBER_OF_KIDS1).getDescendant(inputNumberOfKids1);
+ selenium.type(inputName, Integer.toString(numberOfKids));
+ guardXhr(selenium).fireEvent(input, Event.BLUR);
+ }
+
+ public void verifyElement(int column, int row, Object expectedValue) {
+ JQueryLocator locator = model.getColumnHeader(COLUMN_NAME);
+ String text = selenium.getText(locator);
+ assertEquals(text, expectedValue.toString());
+ }
+
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableScrollerTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableScrollerTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableScrollerTest.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import static org.testng.Assert.assertEquals;
+
+import org.richfaces.tests.metamer.ftest.annotations.Templates;
+import org.richfaces.tests.metamer.ftest.model.DataScroller;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class DataTableScrollerTest extends AbstractDataTableTest {
+
+ @Test
+ public void testRowCountFooterScroller() {
+ testRowCount(dataScroller2);
+ }
+
+ @Test
+ @Templates(exclude = { "a4jRepeat1", "a4jRepeat2",
"hDataTable1", "hDataTable2", "richDataTable1,redDiv",
+ "richDataTable2,redDiv", "uiRepeat1", "uiRepeat2"
})
+ public void testRowCountOutsideTable() {
+ testRowCount(dataScroller1);
+ }
+
+ private void testRowCount(DataScroller dataScroller) {
+ for (Integer rowsPerPage : COUNTS) {
+ if (rowsPerPage != null) {
+ attributes.setRows(rowsPerPage);
+ selenium.waitForPageToLoad();
+ }
+
+ dataScroller.gotoFirstPage();
+ int rowCountPreset = attributes.getRows();
+ int rowCountActual = model.getRows();
+ assertEquals(rowCountActual, Math.min(ELEMENTS_TOTAL, rowCountPreset));
+
+ assertEquals(dataScroller.hasPages(), rowCountActual < ELEMENTS_TOTAL);
+ if (dataScroller.hasPages()) {
+ dataScroller.gotoLastPage();
+
+ int pagesExpected = pageCountActualExpected(rowCountActual);
+ int countOfVisiblePages = dataScroller.getCountOfVisiblePages();
+
+ if (countOfVisiblePages < pagesExpected) {
+ int lastVisiblePage = dataScroller.getLastVisiblePage();
+ assertEquals(lastVisiblePage,
pageCountActualExpected(rowCountActual));
+ } else {
+ assertEquals(countOfVisiblePages, pagesExpected);
+ }
+
+ int rowCountExpected = rowCountLastPageExpected(rowCountPreset);
+ rowCountActual = model.getRows();
+ assertEquals(rowCountActual, rowCountExpected);
+ }
+ }
+ }
+
+ private int pageCountActualExpected(int rowCountActual) {
+ return Double.valueOf(Math.ceil((double) ELEMENTS_TOTAL /
rowCountActual)).intValue();
+ }
+
+ private int rowCountLastPageExpected(int rowCountPreset) {
+ int result = ELEMENTS_TOTAL % rowCountPreset;
+ return (result == 0) ? rowCountPreset : result;
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSimpleTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSimpleTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSimpleTest.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.util.List;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.model.Capital;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class DataTableSimpleTest extends AbstractDataTableTest {
+
+ protected static final int COLUMNS_TOTAL = 2;
+
+ @Inject
+ protected Integer first = null;
+
+ @Inject
+ protected Integer rows = 30;
+
+ private int expectedFirst;
+ private int expectedRows;
+ private List<Capital> expectedElements;
+
+ @BeforeMethod
+ public void setup() {
+ attributes.setFirst(first);
+ attributes.setRows(rows);
+
+ if (first == null) {
+ expectedFirst = 0;
+ } else {
+ expectedFirst = Math.min(ELEMENTS_TOTAL, first);
+ }
+
+ if (rows == null) {
+ expectedRows = ELEMENTS_TOTAL - first;
+ } else {
+ expectedRows = rows - first;
+ }
+
+ expectedElements = getExpectedElements();
+ }
+
+ @Test
+ public void testRendered() {
+ assertFalse(model.isVisible());
+ assertFalse(model.isNoData());
+ assertEquals(model.getColumns(), 0);
+ assertEquals(model.getRows(), 0);
+ }
+
+ @Test
+ public void testNoDataLabel() {
+ assertTrue(model.isVisible());
+ assertTrue(model.isNoData());
+ assertEquals(model.getColumns(), 0);
+ assertEquals(model.getRows(), 0);
+ assertEquals(selenium.getText(model.getNoData()), "There is no
data.");
+ }
+
+ @Test
+ @Use(field = "first", value = "COUNTS")
+ public void testFirst() {
+ verifyTable();
+ }
+
+ @Test
+ @Use(field = "rows", value = "COUNTS")
+ public void testRows() {
+ verifyTable();
+ }
+
+ public void verifyTable() {
+ assertTrue(model.isVisible());
+ assertFalse(model.isNoData());
+ assertEquals(model.getColumns(), COLUMNS_TOTAL);
+ assertEquals(model.getRows(), expectedRows);
+ }
+
+ public void verifyElements() {
+ for (int i = 0; i < expectedRows; i++) {
+ Capital expectedCapital = expectedElements.get(i);
+ JQueryLocator stateLocator = model.getElement(1, i);
+ JQueryLocator capitalLocator = model.getElement(1, i);
+
+ assertEquals(selenium.getText(stateLocator), expectedCapital.getState());
+ assertEquals(selenium.getText(capitalLocator), expectedCapital.getState());
+ }
+ }
+
+ public List<Capital> getExpectedElements() {
+ return CAPITALS.subList(expectedFirst, expectedFirst + expectedRows);
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSortingTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSortingTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/abstractions/DataTableSortingTest.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.abstractions;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.testng.Assert.assertEquals;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.richfaces.model.SortMode;
+import org.richfaces.tests.metamer.model.Employee;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class DataTableSortingTest extends AbstractDataTableTest {
+
+ @Test
+ public void testSortModeSingle() {
+ attributes.setSortMode(SortMode.single);
+
+ sortByColumn(COLUMN_TITLE);
+ verifySortingByColumns("title");
+
+ sortByColumn(COLUMN_SEX);
+ verifySortingByColumns("sex");
+
+ sortByColumn(COLUMN_NAME);
+ verifySortingByColumns("name");
+
+ sortByColumn(COLUMN_NUMBER_OF_KIDS1);
+ verifySortingByColumns("numberOfKids");
+
+ rerenderAll();
+ verifySortingByColumns("numberOfKids");
+
+ fullPageRefresh();
+ verifySortingByColumns("numberOfKids");
+ }
+
+ @Test
+ public void testSortModeMulti() {
+ attributes.setSortMode(SortMode.single);
+
+ sortByColumn(COLUMN_TITLE);
+ verifySortingByColumns("title");
+
+ sortByColumn(COLUMN_SEX);
+ verifySortingByColumns("title", "sex");
+
+ sortByColumn(COLUMN_NUMBER_OF_KIDS1);
+ verifySortingByColumns("title", "sex",
"numberOfKids");
+
+ sortByColumn(COLUMN_NAME);
+ verifySortingByColumns("title", "sex",
"numberOfKids", "name");
+
+ sortByColumn(COLUMN_NUMBER_OF_KIDS1);
+ verifySortingByColumns("title", "sex", "name",
"numberOfKids");
+
+ sortByColumn(COLUMN_TITLE);
+ verifySortingByColumns("sex", "name",
"numberOfKids", "title");
+
+ rerenderAll();
+ verifySortingByColumns("sex", "name",
"numberOfKids", "title");
+
+ fullPageRefresh();
+ verifySortingByColumns("sex", "name",
"numberOfKids", "title");
+ }
+
+ int rowIndex;
+ int modelIndex;
+ List<Employee> sortedEmployees;
+
+ public void sortByColumn(int column) {
+ selenium.click(model.getColumnHeader(column).getDescendant(jq("a")));
+ }
+
+ public void verifySortingByColumns(String... columns) {
+ Comparator<Employee> employeeComparator =
getPropertyComparator(Employee.class, columns);
+ sortedEmployees = new ArrayList<Employee>(EMPLOYEES);
+ Collections.sort(sortedEmployees, employeeComparator);
+
+ int firstPageRows = model.getRows();
+
+ dataScroller1.gotoFirstPage();
+
+ for (rowIndex = 0; rowIndex < model.getRows(); rowIndex++) {
+ modelIndex = rowIndex;
+ verifyRow(rowIndex, modelIndex);
+ }
+
+ dataScroller1.gotoPage(2);
+
+ for (rowIndex = 0; rowIndex < model.getRows(); rowIndex++) {
+ modelIndex = firstPageRows + rowIndex;
+ verifyRow(rowIndex, modelIndex);
+ }
+
+ dataScroller1.gotoLastPage();
+
+ for (rowIndex = 0; rowIndex < model.getRows(); rowIndex++) {
+ modelIndex = EMPLOYEES.size() - model.getRows() + rowIndex;
+ verifyRow(rowIndex, modelIndex);
+ }
+ }
+
+ public void verifyRow(int rowIndex, int modelIndex) {
+ assertEquals(employees.getSex(rowIndex),
sortedEmployees.get(modelIndex).getSex());
+ assertEquals(employees.getName(rowIndex), sortedEmployees.get(modelIndex));
+ assertEquals(employees.getTitle(rowIndex),
sortedEmployees.get(modelIndex).getTitle());
+ assertEquals(employees.getNumberOfKids(rowIndex),
sortedEmployees.get(modelIndex).getNumberOfKids());
+ }
+
+ public <T> Comparator<T> getPropertyComparator(final Class<T>
classT, final String... properties) {
+ return new Comparator<T>() {
+
+ @Override
+ public int compare(T o1, T o2) {
+ for (String property : properties) {
+ String getterName = "get" +
StringUtils.capitalize(property);
+ try {
+
+ Method getter = classT.getClass().getMethod(getterName);
+ Object got1 = getter.invoke(o1);
+ Object got2 = getter.invoke(o2);
+ Method compareTo =
got1.getClass().getMethod("compareTo", got2.getClass());
+ int result = (Integer) compareTo.invoke(got1, got2);
+ if (result != 0) {
+ return result;
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Cannot obtain property
'" + property + "'", e);
+ }
+ }
+ return 0;
+ }
+
+ };
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java 2010-12-06
17:51:19 UTC (rev 20411)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java 2010-12-06
17:53:17 UTC (rev 20412)
@@ -29,8 +29,6 @@
import java.util.LinkedList;
import java.util.List;
-import javax.xml.bind.JAXBException;
-
import org.richfaces.tests.metamer.bean.Model;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.richfaces.tests.metamer.ftest.annotations.Inject;
@@ -63,18 +61,10 @@
@Use(booleans = { true, false })
Boolean selectFirst;
- List<Capital> capitals;
+ List<Capital> capitals = Model.unmarshallCapitals();
StringBuilder partialInput;
- {
- try {
- capitals = Model.unmarshallCapitals();
- } catch (JAXBException e) {
- throw new IllegalStateException(e);
- }
- }
-
@BeforeMethod
public void prepareProperties() {
attributes.setAutofill(autofill);