Author: lfryc(a)redhat.com
Date: 2010-07-10 17:13:59 -0400 (Sat, 10 Jul 2010)
New Revision: 17911
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/AbstractPushTestCase.java
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/IntervalTestCase.java
Log:
testing a4j:poll from client perspective (the client time of observation the event)
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/AbstractPushTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/AbstractPushTestCase.java 2010-07-10
21:12:49 UTC (rev 17910)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/AbstractPushTestCase.java 2010-07-10
21:13:59 UTC (rev 17911)
@@ -68,7 +68,7 @@
public void initializeHttpClient() {
httpClient = new HttpClient();
URL eventProducerUrl = buildUrl(getTestUrl(), "event-producer.xhtml");
- pushMethod = new GetMethod(eventProducerUrl.toString() +
"?pushEnabled=true");
+ pushMethod = new GetMethod(eventProducerUrl.toString());
}
/**
Modified:
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/IntervalTestCase.java
===================================================================
---
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/IntervalTestCase.java 2010-07-10
21:12:49 UTC (rev 17910)
+++
root/tests/metamer/trunk/ftest/test-source/src/main/java/org/richfaces/tests/testapp/a4jPush/IntervalTestCase.java 2010-07-10
21:13:59 UTC (rev 17911)
@@ -21,7 +21,7 @@
*******************************************************************************/
package org.richfaces.tests.testapp.a4jPush;
-import static java.lang.System.currentTimeMillis;
+import static org.jboss.test.selenium.utils.PrimitiveUtils.asLong;
import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -29,6 +29,8 @@
import java.io.IOException;
import org.apache.commons.httpclient.HttpException;
+import org.jboss.test.selenium.locator.Attribute;
+import org.jboss.test.selenium.locator.AttributeLocator;
import org.testng.annotations.Test;
/**
@@ -39,13 +41,16 @@
*/
public class IntervalTestCase extends AbstractPushTestCase {
+ private static final Attribute ATTRIBUTE_TITLE = new Attribute("title");
private static final int[] INTERVAL_VALUES = new int[]{1000, 5000, 500};
- private static final long MAX_DEVIATION = 300;
- private static final long MAX_AVERAGE_DEVIATION = 100;
+ private static final long MAX_DEVIATION = 100;
+ private static final long MAX_AVERAGE_DEVIATION = 75;
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);
+
private long startTime;
private int counter;
private int counterStep;
@@ -72,7 +77,7 @@
* </p>
*/
@Test
- public void testInterval() throws HttpException, IOException {
+ public void testIntervalFromClientPerspective() throws HttpException, IOException {
for (int interval : INTERVAL_VALUES) {
counterStep = DEFAULT_COUNTER_STEP;
pushAttributes.setInterval(interval);
@@ -96,7 +101,7 @@
* Remembers start of the time frame and current value of counter.
*/
private void startIntervalAndCounter() {
- startTime = currentTimeMillis();
+ startTime = getClientTime();
counter = getCounter();
}
@@ -118,13 +123,13 @@
* </p>
*/
private void validateIntervalAndCounter(int interval) {
- long runTime = currentTimeMillis() - startTime;
+ long runTime = getClientTime() - startTime;
long deviation = Math.abs(interval - runTime);
assertTrue(deviation <= MAX_DEVIATION, format("Deviation ({0}) is greater
than defined maximum {1}", deviation,
MAX_DEVIATION));
if (seleniumDebug) {
- System.out.println("deviation: " + deviation);
+ System.out.println(format("deviation for interval {0}: {1}",
interval, deviation));
}
deviationTotal += deviation;
@@ -148,4 +153,13 @@
"Average deviation for all the intervals ({0}) should not be greater
than defined maximum {1}",
averageDeviation, MAX_AVERAGE_DEVIATION));
}
+
+ /**
+ * Returns the time of push event (the time when arrived the response from server)
+ *
+ * @return the time of push event (the time when arrived the response from server)
+ */
+ private long getClientTime() {
+ return asLong(selenium.getAttribute(clientTime));
+ }
}