Author: jjamrich
Date: 2011-09-05 04:48:31 -0400 (Mon, 05 Sep 2011)
New Revision: 22677
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeEnum.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeList.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/Attributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/TooltipAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/UsageTest.java
Log:
RFPL-1439: PoC for unified way to setting attributes in Metamer tests
There is PoC with core classes and one usage test with example.
The main difference between current solution and this is that there is no need to write
setter methods for all component attributes, but only simply copy all properties into enum
(which should be simply copy&paste from component UIClass), and add type safety on
component properties tests (usable for refactoring, when some attributes renamed or
removed)
In next step is neccessary to change all classes using AbstractComponentAttributes class,
and change routines in AbstractMetamerTest class as well since there are some routines to
test style, styleClass or title attributes.
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeEnum.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeEnum.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeEnum.java 2011-09-05
08:48:31 UTC (rev 22677)
@@ -0,0 +1,5 @@
+package org.richfaces.tests.metamer.ftest.attributes;
+
+public interface AttributeEnum {
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeList.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeList.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/AttributeList.java 2011-09-05
08:48:31 UTC (rev 22677)
@@ -0,0 +1,5 @@
+package org.richfaces.tests.metamer.ftest.attributes;
+
+public class AttributeList {
+ public static Attributes<TooltipAttributes> tooltipAttributes = new
Attributes<TooltipAttributes>();
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/Attributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/Attributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/Attributes.java 2011-09-05
08:48:31 UTC (rev 22677)
@@ -0,0 +1,151 @@
+package org.richfaces.tests.metamer.ftest.attributes;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guard;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static
org.jboss.test.selenium.locator.reference.ReferencedLocator.referenceInferred;
+import static org.richfaces.tests.metamer.ftest.AbstractMetamerTest.pjq;
+
+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.interception.CommandContext;
+import org.jboss.test.selenium.interception.CommandInterceptionException;
+import org.jboss.test.selenium.interception.CommandInterceptor;
+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.ExtendedLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.option.OptionValueLocator;
+import org.jboss.test.selenium.locator.reference.LocatorReference;
+import org.jboss.test.selenium.locator.reference.ReferencedLocator;
+import org.jboss.test.selenium.request.RequestType;
+import org.jboss.test.selenium.waiting.Wait;
+
+import com.thoughtworks.selenium.SeleniumException;
+
+
+public class Attributes<T extends AttributeEnum> {
+
+ protected AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+ LocatorReference<ExtendedLocator<JQueryLocator>> root =
+ new
LocatorReference<ExtendedLocator<JQueryLocator>>(pjq(""));
+ ReferencedLocator<JQueryLocator> propertyLocator = referenceInferred(root,
":input[id*=:{0}Input]{1}");
+
+ RequestType requestType = RequestType.HTTP;
+
+ public void set(T attribute, String string) {
+ setProperty(attribute.toString(), string);
+ }
+
+ // TODO jjamrich 2011-09-02: make sure that this resolve to correct string
representation of number given as attr
+ public void set(T attribute, Integer integer) {
+ setProperty(attribute.toString(), integer);
+ }
+
+ public void set(T attribute, Boolean bool) {
+ setProperty(attribute.toString(), bool);
+ }
+
+ public void set(T attribute, Enum<?> item) {
+ setProperty(attribute.toString(), item.toString());
+ }
+
+ /*protected void set(String propertyName, Object value) {
+
+ }*/
+
+ protected void setProperty(String propertyName, Object value) {
+ selenium.getInterceptionProxy().registerInterceptor(new
RepeatForElementNotFound());
+
+ ExtendedLocator<JQueryLocator> locator =
propertyLocator.format(propertyName, "");
+ final AttributeLocator<?> typeLocator =
locator.getAttribute(Attribute.TYPE);
+ final ExtendedLocator<JQueryLocator> optionLocator =
locator.getChild(jq("option"));
+
+ String inputType = null;
+ if (selenium.getCount(propertyLocator.format(propertyName)) > 1) {
+ inputType = "radio";
+ } else if (selenium.getCount(optionLocator) > 1) {
+ inputType = "select";
+ } else {
+ inputType = selenium.getAttribute(typeLocator);
+ }
+
+ if (value == null) {
+ value = "";
+ }
+
+ String valueAsString = value.toString();
+ System.out.println("\n ###setting following value as string: '" +
valueAsString + "'");
+
+ if ("text".equals(inputType)) {
+ applyText(locator, valueAsString);
+ } else if ("checkbox".equals(inputType)) {
+ boolean checked = Boolean.valueOf(valueAsString);
+ applyCheckbox(locator, checked);
+ } else if ("radio".equals(inputType)) {
+ locator = propertyLocator.format(propertyName, "[value="
+ + ("".equals(valueAsString) ? "null" : valueAsString)
+ "]");
+
+ if (!selenium.isChecked(locator)) {
+ applyRadio(locator);
+ }
+ } else if ("select".equals(inputType)) {
+ String curValue = selenium.getValue(locator);
+ if (valueAsString.equals(curValue)) {
+ return;
+ }
+ applySelect(locator, valueAsString);
+ }
+
+
selenium.getInterceptionProxy().unregisterInterceptorType(RepeatForElementNotFound.class);
+ }
+
+ protected void applyText(ElementLocator<?> locator, String value) {
+ guard(selenium, requestType).type(locator, value);
+ }
+
+ protected void applyCheckbox(ElementLocator<?> locator, boolean checked) {
+ selenium.check(locator, checked);
+ guard(selenium, requestType).fireEvent(locator, Event.CHANGE);
+ }
+
+ protected void applyRadio(ElementLocator<?> locator) {
+ guard(selenium, requestType).click(locator);
+ }
+
+ protected void applySelect(ElementLocator<?> locator, String value) {
+ OptionValueLocator optionLocator = new OptionValueLocator(value);
+ guard(selenium, requestType).select(locator, optionLocator);
+ }
+
+ private class RepeatForElementNotFound implements CommandInterceptor {
+ @Override
+ public void intercept(CommandContext ctx) throws CommandInterceptionException {
+ for (int i = 1; i <= 3; i++) {
+ try {
+ ctx.invoke();
+ break;
+ } catch (SeleniumException e) {
+ if (i == 3) {
+ throw e;
+ }
+ if (e.getMessage().matches("ERROR: Element .* not found"))
{
+ Wait.waitAjax().timeout(500).interval(100).waitForTimeout();
+ continue;
+ }
+ throw e;
+ }
+ }
+ }
+ }
+
+ public RequestType getRequestType() {
+ return requestType;
+ }
+
+ public void setRequestType(RequestType requestType) {
+ this.requestType = requestType;
+ }
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/TooltipAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/TooltipAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/TooltipAttributes.java 2011-09-05
08:48:31 UTC (rev 22677)
@@ -0,0 +1,42 @@
+package org.richfaces.tests.metamer.ftest.attributes;
+
+public enum TooltipAttributes implements AttributeEnum {
+ attached,
+ data,
+ dir,
+ direction,
+ execute,
+ followMouse,
+ hideDelay,
+ hideEvent,
+ horizontalOffset,
+ jointPoint,
+ lang,
+ layout,
+ limitRender,
+ mode,
+ onbeforedomupdate,
+ onbeforehide,
+ onbeforeshow,
+ onbegin,
+ onclick,
+ oncomplete,
+ ondblclick,
+ onhide,
+ onmousedown,
+ onmousemove,
+ onmouseout,
+ onmouseover,
+ onmouseup,
+ onshow,
+ render,
+ showDelay,
+ showEvent,
+ status,
+ style,
+ styleClass,
+ title,
+ verticalOffset,
+ zindex,
+
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/UsageTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/UsageTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/attributes/UsageTest.java 2011-09-05
08:48:31 UTC (rev 22677)
@@ -0,0 +1,42 @@
+package org.richfaces.tests.metamer.ftest.attributes;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.tooltipAttributes;
+import static org.richfaces.tests.metamer.ftest.attributes.TooltipAttributes.direction;
+import static org.richfaces.tests.metamer.ftest.attributes.TooltipAttributes.hideEvent;
+
+import java.net.URL;
+
+import org.jboss.test.selenium.geometry.Point;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.utils.URLUtils;
+import org.richfaces.component.Positioning;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.richTooltip.TooltipModel;
+import org.testng.annotations.Test;
+
+public class UsageTest extends AbstractMetamerTest {
+
+ JQueryLocator panel = pjq("div[id$=panel]");
+ TooltipModel tooltip = new TooltipModel(jq(".rf-tt"), panel);
+
+ @Test
+ public void test1() {
+ tooltipAttributes.set(direction, Positioning.auto);
+ }
+
+ @Test
+ public void testHideEvent() {
+ tooltipAttributes.set(hideEvent, "mouseup");
+
+ tooltip.recall();
+
+ selenium.mouseUpAt(panel, new Point(5, 5));
+ waitGui.until(isNotDisplayed.locator(tooltip));
+ }
+
+ @Override
+ public URL getTestUrl() {
+ return URLUtils.buildUrl(contextPath,
"faces/components/richTooltip/simple.xhtml");
+ }
+}