Author: lfryc(a)redhat.com
Date: 2010-07-23 03:21:06 -0400 (Fri, 23 Jul 2010)
New Revision: 18210
Added:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataTable.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/TestScroller.java
Log:
introduced AssertingDataScroller - used in richExtendedDataTable/TestScroller and in new
case richDataScroller/TestPagination
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java 2010-07-23
07:19:27 UTC (rev 18209)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java 2010-07-23
07:21:06 UTC (rev 18210)
@@ -25,6 +25,7 @@
import org.jboss.test.selenium.locator.CompoundableLocator;
import org.jboss.test.selenium.locator.IterableLocator;
import org.jboss.test.selenium.locator.type.LocationStrategy;
+import org.jboss.test.selenium.utils.text.SimplifiedFormat;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -101,4 +102,15 @@
public Iterable<T> getDescendants(T elementLocator) {
return getReferenced().getDescendants(elementLocator);
}
+
+ @SuppressWarnings("unchecked")
+ public T format(Object... args) {
+ String newAddition = SimplifiedFormat.format(addition, args);
+ try {
+ return (T) this.getClass().getConstructor(LocatorReference.class,
String.class)
+ .newInstance(reference, newAddition);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
}
Added:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java
(rev 0)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-23
07:21:06 UTC (rev 18210)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.metamer.ftest.richDataScroller;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.id;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.locator.IdLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.richExtendedDataTable.AssertingDataScroller;
+import org.richfaces.tests.metamer.ftest.richExtendedDataTable.DataTable;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.*;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.*;
+
+/**
+ * Test the functionality of switching pages using DataScroller bound to DataTable.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestPagination extends AbstractMetamerTest {
+
+ private static final int[] PAGES = new int[] { 3, 6, 1, 4, 6, 2, 4, 5 };
+
+ IdLocator attributeFastStep = id("form:attributes:fastStepInput");
+ IdLocator attributeMaxPages = id("form:attributes:maxPagesInput");
+
+ AssertingDataScroller dataScroller = new AssertingDataScroller(null);
+ DataTable dataTable = new
DataTable(pjq("table.rf-dt[id$=richDataTable]"));
+
+ JQueryLocator scroller1 = pjq("span.rf-ds[id$=scroller1]");
+ JQueryLocator scroller2 = pjq("span.rf-ds[id$=scroller2]");
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richDataScroller/simple.xhtml");
+ }
+
+ @Test(dataProvider = "templates")
+ public void testNumberedPagesScrollerOutsideTable(String template) {
+ testNumberedPages(scroller1);
+ }
+
+ @Test(dataProvider = "templates")
+ public void testNumberedPagesFooterScroller(String template) {
+ testNumberedPages(scroller2);
+ }
+
+ public void testNumberedPages(JQueryLocator scrollerLocator) {
+ dataScroller.setRoot(scrollerLocator);
+ dataScroller.setFastStep(2);
+ dataScroller.setLastPage(dataScroller.getLastPage());
+
+ for (int pageNumber : PAGES) {
+ String tableText = dataTable.getTableText();
+ dataScroller.gotoPage(pageNumber);
+ assertFalse(tableText.equals(dataTable.getTableText()));
+ }
+ }
+
+ @Override
+ @AfterMethod(alwaysRun = true)
+ public void invalidateSession() {
+ super.invalidateSession();
+ }
+
+ @BeforeMethod
+ public void prepareAttributes() {
+ guardHttp(selenium).type(attributeFastStep, "2");
+ guardHttp(selenium).type(attributeMaxPages, "3");
+ }
+}
Added:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java
(rev 0)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/AssertingDataScroller.java 2010-07-23
07:21:06 UTC (rev 18210)
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * 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.metamer.ftest.richExtendedDataTable;
+
+import static junit.framework.Assert.*;
+
+import org.jboss.test.selenium.locator.JQueryLocator;
+
+/**
+ * Provides DataScroller control methods with assertions about scroller state.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class AssertingDataScroller extends DataScroller {
+
+ private static final String CLASS_DISABLED = "rf-ds-dis";
+
+ private Integer fastStep = null;
+ private Integer lastPage = null;
+
+ public AssertingDataScroller(JQueryLocator root) {
+ super(root);
+ }
+
+ public void setFastStep(int fastStep) {
+ this.fastStep = fastStep;
+ }
+
+ public void setLastPage(int pageNumber) {
+ this.lastPage = pageNumber;
+ }
+
+ @Override
+ public void gotoPage(int pageNumber) {
+ int startCount = this.getCountOfVisiblePages();
+ super.gotoPage(pageNumber);
+
+ int currentPage = this.getCurrentPage();
+ assertEquals(this.getCountOfVisiblePages(), startCount);
+ assertEquals(currentPage, pageNumber);
+
+ assertEquals(isFirstPageButtonDisabled(), this.isFirstPage());
+ assertEquals(isLastPageButtonDisabled(), this.isLastPage());
+
+ if (fastStep != null) {
+ assertEquals(isFastRewindDisabled(), currentPage - fastStep < 1);
+ if (lastPage != null) {
+ assertEquals(isFastForwardDisabled(), currentPage + fastStep >
lastPage);
+ }
+ }
+ }
+
+ @Override
+ public void gotoFirstPage() {
+ super.gotoFirstPage();
+ assertTrue(isFastRewindDisabled());
+ assertTrue(isFirstPageButtonDisabled());
+ }
+
+ @Override
+ public void gotoLastPage() {
+ super.gotoLastPage();
+ assertTrue(isFastForwardDisabled());
+ assertTrue(isLastPageButtonDisabled());
+ }
+
+ public boolean isFastForwardDisabled() {
+ return selenium.belongsClass(fastForwardButton, CLASS_DISABLED);
+ }
+
+ public boolean isFastRewindDisabled() {
+ return selenium.belongsClass(fastRewindButton, CLASS_DISABLED);
+ }
+
+ public boolean isLastPageButtonDisabled() {
+ return selenium.belongsClass(lastPageButton, CLASS_DISABLED);
+ }
+
+ public boolean isFirstPageButtonDisabled() {
+ return selenium.belongsClass(firstPageButton, CLASS_DISABLED);
+ }
+}
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java 2010-07-23
07:19:27 UTC (rev 18209)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataScroller.java 2010-07-23
07:21:06 UTC (rev 18210)
@@ -32,6 +32,8 @@
import static org.jboss.test.selenium.locator.reference.ReferencedLocator.*;
/**
+ * Provides DataScroller control methods.
+ *
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
@@ -40,9 +42,16 @@
AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
LocatorReference<JQueryLocator> root = new
LocatorReference<JQueryLocator>(null);
- ReferencedLocator<JQueryLocator> pageNumbers = ref(root, ">
.rf-ds-dtl");
+
+ ReferencedLocator<JQueryLocator> numberedPages = ref(root, ">
.rf-ds-dtl");
+ ReferencedLocator<JQueryLocator> specificNumberedPage = ref(root, ">
.rf-ds-dtl:textEquals('{0}')");
+
ReferencedLocator<JQueryLocator> firstPageButton = ref(root, ">
.rf-ds-l[id$=ds_f]");
- ReferencedLocator<JQueryLocator> lastPageButton = ref(root, ">
.rf-ds-r:eq(1)");
+ ReferencedLocator<JQueryLocator> fastRewindButton = ref(root, ">
.rf-ds-l[id$=ds_fr]");
+ ReferencedLocator<JQueryLocator> fastForwardButton = ref(root, ">
.rf-ds-r[id$=ds_ff]");
+ ReferencedLocator<JQueryLocator> lastPageButton = ref(root, ">
.rf-ds-r[id$=ds_l]");
+
+ ReferencedLocator<JQueryLocator> firstVisiblePage = ref(root, ">
.rf-ds-dtl:first");
ReferencedLocator<JQueryLocator> lastVisiblePage = ref(root, ">
.rf-ds-dtl:last");
ReferencedLocator<JQueryLocator> currentPage = ref(root, ">
.rf-ds-cur");
@@ -70,28 +79,63 @@
}
}
- public void clickLastPageButton() {
- guardXhr(selenium).click(lastPageButton);
+ public void gotoPage(int pageNumber) {
+ while (pageNumber > getLastVisiblePage()) {
+ fastForward();
+ }
+ while (pageNumber < getFirstVisiblePage()) {
+ fastRewind();
+ }
+ clickPageButton(pageNumber);
}
- public void clickFirstPageButton() {
- guardXhr(selenium).click(firstPageButton);
+ public void fastForward() {
+ if (selenium.belongsClass(fastForwardButton, "rf-ds-dis")) {
+ throw new AssertionError("fast forward button disabled");
+ }
+ clickFastForward();
}
+ public void fastRewind() {
+ if (selenium.belongsClass(fastRewindButton, "rf-ds-dis")) {
+ throw new AssertionError("fast rewind button disabled");
+ }
+ clickFastRewind();
+ }
+
public int getCountOfVisiblePages() {
- return selenium.getCount(pageNumbers);
+ return selenium.getCount(numberedPages);
}
public boolean hasPages() {
return selenium.isElementPresent(lastVisiblePage);
}
- public Integer getLastVisiblePage() {
+ public int getFirstVisiblePage() {
if (!hasPages()) {
- return null;
+ return 1;
}
+ return integer(selenium.getText(firstVisiblePage));
+ }
+
+ public int getLastVisiblePage() {
+ if (!hasPages()) {
+ return 1;
+ }
return integer(selenium.getText(lastVisiblePage));
}
+
+ public int getLastPage() {
+ int startPage = getCurrentPage();
+ clickLastPageButton();
+ int lastPage = getCurrentPage();
+ if (startPage == 1) {
+ clickFirstPageButton();
+ } else {
+ gotoPage(startPage);
+ }
+ return lastPage;
+ }
public int getCurrentPage() {
if (!hasPages()) {
@@ -111,4 +155,26 @@
public static int integer(String string) {
return Integer.valueOf(string);
}
+
+ public void clickLastPageButton() {
+ guardXhr(selenium).click(lastPageButton);
+ }
+
+ public void clickFirstPageButton() {
+ guardXhr(selenium).click(firstPageButton);
+ }
+
+ public void clickPageButton(int pageNumber) {
+ guardXhr(selenium).click(specificNumberedPage.format(pageNumber));
+ }
+
+ public void clickFastForward() {
+ guardXhr(selenium).click(fastForwardButton);
+ }
+
+ public void clickFastRewind() {
+ guardXhr(selenium).click(fastRewindButton);
+ }
+
+
}
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataTable.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataTable.java 2010-07-23
07:19:27 UTC (rev 18209)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/DataTable.java 2010-07-23
07:21:06 UTC (rev 18210)
@@ -30,6 +30,8 @@
import static org.jboss.test.selenium.locator.reference.ReferencedLocator.*;
/**
+ * Provides methods to control DataTable
+ *
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
@@ -38,7 +40,7 @@
AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
LocatorReference<JQueryLocator> root = new
LocatorReference<JQueryLocator>(null);
-
+
ReferencedLocator<JQueryLocator> tableRows = ref(root, "> div.rf-edt-b
table table tr");
public DataTable(JQueryLocator tableRoot) {
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/TestScroller.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/TestScroller.java 2010-07-23
07:19:27 UTC (rev 18209)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/TestScroller.java 2010-07-23
07:21:06 UTC (rev 18210)
@@ -42,8 +42,8 @@
private static final int TOTAL_ROW_COUNT = 50;
private static final Integer[] ROW_COUNT_VALUES =
new Integer[]{null, 10, 1, TOTAL_ROW_COUNT, 13, 9, 17, TOTAL_ROW_COUNT + 1, 2
* TOTAL_ROW_COUNT};
- DataScroller dataScroller1 = new
DataScroller(pjq("span.rf-ds[id$=scroller1]"));
- DataScroller dataScroller2 = new
DataScroller(pjq("span.rf-ds[id$=scroller2]"));
+ DataScroller dataScroller1 = new
AssertingDataScroller(pjq("span.rf-ds[id$=scroller1]"));
+ DataScroller dataScroller2 = new
AssertingDataScroller(pjq("span.rf-ds[id$=scroller2]"));
DataTable table = new DataTable(pjq("div.rf-edt[id$=richEDT]"));
IdLocator attributeRowsInput = id("form:attributes:rowsInput");