Author: lfryc(a)redhat.com
Date: 2010-07-10 16:55:54 -0400 (Sat, 10 Jul 2010)
New Revision: 17882
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataScroller.java
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataTable.java
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/ScrollerTestCase.java
Log:
ScrollerTestCase for internal and external dataTable's dataScroller
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataScroller.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataScroller.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataScroller.java 2010-07-10
20:55:54 UTC (rev 17882)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * 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 org.jboss.test.selenium.locator.JQueryLocator;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.*;
+import static org.jboss.test.selenium.framework.AjaxSelenium.getCurrentSelenium;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.*;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class DataScroller {
+ JQueryLocator scrollerRoot;
+ JQueryLocator pageNumbers = jq(".rf-ds-dtl");
+ JQueryLocator firstPageButton = jq(".rf-ds-l[id$=ds_f]");
+ JQueryLocator lastPageButton = jq(".rf-ds-r:eq(1)");
+ JQueryLocator lastVisiblePage = jq(".rf-ds-dtl:last");
+ JQueryLocator currentPage = jq(".rf-ds-cur");
+
+ public DataScroller(JQueryLocator scrollerRoot) {
+ this.scrollerRoot = scrollerRoot;
+ }
+
+ public JQueryLocator getRoot() {
+ return scrollerRoot;
+ }
+
+ public void gotoFirstPage() {
+ if (!isFirstPage()) {
+ clickFirstPageButton();
+ }
+ }
+
+ public void gotoLastPage() {
+ if (!isLastPage()) {
+ clickLastPageButton();
+ }
+ }
+
+ public void clickLastPageButton() {
+ JQueryLocator locator = scrollerRoot.getDescendant(lastPageButton);
+ guardXhr(getCurrentSelenium()).click(locator);
+ }
+
+ public void clickFirstPageButton() {
+ JQueryLocator locator = scrollerRoot.getDescendant(firstPageButton);
+ guardXhr(getCurrentSelenium()).click(locator);
+ }
+
+ public int getCountOfVisiblePages() {
+ JQueryLocator locator = scrollerRoot.getDescendant(pageNumbers);
+ return getCurrentSelenium().getCount(locator);
+ }
+
+ public boolean hasPages() {
+ JQueryLocator locator = scrollerRoot.getDescendant(lastVisiblePage);
+ return getCurrentSelenium().isElementPresent(locator);
+ }
+
+ public Integer getLastVisiblePage() {
+ JQueryLocator locator = scrollerRoot.getDescendant(lastVisiblePage);
+ if (!hasPages()) {
+ return null;
+ }
+ return integer(getCurrentSelenium().getText(locator));
+ }
+
+ public int getCurrentPage() {
+ JQueryLocator locator = scrollerRoot.getDescendant(currentPage);
+ if (!hasPages()) {
+ return 1;
+ }
+ return integer(getCurrentSelenium().getText(locator));
+ }
+
+ public boolean isFirstPage() {
+ return getCurrentPage() == 1;
+ }
+
+ public boolean isLastPage() {
+ return getCurrentPage() == getLastVisiblePage();
+ }
+
+ public static int integer(String string) {
+ return Integer.valueOf(string);
+ }
+}
Added:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataTable.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataTable.java
(rev 0)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/DataTable.java 2010-07-10
20:55:54 UTC (rev 17882)
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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 org.jboss.test.selenium.locator.JQueryLocator;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.*;
+import static org.jboss.test.selenium.framework.AjaxSelenium.getCurrentSelenium;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class DataTable {
+ JQueryLocator tableRoot;
+ JQueryLocator tableRows = jq(".rf-dt-c:nth-child(1)");
+
+ public DataTable(JQueryLocator tableRoot) {
+ super();
+ this.tableRoot = tableRoot;
+ }
+
+ public int getCountOfTableRows() {
+ JQueryLocator locator = tableRoot.getDescendant(tableRows);
+ return getCurrentSelenium().getCount(locator);
+
+ }
+
+ public static int integer(String string) {
+ return Integer.valueOf(string);
+ }
+}
Modified:
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 2010-07-10
20:55:17 UTC (rev 17881)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/richExtendedDataTable/ScrollerTestCase.java 2010-07-10
20:55:54 UTC (rev 17882)
@@ -32,7 +32,6 @@
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;
/**
@@ -55,12 +54,6 @@
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);
@@ -71,27 +64,21 @@
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}) {
+ private void testRowCount(DataScroller dataScroller) {
+ for (Integer rowsPerPage : new Integer[]{null, 10, 1, TOTAL_ROW_COUNT, 13, 9, 17,
TOTAL_ROW_COUNT + 1, 2 * TOTAL_ROW_COUNT}) {
if (rowsPerPage != null) {
selenium.type(attributeRowsInput, String.valueOf(rowsPerPage));
guardHttp(selenium).fireEvent(attributeRowsInput, Event.BLUR);
}
+ dataScroller.gotoFirstPage();
int rowCountPreset = Integer.valueOf(selenium.getValue(attributeRowsInput));
int rowCountActual = table.getCountOfTableRows();
- assertEquals(table.getCountOfTableRows(), Math.min(TOTAL_ROW_COUNT,
rowCountPreset));
+ assertEquals(rowCountActual, Math.min(TOTAL_ROW_COUNT, rowCountPreset));
assertEquals(dataScroller.hasPages(), rowCountActual < TOTAL_ROW_COUNT);
if (dataScroller.hasPages()) {
- dataScroller.clickLastPage();
+ dataScroller.gotoLastPage();
int pagesExpected = pageCountActual(rowCountActual);
int countOfVisiblePages = dataScroller.getCountOfVisiblePages();