Author: andrei_exadel
Date: 2008-10-09 11:44:53 -0400 (Thu, 09 Oct 2008)
New Revision: 10705
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataScrollerBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/layout/layout.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataScroller/dataScroller.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/test.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataScrollerTest.java
Log:
DataScrolle Test
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataScrollerBean.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataScrollerBean.java 2008-10-09
14:36:29 UTC (rev 10704)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DataScrollerBean.java 2008-10-09
15:44:53 UTC (rev 10705)
@@ -7,6 +7,7 @@
package org.ajax4jsf.bean;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import javax.faces.event.ActionEvent;
@@ -31,10 +32,53 @@
private Integer page;
+ private String reRender = null;
+
+ private Boolean limitToList = false;
+
+ private String input;
+
+ private String onComplete = null;
+
+ private Boolean bypassUpdates = false;
+
public DataScrollerBean() {
init();
}
+ public String maxPages() {
+ maxPages = 5;
+ return null;
+ }
+
+ public String rendered() {
+ rendered = false;
+ return null;
+ }
+
+ public String testReRender() {
+ reRender = "time";
+ onComplete = "window.dataScrollerComplete = true";
+ return null;
+ }
+
+ public String testByPassUpdates() {
+ bypassUpdates = true;
+ reRender = "input";
+ return null;
+ }
+
+ public String testLimitToList1() {
+ limitToList = true;
+ return null;
+ }
+
+ public String testLimitToList2() {
+ limitToList = true;
+ reRender = "scroller, tbl";
+ return null;
+ }
+
private void init() {
data = new ArrayList();
for (int i = 0; i < totalRows; i++) {
@@ -43,9 +87,26 @@
}
}
+ public void reset() {
+ tableRows = 1;
+ totalRows = 10;
+ maxPages = 10;
+ rendered = true;
+ page = null;
+ data = null;
+ reRender = null;
+ limitToList = false;
+ onComplete = null;
+ bypassUpdates = false;
+ }
+
public void apply(ActionEvent event) {
init();
}
+
+ public String getTime() {
+ return String.valueOf(new Date().getTime());
+ }
/**
* @return the rendered
@@ -65,6 +126,9 @@
* @return the data
*/
public List getData() {
+ if (data == null) {
+ init();
+ }
return data;
}
@@ -130,8 +194,44 @@
public void setPage(Integer page) {
this.page = page;
}
-
-
-
+ public String getReRender() {
+ return reRender;
+ }
+
+ public void setReRender(String reRender) {
+ this.reRender = reRender;
+ }
+
+ public Boolean getLimitToList() {
+ return limitToList;
+ }
+
+ public void setLimitToList(Boolean limitToList) {
+ this.limitToList = limitToList;
+ }
+
+ public String getInput() {
+ return input;
+ }
+
+ public void setInput(String input) {
+ this.input = input;
+ }
+
+ public String getOnComplete() {
+ return onComplete;
+ }
+
+ public void setOnComplete(String onComplete) {
+ this.onComplete = onComplete;
+ }
+
+ public Boolean getBypassUpdates() {
+ return bypassUpdates;
+ }
+
+ public void setBypassUpdates(Boolean bypassUpdates) {
+ this.bypassUpdates = bypassUpdates;
+ }
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/layout/layout.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataScroller/dataScroller.xhtml
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataScroller/dataScroller.xhtml 2008-10-09
14:36:29 UTC (rev 10704)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dataScroller/dataScroller.xhtml 2008-10-09
15:44:53 UTC (rev 10705)
@@ -14,10 +14,16 @@
<td>Total Rows:</td><td><h:inputText
value="#{dataScrollerBean.totalRows}" /></td>
</tr>
<tr>
- <td>Table Rows:</td><td><h:inputText
value="#{dataScrollerBean.tableRows}" /></td>
+ <td>Table Rows:</td><td><h:inputText id="tableRow"
value="#{dataScrollerBean.tableRows}" /></td>
</tr>
</table>
<h:commandButton id="apply"
actionListener="#{dataScrollerBean.apply}" value="apply"/>
+ <h:commandButton id="maxP"
action="#{dataScrollerBean.maxPages}" value="Test maxPages" />
+ <h:commandButton id="rendered"
action="#{dataScrollerBean.rendered}" value="Test rendered" />
+ <h:commandButton id="rerender"
action="#{dataScrollerBean.testReRender}" value="Test reRender" />
+ <h:commandButton id="limit2list1"
action="#{dataScrollerBean.testLimitToList1}" value="Test Limit2List1"
/>
+ <h:commandButton id="limit2list2"
action="#{dataScrollerBean.testLimitToList2}" value="Test Limit2List2"
/>
+ <h:commandButton id="bypassUpdates"
action="#{dataScrollerBean.testByPassUpdates}" value="Test
bypassUpdates" />
</h:form>
<br/>
<h:form id="_data">
@@ -33,9 +39,15 @@
onmouseout="EventQueue.fire('onmouseout')"
onmouseover="EventQueue.fire('onmouseover')"
onmouseup="EventQueue.fire('onmouseup')"
+ limitToList="#{dataScrollerBean.limitToList}"
+ reRender="#{dataScrollerBean.reRender}"
+ oncomplete="#{dataScrollerBean.onComplete}"
+ bypassUpdates="#{dataScrollerBean.bypassUpdates}"
/>
-
- <br/><br/>
+
+
+ <br/>
+ <br/>
<rich:dataTable id="tbl" value="#{dataScrollerBean.data}"
rows="#{dataScrollerBean.tableRows}" var="var">
<rich:column>
<f:facet name="header">
@@ -50,6 +62,12 @@
<h:outputText value="#{var[1]}" />
</rich:column>
</rich:dataTable>
+
+ <br/><br/>
+
+ <h:outputText id="time"
value="#{dataScrollerBean.time}"></h:outputText>
+ <h:inputText id="input"
value="#{dataScrollerBean.input}"></h:inputText>
+
</h:form>
</ui:define>
</ui:composition>
Modified: trunk/test-applications/seleniumTest/richfaces/src/main/webapp/test.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-09
14:36:29 UTC (rev 10704)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-10-09
15:44:53 UTC (rev 10705)
@@ -1056,4 +1056,11 @@
assertEvents(assertevent);
}
+
+ public String getElementById(String id) {
+ StringBuffer b = new StringBuffer("$('");
+ b.append(id);
+ b.append("')");
+ return b.toString();
+ }
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataScrollerTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataScrollerTest.java 2008-10-09
14:36:29 UTC (rev 10704)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DataScrollerTest.java 2008-10-09
15:44:53 UTC (rev 10705)
@@ -7,12 +7,10 @@
package org.richfaces.testng;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Arrays;
import java.util.List;
-import java.util.Map;
import org.ajax4jsf.template.Template;
-import org.richfaces.SeleniumEvent;
import org.richfaces.SeleniumTestBase;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -24,25 +22,242 @@
*/
public class DataScrollerTest extends SeleniumTestBase {
+ static final String RESET_METHOD_ME = "#{dataScrollerBean.reset}";
+
String dataScrollerId;
String dataScrollerTableId;
String dataTableId;
+ static final String [] activePageClasses = new String[] {
+ "dr-dscr-act","rich-datascr-act"
+ };
+
+ static final String [] inactivePageClasses = new String[] {
+ "dr-dscr-inact","rich-datascr-inact"
+ };
+ static final String [] activeForwardClasses = new String[] {
+ "dr-dscr-button","rich-datascr-button"
+ };
+
+ static final String [] inactiveForwardClasses = new String [] {
+ "dr-dscr-button-dsbld",
+ "rich-datascr-button-dsbld",
+ "dr-dscr-button",
+ "rich-datascr-button"
+ };
+
@Test
- public void testDataScroller(Template template) {
- renderPage(template);
- String parentId = getParentId();
+ public void testBypassUpdates(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ String inputId = getParentId() + "_data:input";
+ String commandId = getParentId() + "_controls:bypassUpdates";
+
+ clickCommandAndWait(commandId);
+
+ setValueById(inputId, "bypassUpdates = true");
+ clickControl(4);
+ AssertTextEquals(inputId, "", "BypassUpdates attribute does not
work.");
+
+ }
+
+ @Test
+ public void testLimitToList(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ String commandId = getParentId() + "_controls:limit2list1";
+ clickCommandAndWait(commandId);
+
+ String text = selenium.getTable("id=" + dataTableId +
"."+1+".1");
+
+ clickControl(4);
+
+ Assert.assertEquals(selenium.getTable("id=" + dataTableId +
"."+1+".1"), text, "LimitToList does not work. Datatable has been
rerendered");
+
+ commandId = getParentId() + "_controls:limit2list2";
+ clickCommandAndWait(commandId);
+
+ text = selenium.getTable("id=" + dataTableId +
"."+1+".1");
+ clickControl(5);
+ Assert.assertFalse(selenium.getTable("id=" + dataTableId +
"."+1+".1").equals(text), "LimitToList does not work. Datatable
has not been updated");
+
+ }
+
+ @Test
+ public void testReRender(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ String commandId = getParentId() + "_controls:rerender";
+ clickCommandAndWait(commandId);
+
+ String timeId = getParentId() + "_data:time";
+ String text = getTextById(timeId);
+
+ clickControl(4);
+
+ String scr = runScript("window.dataScrollerComplete");
+ if (!scr.equals("true")) {
+ Assert.fail("Oncomplete attribute does not work");
+ }
+
+ AssertTextNotEquals(timeId, text, "ReRender attribute does not work");
+ }
+
+ @Test
+ public void testRendered(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ String commandId = getParentId() + "_controls:rendered";
+ clickCommandAndWait(commandId);
+
+ AssertNotPresent(dataScrollerId, "Rendered attribute does not work");
+ AssertNotPresent(dataScrollerTableId, "Rendered attribute does not work");
+ }
+
+
+ @Test
+ public void testDataScrollerRendering(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ testRendering();
+ testHTMLEvent(dataScrollerId);
+ }
+
+ @Test
+ public void testDataScrollerPagination(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ testPageCount(16);
+
+ clickControl(5);
+ testData(1, "Page 3");
+
+ assertClassNames(getPageLinkRefScript(5), activePageClasses, "'3' link
should current", false);
+ assertClassNames(getPageLinkRefScript(3), inactivePageClasses, "'1' link
should be inactive", false);
+ assertClassNames(getPageLinkRefScript(0), activeForwardClasses, "'��'
control should be accessible", false);
+ assertClassNames(getPageLinkRefScript(1), activeForwardClasses, "'�'
control should be accessible", false);
+
+ clickControl(10);
+ testData(1, "Page 8");
+ assertClassNames(getPageLinkRefScript(10), activePageClasses, "'8' link
should current", false);
+
+ clickControl(15);
+ testData(1, "Page 10");
+ assertClassNames(getPageLinkRefScript(15), inactiveForwardClasses, "'��'
control should be inactive", false);
+ assertClassNames(getPageLinkRefScript(14), inactiveForwardClasses, "'�'
control should be inactive", false);
+
+ clickControl(1);
+ testData(1, "Page 9");
+ assertClassNames(getPageLinkRefScript(0), activeForwardClasses, "'��'
control should be active", false);
+ assertClassNames(getPageLinkRefScript(1), activeForwardClasses, "'�'
control should be active", false);
+ assertClassNames(getPageLinkRefScript(11), activePageClasses, "'9' link
should be current", false);
+
+ clickControl(0);
+ testData(1, "Page 1");
+ assertClassNames(getPageLinkRefScript(3), activePageClasses, "'1' link
should be current", false);
+ assertClassNames(getPageLinkRefScript(4), inactivePageClasses, "'2' link
should be inactive", false);
+
+ clickControl(14);
+ testData(1, "Page 2");
+ assertClassNames(getPageLinkRefScript(3), inactivePageClasses, "'1' link
should be inactive", false);
+ assertClassNames(getPageLinkRefScript(4), activePageClasses, "'2' link
should be current", false);
+
+
+ }
+
+ @Test
+ public void testMaxPagesAttr(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ testPageCount(16);
+
+ String buttonId = getParentId() + "_controls:maxP";
+ clickCommandAndWait(buttonId);
+
+ testPageCount(11);
+
+ String text = selenium.getTable("id=" + dataScrollerTableId +
".0.5");
+ Assert.assertEquals(text, "3", "'3' link should be in the
middle");
+
+ clickControl(7);
+ testPageCount(11);
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.5");
+ Assert.assertEquals(text, "5", "'5' link should be in the
middle");
+ testData(1, "Page 5");
+
+
+ clickControl(10);
+ testPageCount(11);
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.7");
+ Assert.assertEquals(text, "10");
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.3");
+ Assert.assertEquals(text, "6");
+ testData(1, "Page 10");
+
+ clickControl(3);
+ testPageCount(11);
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.5");
+ Assert.assertEquals(text, "6");
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.3");
+ Assert.assertEquals(text, "4");
+ testData(1, "Page 6");
+
+ clickControl(1);
+ clickControl(1);
+ testPageCount(11);
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.5");
+ Assert.assertEquals(text, "4");
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.3");
+ Assert.assertEquals(text, "2");
+ testData(1, "Page 4");
+
+
+ }
+
+
+ @Test
+ public void testChangedData(Template template) {
+ renderPage(template, RESET_METHOD_ME);
+ initIDs(getParentId(), template);
+
+ String tableRowsId = getParentId() + "_controls:tableRow";
+ setValueById(tableRowsId, "2");
+
+ String applyId = getParentId() + "_controls:apply";
+ clickCommandAndWait(applyId);
+
+ testPageCount(11);
+ assertRowsCount(2, dataTableId);
+
+ clickControl(7);
+ String text = selenium.getTable("id=" + dataScrollerTableId +
".0.7");
+ Assert.assertEquals(text, "5", "5th page should be displayed");
+ assertRowsCount(2, dataTableId);
+
+ clickControl(3);
+ text = selenium.getTable("id=" + dataScrollerTableId + ".0.3");
+ Assert.assertEquals(text, "1", "1st page should be displayed");
+ assertRowsCount(2, dataTableId);
+
+
+ }
+
+ private void initIDs(String parentId, Template template) {
dataScrollerId = parentId + "_data:scroller";
dataScrollerTableId = parentId + "_data:scroller_table";
//FIXME: currently dataTableId is invalid (dataTableId + ':0'). May be it's
cause of problem with component state storing inside dataTable.
dataTableId = (!template.getName().equals(Template.DATA_TABLE.getName())) ? parentId +
"_data:tbl" : parentId + "_data:tbl:0";
-
- testRendering();
- testHTMLEvent(dataScrollerId);
}
private void testHTMLEvent(String id) {
@@ -63,6 +278,7 @@
assertEvents(event);
+
}
private void testRendering() {
@@ -76,78 +292,50 @@
"rich-dtascroller-table"},
"DataScroller rendering failed: ", true);
- testPageCount();
+ testPageCount(16);
testControls();
testData(1,"Page 1");
}
- private void testPageCount() {
- assertColumnsCount(16, dataScrollerTableId, "DataScroller inner table contains
invalid columns count");
- String text = selenium.getTable("id=" + dataScrollerTableId +
".0.3");
- Assert.assertEquals("1", text, "DataScroller does not contain first page
link or its position is invalid");
- text = selenium.getTable("id=" + dataScrollerTableId + ".0.7");
- Assert.assertEquals("5", text, "DataScroller does not contain 5th page
link or its position is invalid");
- text = selenium.getTable("id=" + dataScrollerTableId + ".0.12");
- Assert.assertEquals("10", text, "DataScroller does not contain 10th page
link or its position is invalid");
+ private void testPageCount(int n) {
+ assertColumnsCount(n, dataScrollerTableId, "DataScroller inner table contains
invalid columns count");
}
private void testControls() {
// Check '��' link
String text = selenium.getTable("id=" + dataScrollerTableId +
".0.0");
Assert.assertEquals("��", text, "DataScroller does not contain
'��' link or its position is invalid");
- assertClassNames(getPageLinkRefScript(0),new String []
- {"dr-dscr-button-dsbld",
- "rich-datascr-button-dsbld",
- "dr-dscr-button",
- "rich-datascr-button"
- },
+ assertClassNames(getPageLinkRefScript(0),inactiveForwardClasses,
"DataScroller rendering failed: ", false);
// Check '�' link
text = selenium.getTable("id=" + dataScrollerTableId + ".0.1");
Assert.assertEquals("�", text, "DataScroller does not contain
'�' link or its position is invalid");
- assertClassNames(getPageLinkRefScript(1),new String []
- {"dr-dscr-button-dsbld",
- "rich-datascr-button-dsbld",
- "dr-dscr-button",
- "rich-datascr-button"
- },
+ assertClassNames(getPageLinkRefScript(1),inactiveForwardClasses,
"DataScroller rendering failed: ", false);
// Check '1' link
text = selenium.getTable("id=" + dataScrollerTableId + ".0.3");
Assert.assertEquals("1", text, "DataScroller does not contain
'1' link or its position is invalid");
- assertClassNames(getPageLinkRefScript(3),new String []
- {"dr-dscr-act",
- "rich-datascr-act"
- },
+ assertClassNames(getPageLinkRefScript(3),activePageClasses,
"DataScroller rendering failed: ", false);
// Check '5' link
text = selenium.getTable("id=" + dataScrollerTableId + ".0.7");
Assert.assertEquals("5", text, "DataScroller does not contain
'5' link or its position is invalid");
- assertClassNames(getPageLinkRefScript(7),new String []
- {"dr-dscr-inact",
- "rich-datascr-inact"
- },
+ assertClassNames(getPageLinkRefScript(7),inactivePageClasses,
"DataScroller rendering failed: ", false);
// Check '�' link
text = selenium.getTable("id=" + dataScrollerTableId + ".0.14");
Assert.assertEquals("�", text, "DataScroller does not contain
'�' link or its position is invalid");
- assertClassNames(getPageLinkRefScript(14),new String []
- {"dr-dscr-button",
- "rich-datascr-button"
- },
+ assertClassNames(getPageLinkRefScript(14),activeForwardClasses,
"DataScroller rendering failed: ", false);
// Check '��' link
text = selenium.getTable("id=" + dataScrollerTableId + ".0.15");
Assert.assertEquals("��", text, "DataScroller does not contain
'��' link or its position is invalid");
- assertClassNames(getPageLinkRefScript(15),new String []
- {"dr-dscr-button",
- "rich-datascr-button"
- },
+ assertClassNames(getPageLinkRefScript(15),activeForwardClasses,
"DataScroller rendering failed: ", false);
}
@@ -170,6 +358,14 @@
b.append("]");
return b.toString();
}
+
+ private void clickControl(int n) {
+ StringBuffer b = new StringBuffer();
+ b.append(getPageLinkRefScript(n));
+ b.append(".onclick();");
+ selenium.getEval(b.toString());
+ waitForAjaxCompletion();
+ }
/* (non-Javadoc)
* @see org.richfaces.SeleniumTestBase#getTestUrl()