Author: lfryc(a)redhat.com
Date: 2011-01-18 04:03:30 -0500 (Tue, 18 Jan 2011)
New Revision: 21050
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSorting.java
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/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableScroller.java
Log:
rich:collapsibleSubTable - automated Sorting sample (RFPL-731)
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-01-18
08:48:25 UTC (rev 21049)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java 2011-01-18
09:03:30 UTC (rev 21050)
@@ -130,7 +130,7 @@
protected void applyRadio(ElementLocator<?> locator) {
guard(selenium, requestType).click(locator);
}
-
+
protected void applySelect(ElementLocator<?> locator, String value) {
OptionValueLocator optionLocator = new OptionValueLocator(value);
guard(selenium, requestType).select(locator, optionLocator);
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java 2011-01-18
08:48:25 UTC (rev 21049)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java 2011-01-18
09:03:30 UTC (rev 21050)
@@ -61,7 +61,7 @@
CollapsibleSubTable subtable;
CollapsibleSubTableToggler toggler;
List<Employee> employees;
-
+
Configuration secondConfiguration;
CollapsibleSubTable secondSubtable;
CollapsibleSubTableToggler secondToggler;
@@ -69,20 +69,24 @@
@Inject
@Use(empty = true)
ExpandMode expandMode;
-
+
@BeforeMethod
public void configure() {
if (configuration != null) {
subtable = configuration.subtable;
toggler = configuration.toggler;
employees = configuration.employees;
-
+
secondConfiguration = configuration.name.equals("Men") ?
configurationWomen : configurationMen;
secondSubtable = secondConfiguration.subtable;
secondToggler = secondConfiguration.toggler;
}
}
+ protected void resetEmployees() {
+ employees = configuration.employees;
+ }
+
public class Configuration {
CollapsibleSubTable subtable;
CollapsibleSubTableToggler toggler;
@@ -102,13 +106,13 @@
}
}));
}
-
+
@Override
public String toString() {
return name;
}
}
-
+
protected RequestType getRequestTypeForExpandMode() {
switch (expandMode) {
case ajax:
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java 2011-01-18
08:48:25 UTC (rev 21049)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java 2011-01-18
09:03:30 UTC (rev 21050)
@@ -37,7 +37,7 @@
* @version $Revision$
*/
public class CollapsibleSubTableAttributes extends AbstractComponentAttributes {
-
+
JQueryLocator showDataLocator = pjq("input[id$=noDataCheckbox]");
public void setShowData(boolean showData) {
@@ -68,7 +68,7 @@
public void setRows(Integer rows) {
setProperty("rows", rows);
}
-
+
public Integer getRows() {
return Integer.valueOf(getProperty("rows"));
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableScroller.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableScroller.java 2011-01-18
08:48:25 UTC (rev 21049)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableScroller.java 2011-01-18
09:03:30 UTC (rev 21050)
@@ -86,7 +86,7 @@
@Test
@Use(field = "expandMode", enumeration = true)
- public void testScrollerWithRowsAttribute() {
+ public void testScroller() {
paginationTester.testNumberedPages();
}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSorting.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSorting.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSorting.java 2011-01-18
09:03:30 UTC (rev 21050)
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * 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.richCollapsibleSubTable;
+
+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 static org.testng.Assert.assertEquals;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.richfaces.component.SortOrder;
+import org.richfaces.model.SortMode;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.model.DataTable;
+import org.richfaces.tests.metamer.model.Employee;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestCollapsibleSubTableSorting extends AbstractCollapsibleSubTableTest {
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richCollapsibleSubTable/sorting-using-column.xhtml");
+ }
+
+ @Inject
+ @Use(enumeration = true)
+ SortMode sortMode;
+
+ int rows = 0;
+
+ List<Column> sortPriority = new LinkedList<Column>();
+
+ @BeforeMethod
+ public void prepare() {
+ sortPriority.clear();
+ Column.resetAll();
+ }
+
+ @Test
+ public void testSorting() {
+ attributes.setRows(rows);
+ attributes.setSortMode(sortMode);
+
+ sortBy(Column.NAME);
+ verifySorting();
+
+ sortBy(Column.TITLE);
+ verifySorting();
+
+ sortBy(Column.NAME);
+ verifySorting();
+
+ sortBy(Column.TITLE);
+ verifySorting();
+ }
+
+ private void sortBy(Column column) {
+ if (sortMode == SortMode.single) {
+ Column.resetAll();
+ resetEmployees();
+ sortPriority.clear();
+ }
+ column.sort(dataTable);
+ sortPriority.remove(column);
+ sortPriority.add(column);
+ }
+
+ public void verifySorting() {
+ sortEmployees();
+
+ List<Employee> visibleEmployees = employees.subList(0, Math.max(rows,
employees.size()));
+
+ int rowCount = subtable.getRowCount();
+ assertEquals(rowCount, visibleEmployees.size());
+
+ for (int i = 0; i < visibleEmployees.size(); i++) {
+ String name = selenium.getText(subtable.getCell(1, i + 1));
+ String title = selenium.getText(subtable.getCell(2, i + 1));
+
+ assertEquals(name, visibleEmployees.get(i).getName());
+ assertEquals(title, visibleEmployees.get(i).getTitle());
+ }
+ }
+
+ public void sortEmployees() {
+ employees = new LinkedList<Employee>(employees);
+ Collections.sort(employees, new Comparator<Employee>() {
+ @Override
+ public int compare(Employee o1, Employee o2) {
+ if (sortMode == SortMode.single) {
+ Column lastColumn = sortPriority.get(sortPriority.size() - 1);
+ return lastColumn.compare(o1, o2);
+ } else {
+ for (Column column : sortPriority) {
+ if (column.compare(o1, o2) != 0) {
+ return column.compare(o1, o2);
+ }
+ }
+ return 0;
+ }
+ }
+ });
+ }
+
+ public enum Column {
+ NAME, TITLE, BIRTHDAY;
+
+ AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+ SortOrder sortOrder = SortOrder.unsorted;
+
+ public static void resetAll() {
+ for (Column value : values()) {
+ value.reset();
+ }
+ }
+
+ public void reset() {
+ sortOrder = SortOrder.unsorted;
+ }
+
+ public void sort(DataTable dataTable) {
+ sortOrder = (sortOrder == SortOrder.ascending) ? SortOrder.descending :
SortOrder.ascending;
+ int headerIndex = this.ordinal() + 2; // 1 for index; 1 for additional header
on top of links
+
guardXhr(selenium).click(dataTable.getHeader().getNthOccurence(headerIndex).getChild(jq("a")));
+ }
+
+ public int compare(Employee o1, Employee o2) {
+ int result;
+
+ switch (this) {
+ case NAME:
+ result = o1.getName().compareToIgnoreCase(o2.getName());
+ break;
+ case TITLE:
+ result = o1.getTitle().compareToIgnoreCase(o2.getTitle());
+ break;
+ case BIRTHDAY:
+ result = o1.getBirthdate().compareTo(o2.getBirthdate());
+ break;
+ default:
+ throw new IllegalStateException();
+ }
+
+ switch (sortOrder) {
+ case ascending:
+ return result;
+ case descending:
+ return 0 - result;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+ }
+
+}