Author: lfryc(a)redhat.com
Date: 2010-07-10 17:09:59 -0400 (Sat, 10 Jul 2010)
New Revision: 17903
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java
Log:
fixed and refactored PollTestCase
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java 2010-07-10
21:09:34 UTC (rev 17902)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPoll/PollTestCase.java 2010-07-10
21:09:59 UTC (rev 17903)
@@ -27,23 +27,27 @@
import org.jboss.test.selenium.locator.ElementLocator;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.richfaces.tests.testapp.AbstractTestappTestCase;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.jboss.test.selenium.locator.LocatorFactory.*;
import static org.testng.Assert.*;
-import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.*;
import static org.jboss.test.selenium.SystemProperties.isSeleniumDebug;
import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
/**
+ * Tests the a4j:poll component.
+ *
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
public class PollTestCase extends AbstractTestappTestCase {
- private final static int MAX_DEVIATION = 250;
- private final static int MAX_AVERAGE_DEVIATION = 100;
+ private static final int[] TEST_INTERVAL_VALUES = new int[]{1000, 5000, 500};
+ private static final int TEST_INTERVAL_ITERATIONS = 5;
+ private static final int MAX_DEVIATION = 250;
+ private static final int MAX_AVERAGE_DEVIATION = 100;
ElementLocator attributeEnabled = id("form:attributes:enabledInput");
ElementLocator attributeInterval = id("form:attributes:intervalInput");
@@ -54,30 +58,59 @@
return buildUrl(contextPath, "faces/components/a4jPoll/simple.xhtml");
}
+ @AfterMethod(alwaysRun = true)
+ public void clearSession() {
+ invalidateSession();
+ }
+
+ /**
+ * <p>
+ * Test the progress of polling for 3 different values.
+ * </p>
+ *
+ * <p>
+ * It defines the new interval value first for each iteration and then enable
polling.
+ * </p>
+ *
+ * <p>
+ * Then, it waits for first poll event (zero iteration).
+ * </p>
+ *
+ * <p>
+ * For 5 following poll events it checks that runtime between the events haven't
greater deviation from defined
+ * interval than defined {@link #MAX_DEVIATION}.
+ * </p>
+ *
+ * <p>
+ * Test also computes average value of deviation and checks that the average value of
all obtained particular
+ * deviations isn't greater than {@link #MAX_AVERAGE_DEVIATION}.
+ * </p>
+ */
@Test(dataProvider = "templates", groups = "client-side-perf")
- public void testPollInterval(String templates) {
+ public void testInterval(String templates) {
long total = 0;
long count = 0;
- for (int interval : new Integer[]{1000, 5000, 500}) {
+ for (int interval : TEST_INTERVAL_VALUES) {
selenium.type(attributeInterval, String.valueOf(interval));
- waitHttp(selenium).fireEvent(attributeInterval, Event.BLUR);
+ selenium.waitForPageToLoad();
selenium.check(attributeEnabled);
- waitHttp(selenium).fireEvent(attributeEnabled, Event.CHANGE);
+ selenium.fireEvent(attributeEnabled, Event.CHANGE);
+ selenium.waitForPageToLoad();
selenium.getPageExtensions().install();
- for (int i = 0; i <= 5; i++) {
- long time = System.currentTimeMillis();
+ for (int i = 0; i <= TEST_INTERVAL_ITERATIONS; i++) {
+ long runtime = System.currentTimeMillis();
selenium.getRequestInterceptor().clearRequestTypeDone();
selenium.getRequestInterceptor().waitForRequestTypeChange();
- time -= System.currentTimeMillis();
+ runtime -= System.currentTimeMillis();
if (i > 0) {
if (isSeleniumDebug()) {
- System.out.println(time);
+ System.out.println(runtime);
}
- long deviation = Math.abs(interval - Math.abs(time));
+ long deviation = Math.abs(interval - Math.abs(runtime));
assertTrue(deviation <= MAX_DEVIATION, format(
"Particular deviation ({2}) for interval {0} was greater
than {1}", interval, MAX_DEVIATION,
deviation));
@@ -87,14 +120,16 @@
}
selenium.uncheck(attributeEnabled);
- guardHttp(selenium).fireEvent(attributeEnabled, Event.CHANGE);
+ selenium.fireEvent(attributeEnabled, Event.CHANGE);
+ selenium.waitForPageToLoad();
}
+
+ long averageDeviation = total / count;
if (isSeleniumDebug()) {
- System.out.println(total / count);
+ System.out.println(averageDeviation);
}
-
- long averageDeviation = (total / count);
+
assertTrue(averageDeviation <= MAX_AVERAGE_DEVIATION, format(
"Average deviation ({1}) was greater than given maximum {0}",
MAX_AVERAGE_DEVIATION, averageDeviation));
Show replies by date