Author: andrei_exadel
Date: 2009-02-17 10:17:59 -0500 (Tue, 17 Feb 2009)
New Revision: 12683
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/columns/testColumnsSorting.xhtml
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ColumnsBean.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ColumnsTest.java
Log:
RF-6099
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ColumnsBean.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ColumnsBean.java 2009-02-17
12:24:01 UTC (rev 12682)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/ColumnsBean.java 2009-02-17
15:17:59 UTC (rev 12683)
@@ -1,11 +1,14 @@
package org.ajax4jsf.bean;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import javax.faces.event.ActionEvent;
+import org.richfaces.model.Ordering;
+
public class ColumnsBean {
static final String ROW_PREFIX = "Row";
@@ -16,6 +19,7 @@
public class Column {
String header;
+ Ordering ordering;
public Column(String header) {
super();
@@ -32,10 +36,24 @@
public void setHeader(String header) {
this.header = header;
}
+
+ public Ordering getOrdering() {
+ return ordering;
+ }
+
+ public void setOrdering(Ordering ordering) {
+ this.ordering = ordering;
+ }
+
}
public class Row {
String input;
+ int value;
+
+ public Row(int i) {
+ this.value = i;
+ }
public String getInput() {
return input;
@@ -44,9 +62,25 @@
public void setInput(String input) {
this.input = input;
}
-
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+
}
+ Comparator<Row[]> comparator = new Comparator<Row[]>(){
+
+ public int compare(Row[] o1, Row[] o2) {
+ return new Integer(o1[0].value).compareTo(o2[0].value);
+ }
+
+ };
+
private int rows = 2;
private int cols = 3;
@@ -69,7 +103,7 @@
for (int i = 0; i < rows; i++) {
Row[] rows = new Row [cols];
for (int j=0; j<cols; j++) {
- rows[j] = new Row();
+ rows[j] = new Row(i + j);
}
model.add(rows);
}
@@ -121,5 +155,13 @@
this.status = status;
}
+ public Comparator<Row[]> getComparator() {
+ return comparator;
+ }
+
+ public void setComparator(Comparator<Row[]> comparator) {
+ this.comparator = comparator;
+ }
+
}
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/columns/testColumnsSorting.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/columns/testColumnsSorting.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/columns/testColumnsSorting.xhtml 2009-02-17
15:17:59 UTC (rev 12683)
@@ -0,0 +1,37 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition template="#{templateBean.template}">
+ <ui:define name="component">
+ <h:form id="_form">
+ <br/><br/>
+ <rich:dataTable id="table" value="#{columnsBean.model}"
var="row">
+ <rich:columns id="c#{index}"
value="#{columnsBean.columns}" var="column"
+ index="index" sortBy="#{row[index].value}"
sortOrder="#{column.ordering}">
+ <f:facet name="header">
+ <h:outputText value="#{column.ordering}"></h:outputText>
+ </f:facet>
+ <h:outputText value="#{row[index].value}" />
+ </rich:columns>
+ </rich:dataTable><br/>
+
+ <rich:dataTable id="table2" value="#{columnsBean.model}"
var="row">
+ <rich:columns id="c#{index}"
value="#{columnsBean.columns}" var="column"
+ index="index" comparator="#{columnsBean.comparator}"
sortOrder="#{column.ordering}">
+ <f:facet name="header">
+ <h:outputText value="#{column.ordering}"></h:outputText>
+ </f:facet>
+ <h:outputText value="#{row[index].value}" />
+ </rich:columns>
+ </rich:dataTable>
+
+ <h:commandButton id="submit"
value="Submit"></h:commandButton>
+ </h:form>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ColumnsTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ColumnsTest.java 2009-02-17
12:24:01 UTC (rev 12682)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/ColumnsTest.java 2009-02-17
15:17:59 UTC (rev 12683)
@@ -20,32 +20,37 @@
*/
package org.richfaces.testng;
+import java.util.Arrays;
+
import org.ajax4jsf.template.Template;
import org.richfaces.SeleniumTestBase;
+import org.richfaces.model.Ordering;
import org.testng.Assert;
import org.testng.annotations.Test;
public class ColumnsTest extends SeleniumTestBase {
static final String RESET_METHOD = "#{columnsBean.reset}";
+
+ static final String SORTING_TEST_URL =
"pages/columns/testColumnsSorting.xhtml";
- private static final String DATA_TABLE = "table";
+
+ @Test
+ public void testSortingFeature(Template template) {
+ renderPage(SORTING_TEST_URL, template, RESET_METHOD);
+
+ final int columnsCount = 3;
+
+ // Test sorting by sortBy attribute
+ testOrdering(getParentId() + "_form:table", columnsCount);
- private static final String APPLY_BUTTON = "apply";
-
- private static final String RESET_BUTTON = "reset";
-
- private static final String CTRL_FORM = "_controls";
-
- private static final String ROWS_COUNT_CTRL = "rows";
-
- private static final String COLUMNS_COUNT_CTRL = "rows";
-
- private static final String BEGIN_ROW = "begin";
-
- private static final String END_ROW = "end";
+ // Test sorting by comparator attribute
+ testOrdering(getParentId() + "_form:table2", columnsCount);
+
+ }
+
+
-
@Test
public void testOutputAndNestedInputsAndCommands(Template template) {
renderPage(template, RESET_METHOD);
@@ -114,65 +119,7 @@
Assert.fail("Nested command dont work.");
}
}
-
- // @Test
- public void testColumnsComponentLayout(Template template) {
- renderPage(template);
- writeStatus("Testing columns component layout");
-
- String parentId = getParentId() + "_form:";
- String tableId = parentId + DATA_TABLE;
-
- writeStatus("Check columns count equals to 3 ");
- assertColumnsCount(3, tableId);
-
- writeStatus("Check rows count equals to 20 ");
- assertRowsCount(20, tableId);
-
- writeStatus("Check columns headers");
-
- AssertTextEquals("xpath=//table[@id='" + tableId +
"']/tHead/tr[1]/th[1]", "header0");
- AssertTextEquals("xpath=//table[@id='" + tableId +
"']/tHead/tr[1]/th[2]", "header1");
- AssertTextEquals("xpath=//table[@id='" + tableId +
"']/tHead/tr[1]/th[3]", "header2");
-
- writeStatus("Check columns footers");
-
- AssertTextEquals("xpath=//table[@id='" + tableId +
"']/tFoot/tr[1]/td[1]", "footer0");
- AssertTextEquals("xpath=//table[@id='" + tableId +
"']/tFoot/tr[1]/td[2]", "footer1");
- AssertTextEquals("xpath=//table[@id='" + tableId +
"']/tFoot/tr[1]/td[3]", "footer2");
-
- }
-
- // @Test
- public void testColumnsComponentCoreAttributes(Template template) {
- renderPage(template);
-
- writeStatus("Testing columns component core attributes");
-
- String parentId = getParentId() + "_form:";
- String tableId = parentId + DATA_TABLE;
-
- writeStatus("Set columns count == 5, rows count == 10");
- adjustTableParams(10, 5, 0, 10);
-
- writeStatus("Check columns count equals to 5 ");
- assertColumnsCount(5, tableId);
- writeStatus("Check rows count equals to 10 ");
- assertRowsCount(10, tableId);
-
- writeStatus("Set begin column == 2, end column == 2, rows count = 2");
- adjustTableParams(2, 5, 2, 2);
-
- writeStatus("Only one column has to be rendered");
- assertColumnsCount(1, tableId);
- assertRowsCount(2, tableId);
-
- writeStatus("Set end column == 0. there have to be no rows and no columns in
the table");
- adjustTableParams(10, 5, 10, 0);
- assertRowsCount(0, tableId);
-
- reset();
- }
+
private void setInputs(String tableId, int rows, int cols) {
for (int i=0;i<rows; i++) {
@@ -182,22 +129,53 @@
selenium.type(path, v);
}
}
-
}
-
- private void adjustTableParams(int rows, int columns, int begin, int end) {
- String ctrlForm = getParentId() + CTRL_FORM;
- type(ctrlForm + ":rows", String.valueOf(rows));
- type(ctrlForm + ":columns", String.valueOf(columns));
- type(ctrlForm + ":begin", String.valueOf(begin));
- type(ctrlForm + ":end", String.valueOf(end));
- clickAjaxCommandAndWait(ctrlForm + ":apply");
+
+ private void checkSorting (String tableId, int col, String [] expected) {
+ int l = expected.length;
+ String [] values = new String [l];
+ for (int i = 0; i < l; i++) {
+ values[i] =
selenium.getText("//table[@id='"+tableId+"']/tbody/tr["+(i+1)+"]/td["+(col+1)+"]");
+ }
+
+ for (int i = 0; i < l; i++) {
+ if (!expected[i].equals(values[i])) {
+ Assert.fail("Column number [" + col + "] was sorted unexpected.
Column's value should be: " + Arrays.toString(expected) + ". But was: "
+ Arrays.toString(values));
+ }
+ }
}
-
- private void reset() {
- clickAjaxCommandAndWait(getParentId() + CTRL_FORM + ":reset");
+
+ private void clickSort(String tableId, int col) {
+
selenium.click("//table[@id='"+tableId+"']/thead/tr[1]/th["+(col+1)+"]");
+ waitForAjaxCompletion();
}
+ private void checkSortOrderAttribute(String tableId, int col, Ordering ordering) {
+ String header =
selenium.getText("//table[@id='"+tableId+"']/thead/tr[1]/th["+(col+1)+"]");
+ if (!ordering.equals(Ordering.valueOf(header))) {
+ Assert.fail("SortOrder attribute was not changed for columns number
["+col+"]. Expected : " + ordering + ". But was : " + header);
+ }
+ }
+
+ private void testOrdering(String tableId, int cols) {
+ for (int i=0; i<cols; i++) {
+ clickSort(tableId, i);
+
+ checkSorting(tableId, 0, new String [] {"0", "1"});
+ checkSorting(tableId, 1, new String [] {"1", "2"});
+ checkSorting(tableId, 2, new String [] {"2", "3"});
+ checkSortOrderAttribute(tableId, i, Ordering.ASCENDING);
+
+ clickSort(tableId, i);
+
+ checkSorting(tableId, 0, new String [] {"1", "0"});
+ checkSorting(tableId, 1, new String [] {"2", "1"});
+ checkSorting(tableId, 2, new String [] {"3", "2"});
+ checkSortOrderAttribute(tableId, i, Ordering.DESCENDING);
+
+ }
+ }
+
@Override
public String getTestUrl() {