Author: lfryc(a)redhat.com
Date: 2010-07-30 09:26:25 -0400 (Fri, 30 Jul 2010)
New Revision: 18298
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AssertingDataScroller.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java
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/TestScroller.java
Log:
introduced name parameter for AbstractModel (used on #toString() method)
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java 2010-07-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -21,8 +21,6 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.model;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
import org.jboss.test.selenium.locator.IterableLocator;
import org.jboss.test.selenium.locator.reference.LocatorReference;
@@ -38,14 +36,15 @@
public abstract class AbstractModel<T extends IterableLocator<T>> {
protected LocatorReference<T> root = new LocatorReference<T>(null);
+ private String name = this.getClass().getSimpleName();
public AbstractModel(T root) {
setRoot(root);
}
- @Override
- public String toString() {
- return new ToStringBuilder(this,
ToStringStyle.SIMPLE_STYLE).append(root).toString();
+ public AbstractModel(String name, T root) {
+ setRoot(root);
+ this.name = name;
}
public void setRoot(T root) {
@@ -55,4 +54,9 @@
public T getRoot() {
return root.getLocator();
}
+
+ @Override
+ public String toString() {
+ return name;
+ }
}
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AssertingDataScroller.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AssertingDataScroller.java 2010-07-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AssertingDataScroller.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -37,6 +37,10 @@
super(root);
}
+ public AssertingDataScroller(String name, JQueryLocator root) {
+ super(name, root);
+ }
+
@Override
public void gotoPage(int pageNumber) {
int startCount = this.getCountOfVisiblePages();
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java 2010-07-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataGrid.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -24,6 +24,8 @@
import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
import static org.jboss.test.selenium.locator.LocatorFactory.*;
+import java.util.Iterator;
+
import org.jboss.test.selenium.framework.AjaxSelenium;
import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
import org.jboss.test.selenium.locator.JQueryLocator;
@@ -36,27 +38,40 @@
public class DataGrid extends AbstractModel<JQueryLocator> {
AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
-
+
ReferencedLocator<JQueryLocator> rows = ref(root, "> tbody.rf-dg-body
> tr.rf-dg-r");
- JQueryLocator rowToColumn = jq("td.rf-dg-c:not(:empty)");
+ JQueryLocator rowToNonEmptyElement = jq("td.rf-dg-c:not(:empty)");
+ JQueryLocator rowToElement = jq("td.rf-dg-c");
public DataGrid(JQueryLocator root) {
super(root);
}
+ public DataGrid(String name, JQueryLocator root) {
+ super(name, root);
+ }
+
public int getElementCount() {
- return selenium.getCount(rows.getChild(rowToColumn));
+ return selenium.getCount(rows.getChild(rowToNonEmptyElement));
}
-
+
public int getColumnCount() {
- return selenium.getCount(rows.getNthOccurence(1).getChild(rowToColumn));
+ return selenium.getCount(rows.getNthOccurence(1).getChild(rowToElement));
}
-
+
public int getRowCount() {
- return selenium.getCount(rows.getChild(rowToColumn).getNthChildElement(1));
+ return selenium.getCount(rows.getChild(rowToElement).getNthChildElement(1));
}
-
- public JQueryLocator getElement(int row, int column) {
- return
rows.getNthOccurence(row).getChild(rowToColumn).getNthChildElement(column);
+
+ public JQueryLocator getElementOnCoordinates(int row, int column) {
+ return
rows.getNthOccurence(row).getChild(rowToNonEmptyElement).getNthChildElement(column);
}
+
+ public JQueryLocator getElementOnIndex(int index) {
+ return rows.getChild(rowToNonEmptyElement).getNthOccurence(index);
+ }
+
+ public Iterator<JQueryLocator> iterateElements() {
+ return rows.getDescendants(rowToNonEmptyElement).iterator();
+ }
}
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2010-07-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -39,7 +39,7 @@
public class DataScroller extends AbstractModel<JQueryLocator> {
protected static final String CLASS_DISABLED = "rf-ds-dis";
-
+
AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
ReferencedLocator<JQueryLocator> numberedPages = ref(root, ">
.rf-ds-dtl");
@@ -53,18 +53,22 @@
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");
-
+
Integer fastStep = null;
Integer lastPage = null;
public DataScroller(JQueryLocator root) {
super(root);
}
-
+
+ public DataScroller(String name, JQueryLocator root) {
+ super(name, root);
+ }
+
public void setFastStep(int fastStep) {
this.fastStep = fastStep;
}
-
+
public void setLastPage(int pageNumber) {
this.lastPage = pageNumber;
}
@@ -82,14 +86,14 @@
}
public void gotoPage(int pageNumber) {
- while (pageNumber > getLastVisiblePage()) {
+ while (pageNumber > getLastVisiblePage()) {
fastForward();
}
-
+
while (pageNumber < getFirstVisiblePage()) {
fastRewind();
}
-
+
clickPageButton(pageNumber);
}
@@ -146,7 +150,7 @@
}
return integer(selenium.getText(lastVisiblePage));
}
-
+
public int getLastPage() {
int startPage = getCurrentPage();
clickLastPageButton();
@@ -189,7 +193,7 @@
public void clickPageButton(int pageNumber) {
guardXhr(selenium).click(specificNumberedPage.format(pageNumber));
}
-
+
public void clickFastForward() {
guardXhr(selenium).click(fastForwardButton);
}
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java 2010-07-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -43,6 +43,10 @@
public DataTable(JQueryLocator root) {
super(root);
}
+
+ public DataTable(String name, JQueryLocator root) {
+ super(name, root);
+ }
public int getCountOfTableRows() {
return selenium.getCount(tableRows);
Modified:
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java
===================================================================
---
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java 2010-07-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataGrid/TestSimple.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -23,8 +23,11 @@
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static java.lang.Math.*;
import java.net.URL;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXBException;
@@ -37,9 +40,13 @@
import org.richfaces.tests.metamer.ftest.annotations.Use;
import org.richfaces.tests.metamer.ftest.model.DataGrid;
import org.richfaces.tests.metamer.model.Capital;
+import org.richfaces.util.CollectionsUtils;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
+import com.google.inject.internal.Collections2;
+import com.google.inject.internal.cglib.core.CollectionUtils;
+
import static org.jboss.test.selenium.locator.LocatorFactory.*;
import static org.testng.Assert.*;
@@ -55,6 +62,7 @@
JQueryLocator attributeColumns = pjq("input[id$=columnsInput]");
JQueryLocator attributeElements = pjq("input[id$=elementsInput]");
+ JQueryLocator attributeFirst = pjq("input[id$=firstInput]");
DataGrid dataGrid = new DataGrid(jq("table.rf-dg[id$=richDataGrid]"));
@@ -66,6 +74,10 @@
@Use(empty = true)
Integer elements;
+ @Inject
+ @Use(empty = true)
+ Integer first;
+
@SuppressWarnings("restriction")
public TestSimple() throws JAXBException {
capitals = Model.unmarshallCapitals();
@@ -80,6 +92,7 @@
public void prepareAttributes() {
prepareAttribute(attributeColumns, columns);
prepareAttribute(attributeElements, elements);
+ prepareAttribute(attributeFirst, first);
}
private void prepareAttribute(ElementLocator<?> inputLocator, Object value) {
@@ -88,35 +101,52 @@
}
@Test
- @Use(field = "columns", ints = { 1, 3, 11, ELEMENTS_TOTAL / 2,
ELEMENTS_TOTAL })
+ @Use(field = "columns", ints = { 1, 3, 11, ELEMENTS_TOTAL / 2,
ELEMENTS_TOTAL - 1, ELEMENTS_TOTAL,
+ ELEMENTS_TOTAL + 1 })
public void testColumnsAttribute() {
- elements = ELEMENTS_TOTAL;
verifyCounts();
-
- int columnCount = dataGrid.getColumnCount();
- int rowCount = dataGrid.getRowCount();
- rowIteration: for (int r = 1; r <= rowCount; r++) {
- for (int c = 1; c <= columnCount; c++) {
- final int index = ((r - 1) * columnCount) + c - 1;
- if (index >= ELEMENTS_TOTAL) {
- break rowIteration;
- }
- String expectedStateName = capitals.get(index).getState();
- String stateName = selenium.getText(dataGrid.getElement(r,
c).getChild(jq("span")));
- assertEquals(stateName, expectedStateName);
- }
- }
+ verifyElements();
}
@Test
- @Use(field = "elements", ints = { 0, 1, 3, 5, 7 })
+ @Use(field = "elements", ints = { 0, 1, ELEMENTS_TOTAL / 2, ELEMENTS_TOTAL
- 1, ELEMENTS_TOTAL, ELEMENTS_TOTAL + 1 })
public void testElementsAttribute() {
- assertEquals(dataGrid.getElementCount(), (int) elements);
+ verifyCounts();
+ verifyElements();
}
+ @Test
+ @Use(field = "first", ints = { 0, 1, ELEMENTS_TOTAL / 2, ELEMENTS_TOTAL -
1, ELEMENTS_TOTAL, ELEMENTS_TOTAL + 1 })
+ public void testFirstAttribute() {
+ verifyCounts();
+ verifyElements();
+ }
+
private void verifyCounts() {
- assertEquals(dataGrid.getElementCount(), (int) elements);
- assertEquals(dataGrid.getColumnCount(), (int) columns);
- assertEquals(dataGrid.getRowCount(), (int) Math.ceil((float) elements /
columns));
+ int nFirst = first == null ? 0 : min(ELEMENTS_TOTAL, max(0, first));
+ int nElements = (elements == null ? ELEMENTS_TOTAL : min(elements,
ELEMENTS_TOTAL)) - nFirst;
+ int nColumns = columns;
+ double nRows = ceil((float) nElements / columns);
+
+ assertEquals(dataGrid.getElementCount(), (int) nElements);
+ assertEquals(dataGrid.getColumnCount(), (int) nColumns);
+ assertEquals(dataGrid.getRowCount(), (int) nRows);
}
+
+ private void verifyElements() {
+ int nFirst = first == null ? 0 : min(ELEMENTS_TOTAL, max(0, first));
+ int nElements = (elements == null ? ELEMENTS_TOTAL : min(elements,
ELEMENTS_TOTAL)) - nFirst;
+
+ Iterator<Capital> capitalIterator = capitals.subList(nFirst, nFirst +
nElements).iterator();
+ Iterator<JQueryLocator> elementIterator = dataGrid.iterateElements();
+
+ while (capitalIterator.hasNext()) {
+ final Capital capital = capitalIterator.next();
+ if (!elementIterator.hasNext()) {
+ fail("there should be next element for state name: " +
capital.getState());
+ }
+ final JQueryLocator element =
elementIterator.next().getChild(jq("span"));
+ assertEquals(selenium.getText(element), capital.getState());
+ }
+ }
}
Modified:
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 2010-07-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestPagination.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -46,12 +46,12 @@
public class TestPagination extends AbstractMetamerTest {
private static final int[] PAGES = new int[] { 3, 6, 1, 4, 6, 2, 4, 5 };
-
+
@Inject
@Use(value = { "dataScroller*" })
AssertingDataScroller dataScroller;
- AssertingDataScroller dataScroller1 = new
AssertingDataScroller(pjq("span.rf-ds[id$=scroller1]"));
- AssertingDataScroller dataScroller2 = new
AssertingDataScroller(pjq("span.rf-ds[id$=scroller2]"));
+ AssertingDataScroller dataScroller1 = new
AssertingDataScroller("outside-table",
pjq("span.rf-ds[id$=scroller1]"));
+ AssertingDataScroller dataScroller2 = new
AssertingDataScroller("in-table-footer",
pjq("span.rf-ds[id$=scroller2]"));
IdLocator attributeFastStep = id("form:attributes:fastStepInput");
IdLocator attributeMaxPages = id("form:attributes:maxPagesInput");
@@ -73,7 +73,7 @@
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/richDataScroller/simple.xhtml");
}
-
+
@BeforeMethod
public void prepareAttributes() {
guardHttp(selenium).type(attributeFastStep, String.valueOf(fastStep));
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-30
13:25:33 UTC (rev 18297)
+++
root/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richExtendedDataTable/TestScroller.java 2010-07-30
13:26:25 UTC (rev 18298)
@@ -43,10 +43,10 @@
public class TestScroller extends AbstractMetamerTest {
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
AssertingDataScroller(pjq("span.rf-ds[id$=scroller1]"));
- DataScroller dataScroller2 = new
AssertingDataScroller(pjq("span.rf-ds[id$=scroller2]"));
+ 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 AssertingDataScroller("outside-table",
pjq("span.rf-ds[id$=scroller1]"));
+ DataScroller dataScroller2 = new
AssertingDataScroller("inside-table-footer",
pjq("span.rf-ds[id$=scroller2]"));
DataTable table = new DataTable(pjq("div.rf-edt[id$=richEDT]"));
IdLocator attributeRowsInput = id("form:attributes:rowsInput");