Author: jpapouse
Date: 2011-11-23 05:30:53 -0500 (Wed, 23 Nov 2011)
New Revision: 22977
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichDataScrollerBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java
Log:
RFPL-1738: tests for attributes (rich:dataScroller)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichDataScrollerBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichDataScrollerBean.java 2011-11-22
23:37:09 UTC (rev 22976)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/rich/RichDataScrollerBean.java 2011-11-23
10:30:53 UTC (rev 22977)
@@ -45,6 +45,7 @@
private static final long serialVersionUID = 122475400649809L;
private static Logger logger;
private Attributes attributes;
+ private Attributes tableAttributes;
private boolean state = true;
/**
@@ -56,7 +57,7 @@
logger.debug("initializing bean " + getClass().getName());
attributes =
Attributes.getComponentAttributesFromFacesConfig(UIDataScroller.class, getClass());
-
+
attributes.setAttribute("boundaryControls", "show");
attributes.setAttribute("fastControls", "show");
attributes.setAttribute("stepControls", "show");
@@ -69,6 +70,9 @@
attributes.setAttribute("renderIfSinglePage", true);
attributes.setAttribute("for", "richDataTable");
+ tableAttributes = Attributes.getEmptyAttributes(getClass());
+ tableAttributes.setAttribute("rows", 9);
+
}
public Attributes getAttributes() {
@@ -79,6 +83,14 @@
this.attributes = attributes;
}
+ public Attributes getTableAttributes() {
+ return tableAttributes;
+ }
+
+ public void setTableAttributes(Attributes tableAttributes) {
+ this.tableAttributes = tableAttributes;
+ }
+
/**
* Getter for state.
* @return true if non-empty data model should be used in table
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml 2011-11-22
23:37:09 UTC (rev 22976)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml 2011-11-23
10:30:53 UTC (rev 22977)
@@ -56,6 +56,7 @@
fastControls="#{richDataScrollerBean.attributes['fastControls'].value}"
fastStep="#{richDataScrollerBean.attributes['fastStep'].value}"
lastPageMode="#{richDataScrollerBean.attributes['lastPageMode'].value}"
+
limitRender="#{richDataScrollerBean.attributes['limitRender'].value}"
maxPages="#{richDataScrollerBean.attributes['maxPages'].value}"
onbegin="#{richDataScrollerBean.attributes['onbegin'].value}"
onbeforedomupdate="#{richDataScrollerBean.attributes['onbeforedomupdate'].value}"
@@ -64,14 +65,18 @@
render="#{richDataScrollerBean.attributes['render'].value}
#{nestedComponentId}"
renderIfSinglePage="#{richDataScrollerBean.attributes['renderIfSinglePage'].value}"
rendered="#{richDataScrollerBean.attributes['rendered'].value}"
+
status="#{richDataScrollerBean.attributes['status'].value}"
stepControls="#{richDataScrollerBean.attributes['stepControls'].value}"
+
style="#{richDataScrollerBean.attributes['style'].value}"
+
styleClass="#{richDataScrollerBean.attributes['styleClass'].value}"
+
title="#{richDataScrollerBean.attributes['title'].value}"
/>
</ui:define>
<ui:define name="component">
<rich:dataTable id="richDataTable"
- rows="9"
+
rows="#{richDataScrollerBean.tableAttributes['rows'].value}"
value="#{richDataScrollerBean.state ? model.capitals :
null}"
var="record"
@@ -106,10 +111,13 @@
<rich:dataScroller id="scroller2"
boundaryControls="#{richDataScrollerBean.attributes['boundaryControls'].value}"
+
data="#{richDataScrollerBean.attributes['data'].value}"
+
execute="#{richDataScrollerBean.attributes['execute'].value}"
fastControls="#{richDataScrollerBean.attributes['fastControls'].value}"
fastStep="#{richDataScrollerBean.attributes['fastStep'].value}"
first="#{richDataScrollerBean.attributes['first'].value}"
lastPageMode="#{richDataScrollerBean.attributes['lastPageMode'].value}"
+
limitRender="#{richDataScrollerBean.attributes['limitRender'].value}"
maxPages="#{richDataScrollerBean.attributes['maxPages'].value}"
onbegin="#{richDataScrollerBean.attributes['onbegin'].value}"
onbeforedomupdate="#{richDataScrollerBean.attributes['onbeforedomupdate'].value}"
@@ -118,7 +126,11 @@
render="#{richDataScrollerBean.attributes['render'].value} scroller1"
renderIfSinglePage="#{richDataScrollerBean.attributes['renderIfSinglePage'].value}"
rendered="#{richDataScrollerBean.attributes['rendered'].value}"
+
status="#{richDataScrollerBean.attributes['status'].value}"
stepControls="#{richDataScrollerBean.attributes['stepControls'].value}"
+
style="#{richDataScrollerBean.attributes['style'].value}"
+
styleClass="#{richDataScrollerBean.attributes['styleClass'].value}"
+
title="#{richDataScrollerBean.attributes['title'].value}"
/>
</f:facet>
@@ -217,8 +229,10 @@
</fieldset>
<br/><br/>
-
+ <h2>Attributes</h2>
<metamer:attributes value="#{richDataScrollerBean.attributes}"
id="attributes" />
+ <h2>Table Attributes</h2>
+ <metamer:attributes
value="#{richDataScrollerBean.tableAttributes}" id="tableAttributes"
/>
</ui:define>
</ui:composition>
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2011-11-22
23:37:09 UTC (rev 22976)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2011-11-23
10:30:53 UTC (rev 22977)
@@ -27,6 +27,7 @@
import org.jboss.test.selenium.framework.AjaxSelenium;
import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.Attribute;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.locator.reference.ReferencedLocator;
import org.jboss.test.selenium.utils.text.SimplifiedFormat;
@@ -216,7 +217,7 @@
}
return integer(selenium.getText(currentPage));
}
-
+
public boolean isFastForwardButtonPresent() {
return selenium.isElementPresent(fastForwardButton);
}
@@ -250,7 +251,7 @@
}
public boolean isPresent() {
- return selenium.isElementPresent(root.getLocator());
+ return selenium.isElementPresent(root.getLocator()) &&
selenium.isDisplayed(root.getLocator());
}
public static int integer(String string) {
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java 2011-11-22
23:37:09 UTC (rev 22976)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java 2011-11-23
10:30:53 UTC (rev 22977)
@@ -35,7 +35,7 @@
fastControls,
fastStep,
lastPageMode,
- limitRenderer,
+ limitRender,
maxPages,
onbeforedomupdate,
onbegin,
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java 2011-11-22
23:37:09 UTC (rev 22976)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java 2011-11-23
10:30:53 UTC (rev 22977)
@@ -21,28 +21,46 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richDataScroller;
+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 static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
import java.net.URL;
import java.util.Arrays;
import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.waiting.selenium.SeleniumCondition;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.abstractions.DataTableAttributes;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
import org.richfaces.tests.metamer.ftest.attributes.Attributes;
import org.richfaces.tests.metamer.ftest.model.DataScroller;
import org.testng.annotations.Test;
-import static org.testng.Assert.*;
/**
* Test the functionality of switching pages using DataScroller bound to DataTable.
*
* @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
*/
+@Use(field = "scroller", value = {"scrollerOutsideTable",
"scrollerInsideTable"})
public class TestDataScrollerAttributes extends AbstractMetamerTest {
- private final Attributes<DataScrollerAttributes> attributes = new
Attributes<DataScrollerAttributes>();
- private final DataScroller scroller = PaginationTester.DATA_SCROLLER_OUTSIDE_TABLE;
-
+ private final Attributes<DataScrollerAttributes> attributes = new
Attributes<DataScrollerAttributes>(pjq("table[id$='attributes']"));
+ private final Attributes<DataTableAttributes> tableAttributes = new
Attributes<DataTableAttributes>(pjq("table[id$='tableAttributes']"));
+
+ @Inject
+ private DataScroller scroller;
+
+ private DataScroller scrollerOutsideTable =
PaginationTester.DATA_SCROLLER_OUTSIDE_TABLE;
+ private DataScroller scrollerInsideTable =
PaginationTester.DATA_SCROLLER_IN_TABLE_FOOTER;
+
+
@Override
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/richDataScroller/simple.xhtml");
@@ -60,6 +78,20 @@
}
@Test
+ public void testData() {
+ // attributes
+ getAttributes().set(DataScrollerAttributes.data, "RichFaces");
+ getAttributes().set(DataScrollerAttributes.oncomplete, "data =
event.data");
+ // action
+ retrieveRequestTime.initializeValue();
+ getScroller().clickFastForward();
+ waitGui.waitForChange(retrieveRequestTime);
+ // check
+ String data = selenium.getEval(new JavaScript("window.data"));
+ assertEquals(data, "RichFaces", "Data sent with ajax
request");
+ }
+
+ @Test
public void testEvents() throws InterruptedException {
// set event attributes
getAttributes().set(DataScrollerAttributes.onbeforedomupdate, "metamerEvents
+= \"beforedomupdate \"");
@@ -80,6 +112,24 @@
}
@Test
+ public void testExecute() {
+ // attributes
+ getAttributes().set(DataScrollerAttributes.execute, "executeChecker");
+ // action
+ retrieveRequestTime.initializeValue();
+ getScroller().clickFastForward();
+ waitGui.waitForChange(retrieveRequestTime);
+ // check
+ JQueryLocator logItems = jq("ul.phases-list li:eq({0})");
+ for (int i = 0; i < 6; i++) {
+ if ("*
executeChecker".equals(selenium.getText(logItems.format(i)))) {
+ return;
+ }
+ }
+ fail("Attribute execute does not work");
+ }
+
+ @Test
public void testFastControls() {
// init - show
assertTrue(getScroller().isFastForwardButtonPresent(), "The fast forward
button should be present.");
@@ -104,6 +154,43 @@
}
@Test
+ public void testLastPageMode() {
+ retrieveRequestTime.initializeValue();
+ getScroller().clickLastPageButton();
+ waitGui.waitForChange(retrieveRequestTime);
+ // init - short
+ assertEquals(getNumberOfRows(), 5, "Attribute lastPageMode doesn't work.
The number of rows doesn't match, when the value is set to <short>");
+ // full
+ getAttributes().set(DataScrollerAttributes.lastPageMode, "full");
+ assertEquals(getNumberOfRows(), 9, "Attribute lastPageMode doesn't work.
The number of rows doesn't match, when the value is set to <full>");
+ }
+
+ @Test
+ public void testLimitRender() {
+ // false
+ getAttributes().set(DataScrollerAttributes.limitRender, false);
+ retrieveRequestTime.initializeValue();
+ getScroller().clickFastForward();
+ waitGui
+ .failWith("The panel hasn't been rerendered despite of the fact the
attribute 'limitRender' is set to <false>.")
+ .waitForChange(retrieveRequestTime);
+ // true
+ getAttributes().set(DataScrollerAttributes.limitRender, false);
+ String timeBefore = retrieveRequestTime.getValue();
+ getScroller().clickFastRewind();
+ waitModel
+ .until(new SeleniumCondition() {
+ @Override
+ public boolean isTrue() {
+ return getScroller().getCurrentPage() == 1;
+ }
+ });
+ String timeAfter = retrieveRequestTime.getValue();
+ assertEquals(timeAfter, timeBefore, "The panel hasn been rerendered despite
of the fact the attribute 'limitRender' is set to <true>.");
+
+ }
+
+ @Test
public void testMaxPages() {
// init - 10
assertEquals(getScroller().getCountOfVisiblePages(), 6 /* it means - all pages
*/, "The number of visible pages doesn't match.");
@@ -125,6 +212,31 @@
}
@Test
+ public void testRenderIfSinglePage() {
+ // prepare
+ getTableAttributes().set(DataTableAttributes.rows, 200);
+ // init - true
+ assertTrue(getScroller().isPresent(), "The attribute
'renderIfSinglePage' doesn't work.");
+ // false
+ getAttributes().set(DataScrollerAttributes.renderIfSinglePage, false);
+ assertFalse(getScroller().isPresent(), "The attribute
'renderIfSinglePage' doesn't work.");
+ }
+
+ @Test
+ public void testStatus() {
+ // prepare
+ getAttributes().set(DataScrollerAttributes.status, "statusChecker");
+ String statusBefore = selenium.getText(statusChecker);
+ // action
+ retrieveRequestTime.initializeValue();
+ getScroller().clickFastForward();
+ waitGui.waitForChange(retrieveRequestTime);
+ // check
+ String statusAfter = selenium.getText(statusChecker);
+ assertNotEquals(statusAfter, statusBefore, "The status attribute doesn't
work.");
+ }
+
+ @Test
public void testStepControls() {
// init - show
assertTrue(getScroller().isNextButtonPresent(), "The next button should be
present.");
@@ -135,12 +247,35 @@
assertFalse(getScroller().isPreviousButtonPresent(), "The previous button
shouldn't be present.");
}
+ @Test
+ public void testStyle() {
+ super.testStyle(getScroller());
+ }
+
+ @Test
+ public void testStyleClass() {
+ super.testStyleClass(getScroller());
+ }
+
+ @Test
+ public void testTitle() {
+ super.testTitle(getScroller());
+ }
+
private Attributes<DataScrollerAttributes> getAttributes() {
return attributes;
}
+ private int getNumberOfRows() {
+ return selenium.getCount(pjq("*.rf-dt tbody tr.rf-dt-r"));
+ }
+
private DataScroller getScroller() {
return scroller;
}
+ private Attributes<DataTableAttributes> getTableAttributes() {
+ return tableAttributes;
+ }
+
}