Author: lfryc(a)redhat.com
Date: 2011-02-15 05:41:29 -0500 (Tue, 15 Feb 2011)
New Revision: 21660
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/DelayTester.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TestTooltipSimple.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TooltipModel.java
Log:
added DelayTester helper (RFPL-1129), used in TestTooltipSimple (showDelay, hideDelay),
added issue tracking for RF-10522
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/DelayTester.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/DelayTester.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/DelayTester.java 2011-02-15
10:41:29 UTC (rev 21660)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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;
+
+import static org.jboss.test.selenium.SystemProperties.isSeleniumDebug;
+import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+import static org.testng.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.test.selenium.SystemProperties;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public abstract class DelayTester {
+
+ private static final int ITERATION_COUNT = 10;
+ private static final int ONE_PASS_MINIMUM = 250;
+
+ long actualDelay;
+ long expectedDelay;
+
+ public DelayTester(long expectedDelay) {
+ this.expectedDelay = expectedDelay;
+ }
+
+ List<Long> deviations = new ArrayList<Long>();
+
+ public abstract void action();
+
+ public void beforeTest() {
+ }
+
+ public void beforeAction() {
+ }
+
+ public void afterAction() {
+ }
+
+ public void afterTest() {
+ }
+
+ public void run() {
+ beforeTest();
+ for (int i = 0; i < ITERATION_COUNT; i++) {
+ beforeAction();
+ actualDelay = System.currentTimeMillis();
+ action();
+ actualDelay = System.currentTimeMillis() - actualDelay;
+ validateOnePass();
+ afterAction();
+ }
+ checkDeviationMedian();
+ afterTest();
+ }
+
+ protected long getMaximumSingleDeviation() {
+ return Math.max(ONE_PASS_MINIMUM, 2 * actualDelay);
+ }
+
+ protected long getMaximumDeviationMedian() {
+ return getMinMax(200, expectedDelay / 4, 500);
+ }
+
+ private void validateOnePass() {
+ long deviation = Math.abs(expectedDelay - actualDelay);
+ long maxDelay = getMaximumSingleDeviation();
+
+ if (SystemProperties.isSeleniumDebug()) {
+ System.out.println(format("deviation for preset delay {0}: {1} (delay
{2})", expectedDelay, deviation, actualDelay));
+ }
+
+ assertTrue(deviation <= maxDelay,
+ format("Deviation ({0}) is greater than defined maximum ({1})",
deviation, maxDelay));
+
+ deviations.add(deviation);
+ }
+
+ private void checkDeviationMedian() {
+ long maximumDeviationMedian = getMaximumDeviationMedian();
+ long deviationMedian = getMedian(deviations);
+ if (isSeleniumDebug()) {
+ System.out.println("deviationMedian: " + deviationMedian);
+ }
+ assertTrue(
+ deviationMedian <= maximumDeviationMedian,
+ format("Deviation median ({0}) should not be greater than defined
maximum {1}", deviationMedian,
+ maximumDeviationMedian));
+ }
+
+ private <T extends Comparable<T>> T getMedian(List<T> list) {
+ List<T> listCopy = new ArrayList<T>(list);
+ Collections.sort(listCopy);
+ return listCopy.get(listCopy.size() / 2);
+ }
+
+ protected long getMinMax(long min, long value, long max) {
+ if (value < min) {
+ return min;
+ }
+ if (value > max) {
+ return max;
+ }
+ return value;
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TestTooltipSimple.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TestTooltipSimple.java 2011-02-15
10:40:41 UTC (rev 21659)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TestTooltipSimple.java 2011-02-15
10:41:29 UTC (rev 21660)
@@ -33,10 +33,8 @@
import static org.jboss.test.selenium.dom.Event.MOUSEUP;
import static org.jboss.test.selenium.locator.LocatorFactory.jq;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
import java.net.URL;
@@ -50,6 +48,7 @@
import org.richfaces.TooltipMode;
import org.richfaces.component.Positioning;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.DelayTester;
import org.richfaces.tests.metamer.ftest.annotations.Inject;
import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
import org.richfaces.tests.metamer.ftest.annotations.Use;
@@ -138,7 +137,7 @@
super.testDir(tooltip);
}
- // ////@Test
+ @Test
@Uses({ @Use(field = "direction", enumeration = true), @Use(field =
"verticalOffset", value = "offsets"),
@Use(field = "horizontalOffset", value = "offsets") })
public void testPositioning() {
@@ -206,17 +205,16 @@
attributes.setMode(TooltipMode.ajax);
attributes.setHideDelay(presetDelay);
- tooltip.recall();
- long delay = System.currentTimeMillis();
- tooltip.hide();
- waitGui.timeout(6000).until(isNotDisplayed.locator(tooltip));
- delay = System.currentTimeMillis() - delay;
+ new DelayTester(presetDelay) {
+ public void beforeAction() {
+ tooltip.recall();
+ }
- long deviation = Math.abs(presetDelay - delay);
- long maxDeviation = Math.max(250, presetDelay / 2);
-
- assertTrue(deviation < maxDeviation,
- format("deviation '{0}' is greater than maxDeviation
'{1}'", deviation, maxDeviation));
+ public void action() {
+ tooltip.hide();
+ waitGui.timeout(presetDelay +
2000).until(isNotDisplayed.locator(tooltip));
+ }
+ }.run();
}
@Test
@@ -294,21 +292,22 @@
@Test
@Use(field = "presetDelay", ints = { 0, 1000, 5000 })
+ @IssueTracking("https://issues.jboss.org/browse/RF-10522")
public void testShowDelay() {
attributes.setMode(TooltipMode.client);
attributes.setShowDelay(presetDelay);
- long delay = System.currentTimeMillis();
- tooltip.recall();
- waitGui.timeout(6000).until(isDisplayed.locator(tooltip));
- delay = System.currentTimeMillis() - delay;
+ new DelayTester(presetDelay) {
+ public void action() {
+ tooltip.recall();
+ waitGui.timeout(presetDelay + 2000).until(isDisplayed.locator(tooltip));
+ }
- long deviation = Math.abs(presetDelay - delay);
- long maxDeviation = Math.max(200, presetDelay / 2);
-
- assertTrue(deviation < maxDeviation,
- format("deviation '{0}' is greater than maxDeviation
'{1}'", deviation, maxDeviation));
+ public void afterAction() {
+ tooltip.hide();
+ }
+ }.run();
}
@Test
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TooltipModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TooltipModel.java 2011-02-15
10:40:41 UTC (rev 21659)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTooltip/TooltipModel.java 2011-02-15
10:41:29 UTC (rev 21660)
@@ -71,6 +71,7 @@
guard(selenium, getRequestType()).mouseMoveAt(target, new Point(x, y));
} else {
guard(selenium, getRequestType()).mouseOverAt(target, new Point(x, y));
+ selenium.mouseMoveAt(target, new Point(x, y));
}
waitAjax().dontFail().interval(50).timeout(2000).until(IsDisplayed.getInstance().locator(this));
}