Author: lfryc(a)redhat.com
Date: 2010-09-13 07:53:14 -0400 (Mon, 13 Sep 2010)
New Revision: 19165
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/LocatorReference.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java
Log:
extended ReferencedLocator by ability to reference another ReferencedLocator (or any other
ExtendedLocator deriving other type than own type)
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/LocatorReference.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/LocatorReference.java 2010-09-13
11:50:12 UTC (rev 19164)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/LocatorReference.java 2010-09-13
11:53:14 UTC (rev 19165)
@@ -27,7 +27,8 @@
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*
- * @param <T> type of referenced locator
+ * @param <T>
+ * type of referenced locator
*/
public class LocatorReference<T extends Locator<?>> {
@@ -42,12 +43,12 @@
return reference;
}
- public void setLocator(T locator) {
- this.reference = locator;
+ public void setLocator(T root) {
+ this.reference = root;
}
-
+
@Override
public String toString() {
- return "ref@" + reference;
+ return "ref@" + reference;
}
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java 2010-09-13
11:50:12 UTC (rev 19164)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/test/selenium/locator/reference/ReferencedLocator.java 2010-09-13
11:53:14 UTC (rev 19165)
@@ -22,9 +22,8 @@
package org.jboss.test.selenium.locator.reference;
import org.jboss.test.selenium.locator.AbstractElementLocator;
-import org.jboss.test.selenium.locator.CompoundableLocator;
import org.jboss.test.selenium.locator.ElementLocationStrategy;
-import org.jboss.test.selenium.locator.IterableLocator;
+import org.jboss.test.selenium.locator.ExtendedLocator;
import org.jboss.test.selenium.utils.text.SimplifiedFormat;
/**
@@ -34,33 +33,47 @@
* @param <T>
* type of referenced locator
*/
-public class ReferencedLocator<T extends IterableLocator<T> &
CompoundableLocator<T>> extends AbstractElementLocator<T>
- implements IterableLocator<T>, CompoundableLocator<T> {
+public final class ReferencedLocator<T extends ExtendedLocator<T>> extends
AbstractElementLocator<T> implements
+ ExtendedLocator<T> {
- private LocatorReference<T> reference;
+ private LocatorReference<ExtendedLocator<T>> reference;
private String addition;
- public ReferencedLocator(LocatorReference<T> reference, String locator) {
+ private ReferencedLocator(LocatorReference<ExtendedLocator<T>> reference,
String addition) {
super("not-used");
this.reference = reference;
- this.addition = locator;
+ this.addition = addition;
}
- public static <N extends IterableLocator<N> &
CompoundableLocator<N>> ReferencedLocator<N> ref(
- LocatorReference<N> reference, String locator) {
- return new ReferencedLocator<N>(reference, locator);
+ public static <N extends ExtendedLocator<N>> ReferencedLocator<N>
ref(LocatorReference<N> reference, String locator) {
+ LocatorReference<ExtendedLocator<N>> castReference =
(LocatorReference<ExtendedLocator<N>>) reference;
+ ReferencedLocator<N> result = new ReferencedLocator<N>(castReference,
locator);
+ return result;
}
+ public static <N extends ExtendedLocator<N>> ReferencedLocator<N>
referenceInferred(
+ LocatorReference<ExtendedLocator<N>> reference, String locator) {
+ ReferencedLocator<N> result = new ReferencedLocator<N>(reference,
locator);
+ result.reference = reference;
+ return result;
+ }
+
public T getReferenced() {
- T referencedLocator = reference.getLocator();
+ ExtendedLocator<T> referencedLocator = reference.getLocator();
@SuppressWarnings("unchecked")
Class<T> tClass = (Class<T>) referencedLocator.getClass();
try {
+ if (tClass.isAssignableFrom(ReferencedLocator.class)) {
+ ReferencedLocator<T> ancestor = (ReferencedLocator<T>)
referencedLocator;
+ referencedLocator = ancestor.getReferenced();
+ tClass = (Class<T>) referencedLocator.getClass();
+ }
+
T newInstance = tClass.getConstructor(String.class).newInstance(addition);
-
- return referencedLocator.getDescendant(newInstance);
+ T result = referencedLocator.getDescendant(newInstance);
+ return result;
} catch (Exception e) {
throw new IllegalStateException(e);
}
@@ -103,12 +116,11 @@
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);
+ // TODO fix the <T> param cast
+ return (T) new ReferencedLocator<T>(this.reference, newAddition);
} catch (Exception e) {
throw new IllegalStateException(e);
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java 2010-09-13
11:50:12 UTC (rev 19164)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/AbstractComponentAttributes.java 2010-09-13
11:53:14 UTC (rev 19165)
@@ -24,12 +24,17 @@
import org.jboss.test.selenium.dom.Event;
import org.jboss.test.selenium.framework.AjaxSelenium;
import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.Attribute;
import org.jboss.test.selenium.locator.AttributeLocator;
import org.jboss.test.selenium.locator.ElementLocator;
import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.ExtendedLocator;
+import org.jboss.test.selenium.locator.reference.LocatorReference;
+import org.jboss.test.selenium.locator.reference.ReferencedLocator;
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardHttp;
import static org.richfaces.tests.metamer.ftest.AbstractMetamerTest.pjq;
+import static
org.jboss.test.selenium.locator.reference.ReferencedLocator.referenceInferred;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -39,8 +44,17 @@
protected AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
- JQueryLocator propertyLocator = pjq("input[id$={0}Input]");
+ LocatorReference<ExtendedLocator<JQueryLocator>> root = new
LocatorReference<ExtendedLocator<JQueryLocator>>(
+ pjq(""));
+ ReferencedLocator<JQueryLocator> propertyLocator = referenceInferred(root,
"input[id$={0}Input]");
+ public AbstractComponentAttributes() {
+ }
+
+ public <T extends ExtendedLocator<JQueryLocator>>
AbstractComponentAttributes(T root) {
+ this.root.setLocator(root);
+ }
+
protected String getProperty(String propertyName) {
final ElementLocator<?> locator = propertyLocator.format(propertyName);
return selenium.getValue(locator);
@@ -48,8 +62,7 @@
protected void setProperty(String propertyName, Object value) {
final ElementLocator<?> locator = propertyLocator.format(propertyName);
- final AttributeLocator<?> typeLocator = locator.getAttribute(new
org.jboss.test.selenium.locator.Attribute(
- "type"));
+ final AttributeLocator<?> typeLocator =
locator.getAttribute(Attribute.TYPE);
String inputType = selenium.getAttribute(typeLocator);
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 2010-09-13
11:50:12 UTC (rev 19164)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/AbstractModel.java 2010-09-13
11:53:14 UTC (rev 19165)
@@ -21,7 +21,7 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.model;
-import org.jboss.test.selenium.locator.IterableLocator;
+import org.jboss.test.selenium.locator.ExtendedLocator;
import org.jboss.test.selenium.locator.reference.LocatorReference;
/**
@@ -33,7 +33,7 @@
* @param <T>
* the iterable locator type of root
*/
-public abstract class AbstractModel<T extends IterableLocator<T>> {
+public abstract class AbstractModel<T extends ExtendedLocator<T>> {
protected LocatorReference<T> root = new LocatorReference<T>(null);
private String name = this.getClass().getSimpleName();
Show replies by date