Author: lfryc(a)redhat.com
Date: 2010-07-10 16:55:17 -0400 (Sat, 10 Jul 2010)
New Revision: 17881
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/ScrollerTestCase.java
Log:
initial commit of ScrollerTestCase
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/ScrollerTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/ScrollerTestCase.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/ScrollerTestCase.java 2010-07-10
20:55:17 UTC (rev 17881)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * 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.
+ *******************************************************************************/
+
+package org.richfaces.tests.testapp.richExtendedDataTable;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
+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 java.net.URL;
+
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.testapp.AbstractTestappTestCase;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Test case for page /faces/components/commandButton/simple.xhtml
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class ScrollerTestCase extends AbstractTestappTestCase {
+
+ DataScroller dataScroller1 = new
DataScroller(jq("#form\\:richEDT\\:scroller2"));
+ DataScroller dataScroller2 = new DataScroller(jq("#form\\:scroller1"));
+ DataTable table = new DataTable(jq("#form\\:richEDT"));
+ JQueryLocator attributeRowsInput = jq("#form\\:attributes\\:rowsInput");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richExtendedDataTable/scroller.xhtml");
+ }
+
+ final static int TOTAL_ROW_COUNT = 50;
+
+ @Override
+ @BeforeMethod(alwaysRun = true)
+ public void invalidateSession() {
+ super.invalidateSession();
+ }
+
+ @Test(dataProvider = "templates")
+ public void testDefaultDataScrollerRowCount(String templates) {
+ testRowCount(dataScroller1);
+ }
+
+ @Test(dataProvider = "templates")
+ public void testExternalDataScrollerRowCount(String templates) {
+ testRowCount(dataScroller2);
+ }
+
+ // @Test(dataProvider = "templates")
+ // public void testBothDataScrollerRowCount(String templates) {
+ // testRowCount(dataScroller1);
+ // invalidateSession();
+ // testRowCount(dataScroller2);
+ // }
+
+ public void testRowCount(DataScroller dataScroller) {
+ for (Integer rowsPerPage : new Integer[]{null, 10, 1, TOTAL_ROW_COUNT,
TOTAL_ROW_COUNT + 1, 2 * TOTAL_ROW_COUNT}) {
+ if (rowsPerPage != null) {
+ selenium.type(attributeRowsInput, String.valueOf(rowsPerPage));
+ guardHttp(selenium).fireEvent(attributeRowsInput, Event.BLUR);
+ }
+
+ int rowCountPreset = Integer.valueOf(selenium.getValue(attributeRowsInput));
+ int rowCountActual = table.getCountOfTableRows();
+ assertEquals(table.getCountOfTableRows(), Math.min(TOTAL_ROW_COUNT,
rowCountPreset));
+
+ assertEquals(dataScroller.hasPages(), rowCountActual < TOTAL_ROW_COUNT);
+ if (dataScroller.hasPages()) {
+ dataScroller.clickLastPage();
+
+ int pagesExpected = pageCountActual(rowCountActual);
+ int countOfVisiblePages = dataScroller.getCountOfVisiblePages();
+
+ if (countOfVisiblePages < pagesExpected) {
+ int lastVisiblePage = dataScroller.getLastVisiblePage();
+ assertEquals(lastVisiblePage, pageCountActual(rowCountActual));
+ } else {
+ assertEquals(countOfVisiblePages, pagesExpected);
+ }
+
+ rowCountActual = table.getCountOfTableRows();
+ assertEquals(rowCountActual, rowCountLastPage(rowCountPreset));
+ }
+ }
+ }
+
+ int pageCountActual(int rowCountActual) {
+ return Double.valueOf(Math.ceil((double) TOTAL_ROW_COUNT /
rowCountActual)).intValue();
+ }
+
+ int rowCountLastPage(int rowCountPreset) {
+ int result = TOTAL_ROW_COUNT % rowCountPreset;
+ return (result == 0) ? rowCountPreset : result;
+ }
+
+}