Author: lfryc(a)redhat.com
Date: 2011-01-14 08:51:17 -0500 (Fri, 14 Jan 2011)
New Revision: 21022
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
Log:
AbstractModel now extends ExtendedLocator + added ModelIterable to iterate though models
by giving them root locators
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java 2011-01-14
13:50:19 UTC (rev 21021)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java 2011-01-14
13:51:17 UTC (rev 21022)
@@ -21,6 +21,9 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.model;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.ElementLocationStrategy;
import org.jboss.test.selenium.locator.ExtendedLocator;
import org.jboss.test.selenium.locator.reference.LocatorReference;
@@ -33,7 +36,7 @@
* @param <T>
* the iterable locator type of root
*/
-public abstract class AbstractModel<T extends ExtendedLocator<T>> {
+public abstract class AbstractModel<T extends ExtendedLocator<T>> implements
ExtendedLocator<T> {
protected LocatorReference<T> root = new LocatorReference<T>(null);
private String name = this.getClass().getSimpleName();
@@ -59,4 +62,74 @@
public String toString() {
return name;
}
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public T getChild(T elementLocator) {
+ return root.getLocator().getChild(elementLocator);
+ }
+
+ @Override
+ public T getDescendant(T elementLocator) {
+ return root.getLocator().getDescendant(elementLocator);
+ }
+
+ @Override
+ public T getNthChildElement(int index) {
+ return root.getLocator().getNthChildElement(index);
+ }
+
+ @Override
+ public T getNthOccurence(int index) {
+ return root.getLocator().getNthOccurence(index);
+ }
+
+ @Override
+ public Iterable<T> getAllChildren() {
+ return root.getLocator().getAllChildren();
+ }
+
+ @Override
+ public Iterable<T> getAllOccurrences() {
+ return root.getLocator().getAllOccurrences();
+ }
+
+ @Override
+ public Iterable<T> getChildren(T elementLocator) {
+ return root.getLocator().getChildren(elementLocator);
+ }
+
+ @Override
+ public Iterable<T> getDescendants(T elementLocator) {
+ return root.getLocator().getDescendants(elementLocator);
+ }
+
+ @Override
+ public AttributeLocator<T> getAttribute(Attribute attribute) {
+ return root.getLocator().getAttribute(attribute);
+ }
+
+ @Override
+ public ElementLocationStrategy getLocationStrategy() {
+ return root.getLocator().getLocationStrategy();
+ }
+
+ @Override
+ public String getAsString() {
+ return root.getLocator().getAsString();
+ }
+
+ @Override
+ public String getRawLocator() {
+ return root.getLocator().getRawLocator();
+ }
+
+ @Override
+ public T format(Object... args) {
+ return root.getLocator().format(args);
+ }
+
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2011-01-14
13:50:19 UTC (rev 21021)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2011-01-14
13:51:17 UTC (rev 21022)
@@ -24,12 +24,12 @@
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
-import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
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.ReferencedLocator;
+import org.jboss.test.selenium.utils.text.SimplifiedFormat;
/**
* Provides DataScroller control methods.
@@ -96,7 +96,7 @@
public void gotoPage(int pageNumber) {
if (lastPage != null && (pageNumber < 1 || pageNumber > lastPage))
{
- throw new IllegalStateException(format("The given pageNumber
'{0}' is out of range of pages <1,{1}>", pageNumber, lastPage));
+ throw new IllegalStateException(SimplifiedFormat.format("The given
pageNumber '{0}' is out of range of pages <1,{1}>", pageNumber,
lastPage));
}
while (pageNumber > getLastVisiblePage()) {
fastForward(pageNumber);
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/ModelIterable.java 2011-01-14
13:51:17 UTC (rev 21022)
@@ -0,0 +1,52 @@
+package org.richfaces.tests.metamer.ftest.model;
+
+import java.lang.reflect.Constructor;
+import java.util.Iterator;
+
+import org.jboss.test.selenium.locator.ExtendedLocator;
+
+public class ModelIterable<E extends ExtendedLocator<E>, T extends
AbstractModel<E>> implements Iterable<T> {
+
+ Iterable<E> iterable;
+ Class<T> classT;
+
+ public ModelIterable(Iterable<E> iterable, Class<T> classT) {
+ this.iterable = iterable;
+ this.classT = classT;
+ }
+
+ @Override
+ public Iterator<T> iterator() {
+ return new ModelIterator();
+ }
+
+ public class ModelIterator implements Iterator<T> {
+
+ Iterator<E> iterator = iterable.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public T next() {
+ ExtendedLocator<E> locator = iterator.next();
+
+ try {
+ Constructor<T> constructor =
classT.getConstructor(ExtendedLocator.class);
+ T newInstance = constructor.newInstance(locator);
+ return newInstance;
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("unsupported operation");
+ }
+ }
+
+}
Show replies by date