[richfaces-svn-commits] JBoss Rich Faces SVN: r18576 - in modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest: a4jPush and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Wed Aug 11 17:20:08 EDT 2010


Author: lfryc at redhat.com
Date: 2010-08-11 17:20:08 -0400 (Wed, 11 Aug 2010)
New Revision: 18576

Added:
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java
Removed:
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestPoll.java
Modified:
   modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java
Log:
stabilized TestPoll (now a4jPoll/TestInterval) and refactored + refactored a4jPush/TestInterval

Copied: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java (from rev 18575, modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestPoll.java)
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java	                        (rev 0)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestInterval.java	2010-08-11 21:20:08 UTC (rev 18576)
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * 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.a4jPoll;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.commons.httpclient.HttpException;
+import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.IdLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Templates;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+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.utils.text.SimplifiedFormat.format;
+import static org.jboss.test.selenium.utils.PrimitiveUtils.*;
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.*;
+
+/**
+ * Tests the a4j:poll component.
+ * 
+ * @author <a href="mailto:lfryc at redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestInterval extends AbstractMetamerTest {
+
+    private static final int ITERATION_COUNT = 5;
+
+    @Inject
+    int interval;
+
+    IdLocator attributeEnabled = id("form:attributes:enabledInput");
+    IdLocator attributeInterval = id("form:attributes:intervalInput");
+    JQueryLocator time = pjq("span[id$=time]");
+    AttributeLocator<?> clientTime = pjq("span[id$=clientDate]").getAttribute(Attribute.TITLE);
+
+    long startTime;
+
+    long deviationTotal = 0;
+    long devicationCount = 0;
+
+    @Override
+    public URL getTestUrl() {
+        return buildUrl(contextPath, "faces/components/a4jPoll/simple.xhtml");
+    }
+
+    @Test
+    @Use(field = "interval", ints = { 1000 })
+    public void testClientAllTemplates() throws HttpException, IOException {
+        testClient();
+    }
+
+    @Test
+    @Use(field = "interval", ints = { 500, 5000 })
+    @Templates(value = "plain")
+    public void testClientDifferentIntervals() throws HttpException, IOException {
+        testClient();
+    }
+
+    /**
+     * <p>
+     * Test the progress of polling for 3 different values from client side.
+     * </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 visible from client (output from JavaScript's new
+     * Date().getTime()) 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>
+     */
+    public void testClient() {
+        guardHttp(selenium).type(attributeInterval, String.valueOf(interval));
+
+        selenium.check(attributeEnabled);
+        guardHttp(selenium).fireEvent(attributeEnabled, Event.CHANGE);
+
+        waitForPoll();
+        for (int i = 0; i < ITERATION_COUNT; i++) {
+            startInterval();
+            waitForPoll();
+            validateInterval();
+        }
+
+        validateAverageDeviation();
+    }
+
+    private void startInterval() {
+        startTime = System.currentTimeMillis();
+    }
+
+    private void waitForPoll() {
+        selenium.getPageExtensions().install();
+        selenium.getRequestInterceptor().clearRequestTypeDone();
+        selenium.getRequestInterceptor().waitForRequestTypeChange();
+    }
+
+    private void validateInterval() {
+        long runTime = getClientTime() - startTime;
+        long deviation = Math.abs(interval - runTime);
+
+        if (seleniumDebug) {
+            System.out.println(format("deviation for interval {0}: {1}", interval, deviation));
+        }
+
+        assertTrue(deviation <= interval,
+            format("Deviation ({0}) is greater than one interval {1}", deviation, interval));
+
+        deviationTotal += deviation;
+        devicationCount += 1;
+    }
+
+    private void validateAverageDeviation() {
+        long maximumAvgDeviation = Math.min(interval / 4, 1000);
+        long averageDeviation = deviationTotal / devicationCount;
+
+        if (seleniumDebug) {
+            System.out.println("averageDeviation: " + averageDeviation);
+        }
+        assertTrue(
+            averageDeviation <= maximumAvgDeviation,
+            format("Average deviation for all the intervals ({0}) should not be greater than defined maximum {1}",
+                averageDeviation, maximumAvgDeviation));
+    }
+
+    /**
+     * Returns the time of poll event (the time when arrived the response from server)
+     * 
+     * @return the time of poll event (the time when arrived the response from server)
+     */
+    private long getClientTime() {
+        return asLong(selenium.getAttribute(clientTime));
+    }
+}

Deleted: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestPoll.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestPoll.java	2010-08-11 21:19:18 UTC (rev 18575)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPoll/TestPoll.java	2010-08-11 21:20:08 UTC (rev 18576)
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * 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.a4jPoll;
-
-import java.net.URL;
-
-import org.jboss.test.selenium.dom.Event;
-import org.jboss.test.selenium.locator.Attribute;
-import org.jboss.test.selenium.locator.AttributeLocator;
-import org.jboss.test.selenium.locator.IdLocator;
-import org.jboss.test.selenium.locator.JQueryLocator;
-import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
-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.SystemProperties.isSeleniumDebug;
-import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
-import static org.jboss.test.selenium.utils.PrimitiveUtils.*;
-
-/**
- * Tests the a4j:poll component.
- * 
- * @author <a href="mailto:lfryc at redhat.com">Lukas Fryc</a>
- * @version $Revision$
- */
-public class TestPoll extends AbstractMetamerTest {
-
-    private static final Attribute ATTRIBUTE_TITLE = new Attribute("title");
-    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 = 100;
-    private static final int MAX_AVERAGE_DEVIATION = 50;
-
-    IdLocator attributeEnabled = id("form:attributes:enabledInput");
-    IdLocator attributeInterval = id("form:attributes:intervalInput");
-    JQueryLocator time = pjq("span[id$=time]");
-    AttributeLocator<?> clientTime = pjq("span[id$=clientDate]").getAttribute(ATTRIBUTE_TITLE);
-
-    @Override
-    public URL getTestUrl() {
-        return buildUrl(contextPath, "faces/components/a4jPoll/simple.xhtml");
-    }
-
-    /**
-     * <p>
-     * Test the progress of polling for 3 different values from client side.
-     * </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 visible from client (output from JavaScript's new
-     * Date().getTime()) 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(groups = "client-side-perf")
-    public void testIntervalFromClientPerspective() {
-
-        long total = 0;
-        long count = 0;
-        for (int interval : TEST_INTERVAL_VALUES) {
-            selenium.type(attributeInterval, String.valueOf(interval));
-            selenium.waitForPageToLoad();
-
-            selenium.check(attributeEnabled);
-            selenium.fireEvent(attributeEnabled, Event.CHANGE);
-            selenium.waitForPageToLoad();
-
-            selenium.getPageExtensions().install();
-
-            long currentTime = getClientTime();
-
-            for (int i = 0; i <= TEST_INTERVAL_ITERATIONS; i++) {
-                long runtime = System.currentTimeMillis();
-                selenium.getRequestInterceptor().clearRequestTypeDone();
-                selenium.getRequestInterceptor().waitForRequestTypeChange();
-                runtime -= getClientTime();
-                if (i > 0) {
-
-                    long deviation = Math.abs(interval - Math.abs(runtime));
-                    if (isSeleniumDebug()) {
-                        System.out.println(format("deviation for interval {0}: {1}", interval, deviation));
-                    }
-                    assertTrue(deviation <= MAX_DEVIATION, format(
-                        "Particular deviation ({2}) for interval {0} was greater than {1}", interval, MAX_DEVIATION,
-                        deviation));
-                    total += deviation;
-                    count += 1;
-                }
-                currentTime += runtime;
-            }
-
-            selenium.uncheck(attributeEnabled);
-            selenium.fireEvent(attributeEnabled, Event.CHANGE);
-            selenium.waitForPageToLoad();
-        }
-
-        long averageDeviation = total / count;
-
-        if (isSeleniumDebug()) {
-            System.out.println(format("total average deviation: {0}", averageDeviation));
-        }
-
-        assertTrue(averageDeviation <= MAX_AVERAGE_DEVIATION, format(
-            "Average deviation ({1}) was greater than given maximum {0}", MAX_AVERAGE_DEVIATION, averageDeviation));
-    }
-
-    /**
-     * Returns the time of poll event (the time when arrived the response from server)
-     * @return the time of poll event (the time when arrived the response from server)
-     */
-    private long getClientTime() {
-        return asLong(selenium.getAttribute(clientTime));
-    }
-
-}

Modified: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java
===================================================================
--- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java	2010-08-11 21:19:18 UTC (rev 18575)
+++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java	2010-08-11 21:20:08 UTC (rev 18576)
@@ -43,23 +43,22 @@
  * @version $Revision$
  */
 public class TestInterval extends AbstractPushTest {
-
-    private static final Attribute ATTRIBUTE_TITLE = new Attribute("title");
+    
     private static final int DEFAULT_COUNTER_STEP = 2;
     private static final int ITERATION_COUNT = 3;
     private static final int MULTIPLE_PUSH_COUNT = 5;
 
-    AttributeLocator<?> clientTime = pjq("span[id$=clientDate]").getAttribute(ATTRIBUTE_TITLE);
+    @Inject
+    int interval;
 
-    private long startTime;
-    private int counter;
-    private int counterStep;
+    AttributeLocator<?> clientTime = pjq("span[id$=clientDate]").getAttribute(Attribute.TITLE);
 
-    private long deviationTotal = 0;
-    private long deviationCount = 0;
+    long startTime;
+    int counter;
+    int counterStep;
 
-    @Inject
-    private int interval;
+    long deviationTotal = 0;
+    long deviationCount = 0;
 
     /**
      * <p>
@@ -82,21 +81,7 @@
     @Test
     @Use(field = "interval", ints = { 1000 })
     public void testClientAllTemplates() throws HttpException, IOException {
-        counterStep = DEFAULT_COUNTER_STEP;
-        pushAttributes.setInterval(interval);
-
-        pushAndWait(1);
-        for (int i = 0; i < ITERATION_COUNT; i++) {
-            startIntervalAndCounter();
-            pushAndWait(1);
-            validateIntervalAndCounter(interval);
-
-            startIntervalAndCounter();
-            pushAndWait(MULTIPLE_PUSH_COUNT);
-            validateIntervalAndCounter(interval);
-        }
-
-        validateAverageDeviation();
+        testClient();
     }
 
     /**
@@ -121,6 +106,10 @@
     @Use(field = "interval", ints = { 500, 5000 })
     @Templates(value = "plain")
     public void testClientDifferentIntervals() throws HttpException, IOException {
+        testClient();
+    }
+
+    private void testClient() throws HttpException, IOException {
         counterStep = DEFAULT_COUNTER_STEP;
         pushAttributes.setInterval(interval);
 
@@ -128,11 +117,11 @@
         for (int i = 0; i < ITERATION_COUNT; i++) {
             startIntervalAndCounter();
             pushAndWait(1);
-            validateIntervalAndCounter(interval);
+            validateIntervalAndCounter();
 
             startIntervalAndCounter();
             pushAndWait(MULTIPLE_PUSH_COUNT);
-            validateIntervalAndCounter(interval);
+            validateIntervalAndCounter();
         }
 
         validateAverageDeviation();
@@ -163,7 +152,7 @@
      * Validates that counter have been increased by right value.
      * </p>
      */
-    private void validateIntervalAndCounter(int interval) {
+    private void validateIntervalAndCounter() {
         long runTime = getClientTime() - startTime;
         long deviation = Math.abs(interval - runTime);
 



More information about the richfaces-svn-commits mailing list