Author: andrei_exadel
Date: 2008-05-21 11:56:06 -0400 (Wed, 21 May 2008)
New Revision: 8678
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DataTableTest.java
Modified:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/DataTableBean.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/dataTable/dataTableTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
Log:
dataTable test completed
Modified:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/DataTableBean.java
===================================================================
---
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/DataTableBean.java 2008-05-21
15:02:25 UTC (rev 8677)
+++
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/DataTableBean.java 2008-05-21
15:56:06 UTC (rev 8678)
@@ -14,7 +14,7 @@
private int rows = 20;
- private int column = 1;
+ private int column = 3;
private List model;
Modified:
trunk/test-applications/seleniumTest/src/main/webapp/pages/dataTable/dataTableTest.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/src/main/webapp/pages/dataTable/dataTableTest.xhtml 2008-05-21
15:02:25 UTC (rev 8677)
+++
trunk/test-applications/seleniumTest/src/main/webapp/pages/dataTable/dataTableTest.xhtml 2008-05-21
15:56:06 UTC (rev 8678)
@@ -9,25 +9,43 @@
<ui:composition template="#{templateBean.template}">
<ui:define name="component">
<h:form id="_controls">
- <a4j:commandLink value="Rerender" id="apply2"
reRender="table1, date"></a4j:commandLink>
+ <table>
+ <tr>
+ <td>
+ Rows:
+ </td>
+ <td>
+ <h:inputText id="rows"
value="#{dataTableBean.rows}"></h:inputText>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Columns:
+ </td>
+ <td>
+ <h:inputText id="column"
value="#{dataTableBean.column}"></h:inputText>
+ </td>
+ </tr>
+ </table>
+ <a4j:commandLink value="Apply" id="apply"
actionListener="#{dataTableBean.init}" reRender="table,
date"></a4j:commandLink>
</h:form>
<h:form id="_form">
<h:outputText id="date"
value="#{dataTableBean.date}"></h:outputText>
- <rich:dataTable value="#{dataTableBean.model}" id="table1"
var="var">
- <rich:column sortBy="#{var[0]}"
sortOrder="#{dataTableBean.ordering}">
+ <rich:dataTable value="#{dataTableBean.model}" id="table"
var="var">
+ <rich:columns value="#{dataTableBean.columns}" var="col"
index="i" sortBy="#{var[i]}"
sortOrder="#{col.ordering}">
<f:facet name="header">
<h:outputText value="header"></h:outputText>
</f:facet>
<f:facet name="footer">
<h:outputText value="footer"></h:outputText>
</f:facet>
- <h:inputText value="#{var[0]}"></h:inputText>
- <h:outputText value="#{var[0]}"></h:outputText>
- </rich:column>
+ <h:inputText value="#{var[i]}"></h:inputText>
+ <h:outputText value="#{var[i]}"></h:outputText>
+ </rich:columns>
</rich:dataTable>
<br/>
-
+ <a4j:commandLink value="Submit" id="submit"
reRender="table, date"></a4j:commandLink>
</h:form>
</ui:define>
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-05-21
15:02:25 UTC (rev 8677)
+++
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-05-21
15:56:06 UTC (rev 8678)
@@ -133,6 +133,7 @@
* @param message
*/
public void writeStatus(String message) {
+ message = message.replace("'", "\\'");
StringBuffer buffer = new StringBuffer("writeStatus('");
buffer.append(message);
buffer.append("')");
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DataTableTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DataTableTest.java
(rev 0)
+++
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DataTableTest.java 2008-05-21
15:56:06 UTC (rev 8678)
@@ -0,0 +1,206 @@
+package org.richfaces;
+
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.ajax4jsf.test.base.Templates;
+import org.testng.Assert;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+public class DataTableTest extends SeleniumTestBase implements RichSeleniumTest {
+
+ public DataTableTest() {
+ super("http", "localhost", "8080");
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ super.startSelenium(browser);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ public String getTestUrl() {
+ return "/faces/pages/dataTable/dataTableTest.xhtml";
+ }
+
+ @Test
+ public void testDataTable() {
+ _testDataTable(Templates.SIMPLE);
+ }
+
+ private void _testDataTable(Templates template) {
+ renderPage(getTestUrl(), template);
+
+ String parentId = getParentId() + "_form:";
+ String dataTableId = parentId + "table";
+
+ writeStatus("Check columns count equals to 3 ");
+ assertColumnsCount(3, dataTableId);
+ writeStatus("Check rows count equals to 22 ");
+ assertRowsCount(22, dataTableId);
+
+ writeStatus("Check inputs' values ");
+ assertInputValue(dataTableId, 0, "j_id13", "0");
+ assertInputValue(dataTableId, 5, "j_id13", "5");
+ assertInputValue(dataTableId, 19, "j_id13", "19");
+
+ assertInputValue(dataTableId, 0, "j_id18", "1");
+ assertInputValue(dataTableId, 7, "j_id18", "8");
+ assertInputValue(dataTableId, 19, "j_id18", "20");
+
+ assertInputValue(dataTableId, 0, "j_id23", "2");
+ assertInputValue(dataTableId, 11, "j_id23", "13");
+ assertInputValue(dataTableId, 19, "j_id23", "21");
+
+ writeStatus("Insert some values ");
+ insertInputValue(dataTableId, 0, "j_id13", "000");
+ insertInputValue(dataTableId, 19, "j_id23", "777");
+
+ writeStatus("Rerender table");
+ clickById("_form:submit");
+ waitForAjaxCompletion();
+
+ writeStatus("Check values entered ");
+ assertInputValue(dataTableId, 0, "j_id13", "000");
+ assertInputValue(dataTableId, 19, "j_id23", "777");
+
+ writeStatus("Sort ASC by 1'st column ");
+ sortColumn(dataTableId, "j_id13");
+ writeStatus("Check ordering");
+ assertInputValue(dataTableId, 0, "j_id13", "000");
+ assertInputValue(dataTableId, 1, "j_id13", "1");
+ assertInputValue(dataTableId, 18, "j_id13", "8");
+ assertInputValue(dataTableId, 19, "j_id13", "9");
+
+ writeStatus("Sort DESC by 1'st column ");
+ sortColumn(dataTableId, "j_id13");
+ writeStatus("Check ordering");
+ assertInputValue(dataTableId, 0, "j_id13", "9");
+ assertInputValue(dataTableId, 1, "j_id13", "8");
+ assertInputValue(dataTableId, 18, "j_id13", "1");
+ assertInputValue(dataTableId, 19, "j_id13", "000");
+
+ writeStatus("Sort ASC by 1'st column ");
+ sortColumn(dataTableId, "j_id23");
+ writeStatus("Check ordering");
+ assertInputValue(dataTableId, 0, "j_id23", "10");
+ assertInputValue(dataTableId, 1, "j_id23", "11");
+ assertInputValue(dataTableId, 18, "j_id23", "8");
+ assertInputValue(dataTableId, 19, "j_id23", "9");
+
+ writeStatus("Set columns count == 5, rows count == 10");
+ changeColumnCount(10, 5);
+
+ String lastColumnId = getLastColumnId(dataTableId, 5);
+
+ writeStatus("Check columns count equals to 5 ");
+ assertColumnsCount(5, dataTableId);
+ writeStatus("Check rows count equals to 12 ");
+ assertRowsCount(12, dataTableId);
+
+ writeStatus("Check inputs' values ");
+ assertInputValue(dataTableId, 0, "j_id13", "0");
+ assertInputValue(dataTableId, 5, "j_id13", "5");
+ assertInputValue(dataTableId, 9, "j_id13", "9");
+
+ assertInputValue(dataTableId, 0, "j_id18", "1");
+ assertInputValue(dataTableId, 7, "j_id18", "8");
+ assertInputValue(dataTableId, 9, "j_id18", "10");
+
+ assertInputValue(dataTableId, 0, lastColumnId, "4");
+ assertInputValue(dataTableId, 2, lastColumnId, "6");
+ assertInputValue(dataTableId, 9, lastColumnId, "13");
+
+ writeStatus("Sort ASC by the last column ");
+ sortColumn(dataTableId, lastColumnId);
+ writeStatus("Check ordering");
+ assertInputValue(dataTableId, 0, lastColumnId, "10");
+ assertInputValue(dataTableId, 2, lastColumnId, "12");
+ assertInputValue(dataTableId, 9, lastColumnId, "9");
+
+ writeStatus("Sort DESC by the last column ");
+ sortColumn(dataTableId, lastColumnId);
+ writeStatus("Check ordering");
+ assertInputValue(dataTableId, 0, lastColumnId, "9");
+ assertInputValue(dataTableId, 2, lastColumnId, "7");
+ assertInputValue(dataTableId, 9, lastColumnId, "10");
+
+ writeStatus("Sort ASC by the 3d column ");
+ sortColumn(dataTableId, "j_id23");
+
+ writeStatus("Check ordering");
+ assertInputValue(dataTableId, 0, "j_id23", "10");
+ assertInputValue(dataTableId, 2, "j_id23", "2");
+ assertInputValue(dataTableId, 9, "j_id23", "9");
+
+
+ }
+
+ private String getLastColumnId (String tableId, int columnsCount) {
+ String script =
"$('"+tableId+"').rows[0].cells["+String.valueOf(columnsCount
- 1)+"].id";
+ String id = runScript(script);
+ id = id.replace(tableId + ":", "");
+ id = id.replace("header", "");
+ return id;
+ }
+
+ private void changeColumnCount(int rows, int columns) {
+ String script = "$('_controls:rows').value='" +
String.valueOf(rows) + "';";
+ runScript(script);
+ script = "$('_controls:column').value='" +
String.valueOf(columns) + "';";
+ runScript(script);
+ clickById("_controls:apply");
+ waitForAjaxCompletion();
+ }
+
+ private void sortColumn(String tableId, String columnId) {
+ clickById(tableId + ":" + columnId + "header");
+ waitForAjaxCompletion();
+ }
+
+
+ private void insertInputValue(String tableId, int row, String inputId, String value) {
+ String id = tableId + ":"+row+":"+inputId;
+ String script = ("$('" + id + "').firstChild.value='" +
value + "';");
+ runScript(script);
+ }
+
+
+ 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);
+ }
+
+ private void assertColumnsCount(int i, String tableId) {
+ StringBuffer script = new StringBuffer("$('");
+ script.append(tableId);
+ script.append("').rows[0].cells.length");
+
+ String count = runScript(script.toString());
+ Assert.assertEquals(count, String.valueOf(i));
+ }
+
+ private void assertRowsCount(int i, String tableId) {
+ StringBuffer script = new StringBuffer("$('");
+ script.append(tableId);
+ script.append("').rows.length");
+
+ String count = runScript(script.toString());
+ Assert.assertEquals(count, String.valueOf(i));
+ }
+
+}