Author: lfryc(a)redhat.com
Date: 2011-01-08 18:28:47 -0500 (Sat, 08 Jan 2011)
New Revision: 20922
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/scroller.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/AbstractListTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestScroller.java
Removed:
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/dataScroller.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/list.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/ListModel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestSimple.java
Log:
rich:list - added data scroller tests (RFPL-671)
Deleted:
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/dataScroller.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/dataScroller.xhtml 2011-01-08
22:48:22 UTC (rev 20921)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/dataScroller.xhtml 2011-01-08
23:28:47 UTC (rev 20922)
@@ -1,105 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
-
xmlns:rich="http://richfaces.org/rich">
-
- <!--
-JBoss, Home of Professional Open Source
-Copyright 2010, Red Hat, Inc. and individual contributors
-by the @authors tag. See the copyright.txt in the distribution for a
-full listing of individual contributors.
-
-This is free software; you can redistribute it and/or modify it
-under the terms of the GNU Lesser General Public License as
-published by the Free Software Foundation; either version 2.1 of
-the License, or (at your option) any later version.
-
-This software is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this software; if not, write to the Free
-Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- -->
-
- <ui:composition template="/templates/template.xhtml">
-
- <ui:define name="head">
- <f:metadata>
- <f:viewParam name="templates"
value="#{templateBean.templates}">
- <f:converter converterId="templatesListConverter" />
- </f:viewParam>
- </f:metadata>
- <h:outputStylesheet library="css" name="richList.css"
/>
-
- </ui:define>
-
- <ui:define name="outOfTemplateBefore">
- </ui:define>
-
- <ui:define name="component">
- <rich:list id="richList"
- dir="#{richListBean.attributes['dir'].value}"
-
first="#{richListBean.attributes['first'].value}"
-
iterationState="#{richListBean.attributes['iterationState'].value}"
- iterationStatusVar="iterationStatus"
-
keepSaved="#{richListBean.attributes['keepSaved'].value}"
- lang="#{richListBean.attributes['lang'].value}"
-
onclick="#{richListBean.attributes['onclick'].value}"
-
ondblclick="#{richListBean.attributes['ondblclick'].value}"
-
onkeydown="#{richListBean.attributes['onkeydown'].value}"
-
onkeypress="#{richListBean.attributes['onkeypress'].value}"
-
onkeyup="#{richListBean.attributes['onkeyup'].value}"
-
onmousedown="#{richListBean.attributes['onmousedown'].value}"
-
onmousemove="#{richListBean.attributes['onmousemove'].value}"
-
onmouseout="#{richListBean.attributes['onmouseout'].value}"
-
onmouseover="#{richListBean.attributes['onmouseover'].value}"
-
onmouseup="#{richListBean.attributes['onmouseup'].value}"
-
onrowclick="#{richListBean.attributes['onrowclick'].value}"
-
onrowdblclick="#{richListBean.attributes['onrowdblclick'].value}"
-
onrowkeydown="#{richListBean.attributes['onrowkeydown'].value}"
-
onrowkeypress="#{richListBean.attributes['onrowkeypress'].value}"
-
onrowkeyup="#{richListBean.attributes['onrowkeyup'].value}"
-
onrowmousedown="#{richListBean.attributes['onrowmousedown'].value}"
-
onrowmousemove="#{richListBean.attributes['onrowmousemove'].value}"
-
onrowmouseout="#{richListBean.attributes['onrowmouseout'].value}"
-
onrowmouseover="#{richListBean.attributes['onrowmouseover'].value}"
-
onrowmouseup="#{richListBean.attributes['onrowmouseup'].value}"
-
relativeRowIndex="#{richListBean.attributes['relativeRowIndex'].value}"
-
rendered="#{richListBean.attributes['rendered'].value}"
-
rowAvailable="#{richListBean.attributes['rowAvailable'].value}"
-
rowClass="#{richListBean.attributes['rowClass'].value}"
-
rowClasses="#{richListBean.attributes['rowClasses'].value}"
-
rowCount="#{richListBean.attributes['rowCount'].value}"
-
rowData="#{richListBean.attributes['rowData'].value}"
-
rowIndex="#{richListBean.attributes['rowIndex'].value}"
-
rowKey="#{richListBean.attributes['rowKey'].value}"
-
rowKeyConverter="#{richListBean.attributes['rowKeyConverter'].value}"
- rows="#{richListBean.attributes['rows'].value}"
-
style="#{richListBean.attributes['style'].value}"
-
styleClass="#{richListBean.attributes['styleClass'].value}"
- value="#{model.employees}"
- var="item"
- term="#{richListBean.attributes['term'].value}"
-
title="#{richListBean.attributes['title'].value}"
-
type="#{richListBean.attributes['type'].value}">
- <f:facet name="term">
- <h:outputText id="term" value="#{item.title}"
style="font-weight: bold"/>
- </f:facet>
-
- #{item.name}
- </rich:list>
-
- <rich:dataScroller id="dataScroller" for="richList"
/>
- </ui:define>
-
- <ui:define name="outOfTemplateAfter">
- <metamer:attributes value="#{richListBean.attributes}"
id="attributes" />
- </ui:define>
-
- </ui:composition>
-</html>
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/list.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/list.xhtml 2011-01-08
22:48:22 UTC (rev 20921)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/list.xhtml 2011-01-08
23:28:47 UTC (rev 20922)
@@ -35,7 +35,7 @@
Simple page that contains <b>rich:list</b> (with model
containing capitals) and "term" facet which influences list in definitions mode
</metamer:testPageLink>
- <metamer:testPageLink id="dataScroller"
outcome="dataScroller" value="Data Scroller">
+ <metamer:testPageLink id="scroller" outcome="scroller"
value="Data Scroller">
Simple page that contains <b>rich:list</b> (with model
containing capitals) with bound dataScroller
</metamer:testPageLink>
Copied:
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/scroller.xhtml
(from rev 20921,
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/dataScroller.xhtml)
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/scroller.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richList/scroller.xhtml 2011-01-08
23:28:47 UTC (rev 20922)
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
+
xmlns:rich="http://richfaces.org/rich">
+
+ <!--
+JBoss, Home of Professional Open Source
+Copyright 2010, Red Hat, Inc. and individual contributors
+by the @authors tag. See the copyright.txt in the distribution for a
+full listing of individual contributors.
+
+This is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of
+the License, or (at your option) any later version.
+
+This software is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this software; if not, write to the Free
+Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ -->
+
+ <ui:composition template="/templates/template.xhtml">
+ <ui:param name="componentId" value="richList" />
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ </f:metadata>
+ <h:outputStylesheet library="css" name="richList.css"
/>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ <rich:dataScroller id="scroller1" for="richList"
maxPages="7" render="#{nestedComponentId}" />
+ </ui:define>
+
+ <ui:define name="component">
+ <rich:list id="richList"
+ dir="#{richListBean.attributes['dir'].value}"
+
first="#{richListBean.attributes['first'].value}"
+
iterationState="#{richListBean.attributes['iterationState'].value}"
+ iterationStatusVar="iterationStatus"
+
keepSaved="#{richListBean.attributes['keepSaved'].value}"
+ lang="#{richListBean.attributes['lang'].value}"
+
onclick="#{richListBean.attributes['onclick'].value}"
+
ondblclick="#{richListBean.attributes['ondblclick'].value}"
+
onkeydown="#{richListBean.attributes['onkeydown'].value}"
+
onkeypress="#{richListBean.attributes['onkeypress'].value}"
+
onkeyup="#{richListBean.attributes['onkeyup'].value}"
+
onmousedown="#{richListBean.attributes['onmousedown'].value}"
+
onmousemove="#{richListBean.attributes['onmousemove'].value}"
+
onmouseout="#{richListBean.attributes['onmouseout'].value}"
+
onmouseover="#{richListBean.attributes['onmouseover'].value}"
+
onmouseup="#{richListBean.attributes['onmouseup'].value}"
+
onrowclick="#{richListBean.attributes['onrowclick'].value}"
+
onrowdblclick="#{richListBean.attributes['onrowdblclick'].value}"
+
onrowkeydown="#{richListBean.attributes['onrowkeydown'].value}"
+
onrowkeypress="#{richListBean.attributes['onrowkeypress'].value}"
+
onrowkeyup="#{richListBean.attributes['onrowkeyup'].value}"
+
onrowmousedown="#{richListBean.attributes['onrowmousedown'].value}"
+
onrowmousemove="#{richListBean.attributes['onrowmousemove'].value}"
+
onrowmouseout="#{richListBean.attributes['onrowmouseout'].value}"
+
onrowmouseover="#{richListBean.attributes['onrowmouseover'].value}"
+
onrowmouseup="#{richListBean.attributes['onrowmouseup'].value}"
+
relativeRowIndex="#{richListBean.attributes['relativeRowIndex'].value}"
+
rendered="#{richListBean.attributes['rendered'].value}"
+
rowAvailable="#{richListBean.attributes['rowAvailable'].value}"
+
rowClass="#{richListBean.attributes['rowClass'].value}"
+
rowClasses="#{richListBean.attributes['rowClasses'].value}"
+
rowCount="#{richListBean.attributes['rowCount'].value}"
+
rowData="#{richListBean.attributes['rowData'].value}"
+
rowIndex="#{richListBean.attributes['rowIndex'].value}"
+
rowKey="#{richListBean.attributes['rowKey'].value}"
+
rowKeyConverter="#{richListBean.attributes['rowKeyConverter'].value}"
+ rows="#{richListBean.attributes['rows'].value}"
+
style="#{richListBean.attributes['style'].value}"
+
styleClass="#{richListBean.attributes['styleClass'].value}"
+ value="#{model.employees}"
+ var="item"
+ term="#{richListBean.attributes['term'].value}"
+
title="#{richListBean.attributes['title'].value}"
+
type="#{richListBean.attributes['type'].value}">
+ <f:facet name="term">
+ <h:outputText id="term" value="#{item.title}"
style="font-weight: bold"/>
+ </f:facet>
+
+ #{item.name}
+ </rich:list>
+
+ <rich:dataScroller id="scroller2" for="richList"
maxPages="7" render="richList scroller1" />
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <metamer:attributes value="#{richListBean.attributes}"
id="attributes" />
+ </ui:define>
+
+ </ui:composition>
+</html>
\ No newline at end of file
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/AbstractListTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/AbstractListTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/AbstractListTest.java 2011-01-08
23:28:47 UTC (rev 20922)
@@ -0,0 +1,138 @@
+package org.richfaces.tests.metamer.ftest.richList;
+
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+import static org.jboss.test.selenium.dom.Event.CLICK;
+import static org.jboss.test.selenium.dom.Event.DBLCLICK;
+import static org.jboss.test.selenium.dom.Event.KEYDOWN;
+import static org.jboss.test.selenium.dom.Event.KEYPRESS;
+import static org.jboss.test.selenium.dom.Event.KEYUP;
+import static org.jboss.test.selenium.dom.Event.MOUSEDOWN;
+import static org.jboss.test.selenium.dom.Event.MOUSEMOVE;
+import static org.jboss.test.selenium.dom.Event.MOUSEOUT;
+import static org.jboss.test.selenium.dom.Event.MOUSEOVER;
+import static org.jboss.test.selenium.dom.Event.MOUSEUP;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.richfaces.tests.metamer.ftest.richList.ListAttributes.Type.ORDERED;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URL;
+import java.util.List;
+
+import org.jboss.test.selenium.dom.Event;
+import org.richfaces.tests.metamer.bean.Model;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.richList.ListAttributes.Type;
+import org.richfaces.tests.metamer.model.Employee;
+import org.testng.annotations.BeforeMethod;
+
+public abstract class AbstractListTest extends AbstractMetamerTest {
+ protected static List<Employee> EMPLOYESS = Model.unmarshallEmployees();
+ protected static final int ELEMENTS_TOTAL = EMPLOYESS.size();
+ protected static final Event[] events = { CLICK, DBLCLICK, KEYDOWN, KEYPRESS, KEYUP,
MOUSEDOWN, MOUSEMOVE,
+ MOUSEOUT, MOUSEOVER, MOUSEUP };
+ protected static final Integer[] ints = { -1, 0, 1, ELEMENTS_TOTAL / 2,
ELEMENTS_TOTAL - 1, ELEMENTS_TOTAL,
+ ELEMENTS_TOTAL + 1 };
+
+ ListModel list;
+ ListAttributes attributes = new ListAttributes();
+
+ @Inject
+ @Use(empty = true)
+ Integer first;
+
+ @Inject
+ @Use(empty = true)
+ Integer rows;
+
+ @Inject
+ @Use(empty = true)
+ Event event;
+
+ Type type = ORDERED;
+
+ int expectedBegin;
+ int displayedRows;
+ int expectedEnd;
+ List<Employee> expectedEmployees;
+
+ @BeforeMethod(alwaysRun = true)
+ public void prepareAttributes() {
+ list = new ListModel(jq("*[id$=richList]"));
+ attributes.setType(type);
+ list.setType(type);
+
+ if (rows == null) {
+ rows = 20;
+ }
+
+ if (first != null) {
+ attributes.setFirst(first);
+ }
+ if (rows != null) {
+ attributes.setRows(rows);
+ }
+ }
+
+ protected void verifyList() {
+ countExpectedValues();
+ verifyCounts();
+ verifyRows();
+ }
+
+ private void verifyCounts() {
+ assertEquals(list.getTotalRowCount(), displayedRows);
+ }
+
+ private void verifyRows() {
+ int rowCount = list.getTotalRowCount();
+ for (int position = 1; position <= rowCount; position++) {
+ Employee employee = expectedEmployees.get(position - 1);
+ assertEquals(list.getRowText(position), employee.getName());
+ }
+ }
+
+ private void countExpectedValues() {
+
+ // expected begin
+
+ if (first == null || first < 0) {
+ expectedBegin = 0;
+ } else {
+ expectedBegin = first;
+ }
+
+ expectedBegin = minMax(0, expectedBegin, ELEMENTS_TOTAL);
+
+ // expected displayed rows
+
+ if (rows == null || rows < 1 || rows > ELEMENTS_TOTAL) {
+ displayedRows = ELEMENTS_TOTAL;
+ } else {
+ displayedRows = rows;
+ }
+
+ if (first != null && first < 0) {
+ displayedRows = 0;
+ }
+
+ displayedRows = min(displayedRows, ELEMENTS_TOTAL - expectedBegin);
+
+ // expected end
+
+ if (rows == null || rows < 1) {
+ expectedEnd = ELEMENTS_TOTAL - 1;
+ } else {
+ expectedEnd = rows - 1;
+ }
+
+ expectedEmployees = EMPLOYESS.subList(expectedBegin, expectedBegin +
displayedRows);
+ }
+
+ private int minMax(int min, int value, int max) {
+ return max(0, min(max, value));
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/ListModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/ListModel.java 2011-01-08
22:48:22 UTC (rev 20921)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/ListModel.java 2011-01-08
23:28:47 UTC (rev 20922)
@@ -23,13 +23,13 @@
import static org.jboss.test.selenium.locator.LocatorFactory.jq;
import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
-import static org.richfaces.tests.metamer.ftest.richList.ListAttributes.Type;
+
import org.jboss.test.selenium.framework.AjaxSelenium;
import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
import org.jboss.test.selenium.locator.JQueryLocator;
-import org.jboss.test.selenium.locator.reference.LocatorReference;
import org.jboss.test.selenium.locator.reference.ReferencedLocator;
import org.richfaces.tests.metamer.ftest.model.AbstractModel;
+import org.richfaces.tests.metamer.ftest.richList.ListAttributes.Type;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestScroller.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestScroller.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestScroller.java 2011-01-08
23:28:47 UTC (rev 20922)
@@ -0,0 +1,54 @@
+package org.richfaces.tests.metamer.ftest.richList;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.model.DataScroller;
+import org.richfaces.tests.metamer.ftest.richDataScroller.PaginationTester;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class TestScroller extends AbstractListTest {
+
+ @Inject
+ DataScroller dataScroller;
+ DataScroller dataScroller1 = PaginationTester.DATA_SCROLLER_OUTSIDE_TABLE;
+ DataScroller dataScroller2 = PaginationTester.DATA_SCROLLER_IN_TABLE_FOOTER;
+
+ PaginationTester paginationTester = new PaginationTester() {
+
+ @Override
+ protected void verifyBeforeScrolling() {
+ }
+
+ @Override
+ protected void verifyAfterScrolling() {
+ int currentPage = dataScroller.getCurrentPage();
+ first = rows * (currentPage - 1);
+ verifyList();
+ }
+ };
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richList/scroller.xhtml");
+ }
+
+ @BeforeMethod
+ public void prepareComponent() {
+ paginationTester.setDataScroller(dataScroller);
+
+ int lastPage = dataScroller.obtainLastPage();
+ dataScroller.setLastPage(lastPage);
+ paginationTester.initializeTestedPages(lastPage);
+ }
+
+ @Test
+ @Use(field = "dataScroller", value = "dataScroller*")
+ public void testScrollerWithRowsAttribute() {
+ paginationTester.testNumberedPages();
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestSimple.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestSimple.java 2011-01-08
22:48:22 UTC (rev 20921)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richList/TestSimple.java 2011-01-08
23:28:47 UTC (rev 20922)
@@ -21,94 +21,25 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richList;
-import static java.lang.Math.max;
-import static java.lang.Math.min;
-import static org.jboss.test.selenium.dom.Event.CLICK;
-import static org.jboss.test.selenium.dom.Event.DBLCLICK;
-import static org.jboss.test.selenium.dom.Event.KEYDOWN;
-import static org.jboss.test.selenium.dom.Event.KEYPRESS;
-import static org.jboss.test.selenium.dom.Event.KEYUP;
-import static org.jboss.test.selenium.dom.Event.MOUSEDOWN;
-import static org.jboss.test.selenium.dom.Event.MOUSEMOVE;
-import static org.jboss.test.selenium.dom.Event.MOUSEOUT;
-import static org.jboss.test.selenium.dom.Event.MOUSEOVER;
-import static org.jboss.test.selenium.dom.Event.MOUSEUP;
-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.richfaces.tests.metamer.ftest.richList.ListAttributes.Type;
-import static org.richfaces.tests.metamer.ftest.richList.ListAttributes.Type.*;
import java.net.URL;
-import java.util.List;
-import org.jboss.test.selenium.dom.Event;
-import org.richfaces.tests.metamer.bean.Model;
-import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
-import org.richfaces.tests.metamer.ftest.annotations.Inject;
import org.richfaces.tests.metamer.ftest.annotations.Use;
-import org.richfaces.tests.metamer.model.Employee;
-import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
-public class TestSimple extends AbstractMetamerTest {
-
- protected static List<Employee> EMPLOYESS = Model.unmarshallEmployees();
- protected static final int ELEMENTS_TOTAL = EMPLOYESS.size();
- protected static final Event[] events = { CLICK, DBLCLICK, KEYDOWN, KEYPRESS, KEYUP,
MOUSEDOWN, MOUSEMOVE,
- MOUSEOUT, MOUSEOVER, MOUSEUP };
- protected static final Integer[] ints = { -1, 0, 1, ELEMENTS_TOTAL / 2,
ELEMENTS_TOTAL - 1, ELEMENTS_TOTAL,
- ELEMENTS_TOTAL + 1 };
-
- ListModel list;
- ListAttributes attributes = new ListAttributes();
-
- @Inject
- @Use(empty = true)
- Integer first;
-
- @Inject
- @Use(empty = true)
- Integer rows;
-
- @Inject
- @Use(empty = true)
- Event event;
-
- Type type = ORDERED;
-
- int expectedBegin;
- int displayedRows;
- int expectedEnd;
- List<Employee> expectedEmployees;
-
+public class TestSimple extends AbstractListTest {
+
@Override
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/richList/simple.xhtml");
}
- @BeforeMethod(alwaysRun = true)
- public void prepareAttributes() {
- list = new ListModel(jq("*[id$=richList]"));
- attributes.setType(type);
- list.setType(type);
-
- if (rows == null) {
- rows = 20;
- }
-
- if (first != null) {
- attributes.setFirst(first);
- }
- if (rows != null) {
- attributes.setRows(rows);
- }
- }
-
@Test
public void testRenderedAttribute() {
attributes.setRendered("false");
@@ -162,71 +93,13 @@
@Test
@Use(field = "first", value = "ints")
public void testFirstAttribute() {
- verifyRepeat();
+ verifyList();
}
@Test
@Use(field = "rows", value = "ints")
public void testRowsAttribute() {
- verifyRepeat();
+ verifyList();
}
- private void verifyRepeat() {
- countExpectedValues();
- verifyCounts();
- verifyRows();
- }
-
- private void verifyCounts() {
- assertEquals(list.getTotalRowCount(), displayedRows);
- }
-
- private void verifyRows() {
- int rowCount = list.getTotalRowCount();
- for (int position = 1; position <= rowCount; position++) {
- Employee employee = expectedEmployees.get(position - 1);
- assertEquals(employee.getName(), list.getRowText(position));
- }
- }
-
- private void countExpectedValues() {
-
- // expected begin
-
- if (first == null || first < 0) {
- expectedBegin = 0;
- } else {
- expectedBegin = first;
- }
-
- expectedBegin = minMax(0, expectedBegin, ELEMENTS_TOTAL);
-
- // expected displayed rows
-
- if (rows == null || rows < 1 || rows > ELEMENTS_TOTAL) {
- displayedRows = ELEMENTS_TOTAL;
- } else {
- displayedRows = rows;
- }
-
- if (first != null && first < 0) {
- displayedRows = 0;
- }
-
- displayedRows = min(displayedRows, ELEMENTS_TOTAL - expectedBegin);
-
- // expected end
-
- if (rows == null || rows < 1) {
- expectedEnd = ELEMENTS_TOTAL - 1;
- } else {
- expectedEnd = rows - 1;
- }
-
- expectedEmployees = EMPLOYESS.subList(expectedBegin, expectedBegin +
displayedRows);
- }
-
- private int minMax(int min, int value, int max) {
- return max(0, min(max, value));
- }
}
\ No newline at end of file