Author: andrei_exadel
Date: 2008-10-21 08:46:22 -0400 (Tue, 21 Oct 2008)
New Revision: 10848
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataTable/dataTableAutoTest.xhtml
Removed:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataTable/dataTableTest.xhtml
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataTableBean.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataTableTest.java
Log:
DataTable Test
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataTableBean.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataTableBean.java 2008-10-21
11:42:23 UTC (rev 10847)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataTableBean.java 2008-10-21
12:46:22 UTC (rev 10848)
@@ -1,31 +1,157 @@
package org.ajax4jsf.bean;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import javax.faces.component.UIComponent;
import javax.faces.event.ActionEvent;
-import org.ajax4jsf.model.Column;
+import org.ajax4jsf.model.DataComponentState;
+import org.richfaces.component.html.HtmlDataTable;
import org.richfaces.model.Ordering;
@SuppressWarnings("unchecked")
public class DataTableBean {
- private int rows = 20;
+ private int rows = 6;
+
+ private Ordering ordering = Ordering.UNSORTED;
- private int column = 3;
+ private List model;
- private int begin = 1;
+ private ArrayList<String> prioritList = new ArrayList<String>();
- private int end = 10;
+ private boolean filterMethodTurnOn = false;
+
+ private Set<Integer> ajaxKeys = new HashSet<Integer>();
+
+ private Object componentState;
+
- private List model;
+ private final Comparator<Data> comparator = new Comparator<Data>(){
- private List columns;
+ public int compare(Data o1, Data o2) {
+ return o1.v3.compareTo(o2.v3);
+ };
+ };
- private Ordering ordering;
+ public boolean filterMethod(Object o) {
+ if (!filterMethodTurnOn) {
+ return true;
+ }
+ Data data = (Data)o;
+ return data.v5 <= 5;
+ }
+ public class Data {
+ Integer v1;
+ Integer v2;
+ Integer v3;
+ Integer v4;
+ Integer v5;
+
+ String input;
+
+ public Data(Integer v1, Integer v2,Integer v3,Integer v4, Integer v5) {
+ this.v1 = v1;
+ this.v2 = v2;
+ this.v3 = v3;
+ this.v4 = v4;
+ this.v5 = v5;
+ }
+
+ /**
+ * @return the v1
+ */
+ public Integer getV1() {
+ return v1;
+ }
+
+ /**
+ * @param v1 the v1 to set
+ */
+ public void setV1(Integer v1) {
+ this.v1 = v1;
+ }
+
+ /**
+ * @return the v2
+ */
+ public Integer getV2() {
+ return v2;
+ }
+
+ /**
+ * @param v2 the v2 to set
+ */
+ public void setV2(Integer v2) {
+ this.v2 = v2;
+ }
+
+ /**
+ * @return the v3
+ */
+ public Integer getV3() {
+ return v3;
+ }
+
+ /**
+ * @param v3 the v3 to set
+ */
+ public void setV3(Integer v3) {
+ this.v3 = v3;
+ }
+
+ /**
+ * @return the v4
+ */
+ public Integer getV4() {
+ return v4;
+ }
+
+ /**
+ * @param v4 the v4 to set
+ */
+ public void setV4(Integer v4) {
+ this.v4 = v4;
+ }
+
+ /**
+ * @return the v5
+ */
+ public Integer getV5() {
+ return v5;
+ }
+
+ /**
+ * @param v5 the v5 to set
+ */
+ public void setV5(Integer v5) {
+ this.v5 = v5;
+ }
+
+ /**
+ * @return the input
+ */
+ public String getInput() {
+ return input;
+ }
+
+ /**
+ * @param input the input to set
+ */
+ public void setInput(String input) {
+ this.input = input;
+ }
+
+
+
+ }
+
public DataTableBean() {
init();
}
@@ -34,14 +160,42 @@
init();
}
- public void reset(ActionEvent event) {
- rows = 20;
- column = 3;
- begin = 1;
- end = 10;
+ public void reset() {
+ rows = 6;
+ filterMethodTurnOn = false;
+ prioritList = new ArrayList<String>();
+ ordering = Ordering.UNSORTED;
init();
}
+ public String testASCSorting() {
+ prioritList.clear();
+ prioritList.add("Column1");
+ ordering = Ordering.ASCENDING;
+ return null;
+ }
+
+ public String testDESCSorting() {
+ prioritList.clear();
+ prioritList.add("Column1");
+
+ ordering = Ordering.DESCENDING;
+ return null;
+ }
+
+ public String testFilterMethod() {
+ filterMethodTurnOn = true;
+ return null;
+ }
+
+ public String testComponentState() throws Exception {
+ if (!(componentState instanceof DataComponentState)) {
+ throw new Exception("");
+ }
+ return null;
+ }
+
+
public String getDate() {
return new Date().toLocaleString();
}
@@ -49,35 +203,16 @@
private void init() {
model = new ArrayList();
for (int i = 0; i < rows; i++) {
- String [] m = new String[column];
- for (int j = 0; j < column; j++) {
- m[j] = String.valueOf(i + j);
- }
- model.add(m);
+ Data data = new Data(i, i + 1, i + 2, i + 3, i + 4);
+ model.add(data);
}
-
- columns = new ArrayList();
- for (int i = 0; i < column; i++) {
- columns.add(new Column("header","footer", i));
- }
+ ajaxKeys.add(0);
+ ajaxKeys.add(2);
+ ajaxKeys.add(4);
}
- /**
- * @return the columns
- */
- public int getColumn() {
- return column;
- }
/**
- * @param columns
- * the columns to set
- */
- public void setColumn(int column) {
- this.column = column;
- }
-
- /**
* @return the rows
*/
public int getRows() {
@@ -108,21 +243,13 @@
}
/**
- * @return the columns
+ * @return the comparator
*/
- public List getColumns() {
- return columns;
+ public Comparator<Data> getComparator() {
+ return comparator;
}
/**
- * @param columns
- * the columns to set
- */
- public void setColumns(List columns) {
- this.columns = columns;
- }
-
- /**
* @return the ordering
*/
public Ordering getOrdering() {
@@ -137,31 +264,46 @@
}
/**
- * @return the begin
+ * @return the prioritList
*/
- public int getBegin() {
- return begin;
+ public ArrayList<String> getPrioritList() {
+ return prioritList;
}
/**
- * @param begin the begin to set
+ * @param prioritList the prioritList to set
*/
- public void setBegin(int begin) {
- this.begin = begin;
+ public void setPrioritList(ArrayList<String> prioritList) {
+ this.prioritList = prioritList;
}
+
/**
- * @return the end
+ * @return the ajaxKeys
*/
- public int getEnd() {
- return end;
+ public Set<Integer> getAjaxKeys() {
+ return ajaxKeys;
}
/**
- * @param end the end to set
+ * @param ajaxKeys the ajaxKeys to set
*/
- public void setEnd(int end) {
- this.end = end;
+ public void setAjaxKeys(Set<Integer> ajaxKeys) {
+ this.ajaxKeys = ajaxKeys;
}
+ /**
+ * @return the componentState
+ */
+ public Object getComponentState() {
+ return componentState;
+ }
+
+ /**
+ * @param componentState the componentState to set
+ */
+ public void setComponentState(Object componentState) {
+ this.componentState = componentState;
+ }
+
}
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataTable/dataTableAutoTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataTable/dataTableAutoTest.xhtml
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataTable/dataTableAutoTest.xhtml 2008-10-21
12:46:22 UTC (rev 10848)
@@ -0,0 +1,27 @@
+<!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.autoTestTemplate}">
+ <ui:define name="component">
+ <rich:dataTable id="componentId"
+ value="#{dataTableBean.model}"
+ rendered="#{autoTestBean.rendered}"
+ var="var"
+ style="width: 100%; color: yellow"
+ >
+
+ <rich:column id="col1">
+ <f:facet name="header">
+ <h:outputText value="Column1"></h:outputText>
+ </f:facet>
+ <h:outputText id="v1" value="#{var.v1}" /><br/>
+ </rich:column>
+ </rich:dataTable>
+ </ui:define>
+</ui:composition>
+</html>
\ No newline at end of file
Deleted:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataTable/dataTableTest.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataTableTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataTableTest.java 2008-10-21
11:42:23 UTC (rev 10847)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataTableTest.java 2008-10-21
12:46:22 UTC (rev 10848)
@@ -1,189 +1,345 @@
package org.richfaces.testng;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.ajax4jsf.template.Template;
+import org.richfaces.AutoTester;
import org.richfaces.SeleniumTestBase;
+import org.richfaces.model.Ordering;
import org.testng.Assert;
import org.testng.annotations.Test;
public class DataTableTest extends SeleniumTestBase {
+
+ private String dataTableId;
+
+ private String dataTableBodyId;
+
+ private String commandId;
+
+ private static final String FORM_ID = "_form:";
+
+ private static final String CONTROLS_FORM = "_controls:";
+
+ private static final String RESET_METHOD = "#{dataTableBean.reset}";
+
+ private static final String [] dataTableClassNames = new String [] {
+ "dr-table",
+ "rich-table"
+ };
+
+ private static final Map<String, String> styleAttributes = new HashMap<String,
String>();
+ static {
+ styleAttributes.put("width", "100%");
+ styleAttributes.put("color", "yellow");
+ }
+
+ private void init(String parentId) {
+ dataTableId = parentId + FORM_ID + "table";
+ dataTableBodyId = dataTableId + ":tb";
+ commandId = parentId + FORM_ID + "submit";
+ }
+
public String getTestUrl() {
return "pages/dataTable/dataTableTest.xhtml";
}
+
+ @Override
+ public String getAutoTestUrl() {
+ return "pages/dataTable/dataTableAutoTest.xhtml";
+ }
@Test
- public void testDataTable(Template template) {
- renderPage(template);
-
- String parentId = getParentId() + "_form:";
- String dataTableId = parentId + "table";
+ public void testSortByAttribute(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
- reset(parentId + "reset");
- reRenderForm();
-
- writeStatus("Check columns count equals to 3 ");
- assertColumnsCount(3, dataTableId);
- writeStatus("Check rows count equals to 20 ");
- assertRowsCount(20, dataTableId);
-
- String columnsId = getColumnId(dataTableId, 0);
-
- writeStatus("Check inputs' values ");
- assertInputValue(dataTableId, 0, columnsId, "0");
- assertInputValue(dataTableId, 5, columnsId, "5");
- assertInputValue(dataTableId, 19, columnsId, "19");
-
- columnsId = getColumnId(dataTableId, 1);
-
- assertInputValue(dataTableId, 0, columnsId, "1");
- assertInputValue(dataTableId, 7, columnsId, "8");
- assertInputValue(dataTableId, 19, columnsId, "20");
-
- columnsId = getColumnId(dataTableId, 2);
-
- assertInputValue(dataTableId, 0, columnsId, "2");
- assertInputValue(dataTableId, 11, columnsId, "13");
- assertInputValue(dataTableId, 19, columnsId, "21");
-
- writeStatus("Insert some values ");
- insertInputValue(dataTableId, 0, getColumnId(dataTableId, 0), "000");
- insertInputValue(dataTableId, 19, getColumnId(dataTableId, 2), "777");
-
- writeStatus("Rerender table");
- clickById(getParentId() + "_form:submit");
- waitForAjaxCompletion();
-
- writeStatus("Check values entered ");
- assertInputValue(dataTableId, 0, getColumnId(dataTableId, 0), "000");
- assertInputValue(dataTableId, 19, getColumnId(dataTableId, 2), "777");
-
- columnsId = getColumnId(dataTableId, 0);
-
- writeStatus("Sort ASC by 1'st column ");
- sortColumn(dataTableId, columnsId);
- writeStatus("Check ordering");
- assertInputValue(dataTableId, 0, columnsId, "000");
- assertInputValue(dataTableId, 1, columnsId, "1");
- assertInputValue(dataTableId, 18, columnsId, "8");
- assertInputValue(dataTableId, 19, columnsId, "9");
-
- writeStatus("Sort DESC by 1'st column ");
- sortColumn(dataTableId, columnsId);
- writeStatus("Check ordering");
- assertInputValue(dataTableId, 0, columnsId, "9");
- assertInputValue(dataTableId, 1, columnsId, "8");
- assertInputValue(dataTableId, 18, columnsId, "1");
- assertInputValue(dataTableId, 19, columnsId, "000");
-
- columnsId = getColumnId(dataTableId, 2);
-
- writeStatus("Sort ASC by 3'st column ");
- sortColumn(dataTableId, columnsId);
- writeStatus("Check ordering");
- assertInputValue(dataTableId, 0, columnsId, "10");
- assertInputValue(dataTableId, 1, columnsId, "11");
- assertInputValue(dataTableId, 18, columnsId, "8");
- assertInputValue(dataTableId, 19, columnsId, "9");
-
- writeStatus("Set columns count == 5, rows count == 10");
- changeColumnCount(getParentId(), 10, 5, 0, 100);
-
- writeStatus("Check columns count equals to 5 ");
- assertColumnsCount(5, dataTableId);
- writeStatus("Check rows count equals to 10 ");
- assertRowsCount(10, dataTableId);
-
- columnsId = getColumnId(dataTableId, 0);
-
- writeStatus("Check inputs' values ");
- assertInputValue(dataTableId, 0, columnsId, "0");
- assertInputValue(dataTableId, 5, columnsId, "5");
- assertInputValue(dataTableId, 9, columnsId, "9");
-
- columnsId = getColumnId(dataTableId, 1);
-
- assertInputValue(dataTableId, 0, columnsId, "1");
- assertInputValue(dataTableId, 7, columnsId, "8");
- assertInputValue(dataTableId, 9, columnsId, "10");
-
- columnsId = getColumnId(dataTableId, 4);
-
- assertInputValue(dataTableId, 0, columnsId, "4");
- assertInputValue(dataTableId, 2, columnsId, "6");
- assertInputValue(dataTableId, 9, columnsId, "13");
-
- writeStatus("Sort ASC by the last column ");
- sortColumn(dataTableId, columnsId);
- writeStatus("Check ordering");
- assertInputValue(dataTableId, 0, columnsId, "10");
- assertInputValue(dataTableId, 2, columnsId, "12");
- assertInputValue(dataTableId, 9, columnsId, "9");
-
- writeStatus("Sort DESC by the last column ");
- sortColumn(dataTableId, columnsId);
- writeStatus("Check ordering");
- assertInputValue(dataTableId, 0, columnsId, "9");
- assertInputValue(dataTableId, 2, columnsId, "7");
- assertInputValue(dataTableId, 9, columnsId, "10");
-
- columnsId = getColumnId(dataTableId, 2);
- writeStatus("Sort ASC by the 3d column ");
- sortColumn(dataTableId, columnsId);
-
- writeStatus("Check ordering");
- assertInputValue(dataTableId, 0, columnsId, "10");
- assertInputValue(dataTableId, 2, columnsId, "2");
- assertInputValue(dataTableId, 9, columnsId, "9");
-
- changeColumnCount(getParentId(),2, 5, 2, 2);
- assertColumnsCount(1, dataTableId);
- assertRowsCount(2, dataTableId);
-
- changeColumnCount(getParentId(), 10, 5, 10, 0);
- assertRowsCount(0, dataTableId);
-
+ testSorting(2, new String [] {"1", "2", "3",
"4", "5", "6"});
+ testSorting(3, new String [] {"2", "3", "4",
"5", "6", "7"});
+ testSortIcon(2, Ordering.UNSORTED);
+
+ clickSort(2);
+
+ testSorting(2, new String [] {"1", "2", "3",
"4", "5", "6"});
+ testSorting(3, new String [] {"2", "3", "4",
"5", "6", "7"});
+ testSortIcon(2, Ordering.ASCENDING);
+
+ clickSort(2);
+
+ testSorting(2, new String [] {"6", "5", "4",
"3", "2", "1"});
+ testSorting(3, new String [] {"7", "6", "5",
"4", "3", "2"});
+ testSortIcon(2, Ordering.DESCENDING);
+
}
- public void reset(String id) {
- clickAjaxCommandAndWait(id);
+ @Test
+ public void testSortComparator(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ testSorting(2, new String [] {"1", "2", "3",
"4", "5", "6"});
+ testSorting(3, new String [] {"2", "3", "4",
"5", "6", "7"});
+ testSortIcon(3, Ordering.UNSORTED);
+
+ clickSort(3);
+
+ testSorting(2, new String [] {"1", "2", "3",
"4", "5", "6"});
+ testSorting(3, new String [] {"2", "3", "4",
"5", "6", "7"});
+ testSortIcon(3, Ordering.ASCENDING);
+
+ clickSort(3);
+
+ testSorting(2, new String [] {"6", "5", "4",
"3", "2", "1"});
+ testSorting(3, new String [] {"7", "6", "5",
"4", "3", "2"});
+ testSortIcon(3, Ordering.DESCENDING);
}
-
- private String getColumnId(String tableId, int i) {
- String script = "$('" + tableId + "').rows[0].cells["
+ String.valueOf(i) + "].id";
- String id = runScript(script);
- id = id.replace(tableId + ":", "");
- id = id.replace("header", "");
- return id;
+
+ @Test
+ public void testExternalSorting(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ String commandId = getParentId() + CONTROLS_FORM + "testACS";
+ clickCommandAndWait(commandId);
+
+ testSorting(1, new String [] {"0", "1", "2",
"3", "4", "5"});
+ testSortIcon(1, Ordering.ASCENDING);
+
+ commandId = getParentId() + CONTROLS_FORM + "testDESC";
+ clickCommandAndWait(commandId);
+
+ testSorting(1, new String [] {"5", "4", "3",
"2", "1", "0"});
+ testSortIcon(1, Ordering.DESCENDING);
+
+
}
-
- private void changeColumnCount(String parentId, int rows, int columns, int begin, int
end) {
- String script =
"$('"+parentId+"_controls:rows').value='" +
String.valueOf(rows) + "';";
- runScript(script);
- script =
"$('"+parentId+"_controls:column').value='" +
String.valueOf(columns) + "';";
- runScript(script);
- script =
"$('"+parentId+"_controls:begin').value='" +
String.valueOf(begin) + "';";
- runScript(script);
- script = "$('"+parentId+"_controls:end').value='"
+ String.valueOf(end) + "';";
- runScript(script);
- clickById(parentId +"_controls:apply");
- waitForAjaxCompletion();
+
+ @Test
+ public void testFilterBy(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ String filterId = dataTableId + ":col4fsp";
+ setValueById(filterId, "5");
+ clickAjaxCommandAndWait(filterId);
+
+ testRowsCount(1);
+ testSorting(4, new String [] { "5" });
+
+ setValueById(filterId, "3");
+ clickAjaxCommandAndWait(filterId);
+
+ testRowsCount(1);
+ testSorting(4, new String [] { "3" });
}
-
- private void sortColumn(String tableId, String columnId) {
- clickById(tableId + ":" + columnId + "header");
- waitForAjaxCompletion();
+
+ @Test
+ public void testFilterMethod(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ String commandId = getParentId() + CONTROLS_FORM + "testFilterMethod";
+ clickCommandAndWait(commandId);
+
+ testRowsCount(2);
+ testSorting(5, new String [] { "4", "5" });
+ testSorting(3, new String [] { "2", "3" });
+
}
-
- private void insertInputValue(String tableId, int row, String inputId, String value)
{
- String id = tableId + ":" + row + ":" + inputId;
- String script = ("$('" + id +
"').firstChild.value='" + value + "';");
- runScript(script);
+
+ @Test
+ public void testNestedInput(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ String inputId = dataTableId + ":0:input";
+ setValueById(inputId, "One");
+
+ inputId = dataTableId + ":1:input";
+ setValueById(inputId, "Two");
+
+ inputId = dataTableId + ":2:input";
+ setValueById(inputId, "Three");
+
+ clickCommandAndWait(commandId);
+
+ AssertValueEquals(dataTableId + ":0:input", "One", "Nested
input does not work.");
+ AssertValueEquals(dataTableId + ":1:input", "Two", "Nested
input does not work.");
+ AssertValueEquals(dataTableId + ":2:input", "Three",
"Nested input does not work.");
+
}
-
- private void assertInputValue(String tableId, int row, String inputId, String value)
{
- String id = tableId + ":" + row + ":" + inputId;
- String script = "$('" + id + "').firstChild.value";
- Assert.assertEquals(runScript(script), value);
+
+ @Test
+ public void testFacetsAndColumnsHeaders(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ String title = getFacetTitle(true);
+ Assert.assertEquals(title, "Data Table header", "DataTable header
missed");
+
+ title = getFacetTitle(false);
+ Assert.assertEquals(title, "Data Table footer", "Data Table footer
missed");
+
+ for (int i = 1; i < 6; i++) {
+ String headerId = dataTableId + ":col" + i +
"header:sortDiv";
+ AssertTextEquals(headerId, "Column" + i, "Column
["+i+"] header incorrect");
+ }
}
+
+ @Test
+ public void testAjaxKeysAttribute(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ String [] oldValues = new String[6];
+ for (int i = 0; i < 6; i++) {
+ String id = dataTableId + ":" +i + ":date";
+ oldValues[i] = getTextById(id);
+ }
+
+ pause(1500, dataTableId);
+ String linkId = dataTableId + ":0:link";
+ clickAjaxCommandAndWait(linkId);
+
+ String [] newValues = new String[6];
+ for (int i = 0; i < 6; i++) {
+ String id = dataTableId + ":" +i + ":date";
+ newValues[i] = getTextById(id);
+ }
+
+
+ //equal
+
+ List<Integer> notEquals = new ArrayList<Integer>();
+
+ for (int i = 0; i < 6; i++) {
+ if (!oldValues[i].equals(newValues[i])) {
+ notEquals.add(i);
+ }
+ }
+
+ if (notEquals.size() != 3 || !notEquals.get(0).equals(0)
+ || !notEquals.get(1).equals(2)
+ || !notEquals.get(2).equals(4)) {
+ Assert.fail("Ajax keys attribute does not work. [0,2,4] rows should
be reRendered only. But was: " + toString(notEquals));
+ }
+
+ }
+
+
+
+ @Test
+ public void testVars(Template template) {
+ renderPage(template, RESET_METHOD);
+ init(getParentId());
+
+ for (int i = 0; i < 6; i++) {
+ String rowNId = dataTableId + ":" + i + ":rowN";
+ String stateId = dataTableId + ":" + i + ":state";
+ AssertTextEquals(rowNId, String.valueOf(i), "Row var attribute does not
work");
+ Assert.assertNotNull(getTextById(stateId), "State request var does not
present");
+ }
+
+ String commandId = getParentId() + CONTROLS_FORM +
"testComponentState";
+ try {
+ clickCommandAndWait(commandId);
+ }catch (Exception e) {
+ Assert.fail("Component state does not work. State object does not references to
HTMLDataTable");
+ }
+
+ }
+
+
+ @Test
+ public void testHTMLAndRendered (Template template){
+ AutoTester autoTester = getAutoTester(this);
+ autoTester.renderPage(template, RESET_METHOD);
+
+ autoTester.testStyleAndClasses(dataTableClassNames, styleAttributes);
+ autoTester.testRendered();
+ }
+
+
+ private void testRowsCount(int rows) {
+ assertRowsCount(rows, dataTableId);
+ }
+
+ private void testSorting(int columns, String [] values) {
+ columns--;
+ int rowCount = values.length;
+ assertRowsCount(rowCount, dataTableId);
+
+ int i = 0;
+ String [] actualValues = new String[values.length];
+ for (@SuppressWarnings("unused")
+ String v : values) {
+ actualValues[i] = getCellText(i, columns);
+ i++;
+ }
+ i = 0;
+ for (String v : values) {
+ if (!v.equals(actualValues[i])) {
+ Assert.fail("Columns was sorted incorectly. Expected: " +
toString(values) + " But was: " + toString(actualValues));
+ }
+ i++;
+ }
+
+ }
+
+ private void clickSort(int column) {
+ String commandId = dataTableId + ":col" + column + "header";
+ clickAjaxCommandAndWait(commandId);
+ }
+
+ private String getCellText(int row, int cell) {
+ StringBuffer b = new StringBuffer(getElementById(dataTableBodyId));
+
b.append(".rows[").append(row).append("].cells[").append(cell).append("].firstChild.innerHTML");
+ return runScript(b.toString());
+ }
+
+ private void testSortIcon(int column, Ordering ordering) {
+ String id = dataTableId + ":col" + column + "header:sortDiv";
+ StringBuffer b = new StringBuffer(getElementById(id));
+ b.append(".firstChild.childNodes[1].src");
+ String src = runScript(b.toString());
+ if (ordering == Ordering.UNSORTED) {
+ Assert.assertTrue(src.indexOf("DataTableIconSortNone") != -1,
+ "Column [" + column + "] sort image is invalid");
+ } else if (ordering == Ordering.ASCENDING) {
+ Assert.assertTrue(src.indexOf("DataTableIconSortAsc") != -1,
+ "Column [" + column + "] sort image is invalid");
+ } else if (ordering == Ordering.DESCENDING) {
+ Assert.assertTrue(src.indexOf("DataTableIconSortDesc") != -1,
+ "Column [" + column + "] sort image is invalid");
+ }
+ }
+
+ private String toString(String[] ss) {
+ StringBuffer b = new StringBuffer();
+ for (String s : ss) {
+ b.append(s).append(",");
+ }
+ return b.toString();
+ }
+
+ private String toString(List<?> ss) {
+ StringBuffer b = new StringBuffer();
+ for (Object s : ss) {
+ b.append(s).append(",");
+ }
+ return b.toString();
+ }
+ private String getFacetTitle(boolean header) {
+ StringBuffer b = new StringBuffer(getElementById(dataTableId));
+ b.append(".").append(header ? "tHead" : "tFoot").append(
+ ".firstChild.firstChild.innerHTML");
+ return runScript(b.toString());
+ }
+
+
}