Author: lfryc(a)redhat.com
Date: 2010-09-14 09:24:47 -0400 (Tue, 14 Sep 2010)
New Revision: 19192
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestFormQueue.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestGlobalQueue.java
Log:
a4j:queue tests refactored to introduce QueueModel (replaced QueueLocators) to easy reuse
in other tests (RFPL-733)
Copied:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java
(from rev 19188,
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueLocators.java)
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java 2010-09-14
13:24:47 UTC (rev 19192)
@@ -0,0 +1,172 @@
+package org.richfaces.tests.metamer.ftest.a4jQueue;
+
+import static org.jboss.cheiron.retriever.RetrieverAdapter.integerAdapter;
+import static org.jboss.cheiron.retriever.RetrieverAdapter.longAdapter;
+import static org.jboss.test.selenium.SystemProperties.isSeleniumDebug;
+import static org.jboss.test.selenium.dom.Event.KEYPRESS;
+import static org.jboss.test.selenium.locator.Attribute.TITLE;
+import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
+import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
+import static
org.jboss.test.selenium.waiting.retrievers.RetrieverFactory.RETRIEVE_ATTRIBUTE;
+import static org.jboss.test.selenium.waiting.retrievers.RetrieverFactory.RETRIEVE_TEXT;
+import static org.richfaces.tests.metamer.ftest.AbstractMetamerTest.pjq;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.jboss.test.selenium.waiting.WaitFactory.waitAjax;
+
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.reference.LocatorReference;
+import org.jboss.test.selenium.locator.reference.ReferencedLocator;
+import org.jboss.test.selenium.waiting.retrievers.Retriever;
+
+public class QueueModel {
+
+ private AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ private Boolean event2Present = null;
+
+ int deviationTotal;
+ int deviationCount;
+
+ LocatorReference<JQueryLocator> form = new
LocatorReference<JQueryLocator>(null);
+
+ ReferencedLocator<JQueryLocator> input1 = ref(form,
"input:text[id$=input1]");
+ ReferencedLocator<JQueryLocator> input2 = ref(form,
"input:text[id$=input2]");
+
+ ElementLocator<?> events1 = ref(form, "span[id$=events1]");
+ ElementLocator<?> events2 = ref(form, "span[id$=events2]");
+ ElementLocator<?> requests = ref(form, "span[id$=requests]");
+ ElementLocator<?> updates = ref(form, "span[id$=updates]");
+
+ AttributeLocator<?> event1Time = ref(form,
"span[id$=eventTime1\\:outputTime]").getAttribute(TITLE);
+ AttributeLocator<?> event2Time = ref(form,
"span[id$=eventTime2\\:outputTime]").getAttribute(TITLE);
+ AttributeLocator<?> beginTime = ref(form,
"span[id$=beginTime\\:outputTime]").getAttribute(TITLE);
+ AttributeLocator<?> completeTime = ref(form,
"span[id$=completeTime\\:outputTime]").getAttribute(TITLE);
+
+ Retriever<Integer> retrieveEvent1Count =
integerAdapter(RETRIEVE_TEXT.locator(events1));
+ Retriever<Integer> retrieveEvent2Count =
integerAdapter(RETRIEVE_TEXT.locator(events2));
+ Retriever<Integer> retrieveRequestCount =
integerAdapter(RETRIEVE_TEXT.locator(requests));
+ Retriever<Integer> retrieveDOMUpdateCount =
integerAdapter(RETRIEVE_TEXT.locator(updates));
+
+ Retriever<Long> retrieveEvent1Time =
longAdapter(RETRIEVE_ATTRIBUTE.attributeLocator(event1Time));
+ Retriever<Long> retrieveEvent2Time =
longAdapter(RETRIEVE_ATTRIBUTE.attributeLocator(event2Time));
+ Retriever<Long> retrieveBeginTime =
longAdapter(RETRIEVE_ATTRIBUTE.attributeLocator(beginTime));
+ Retriever<Long> retrieveCompleteTime =
longAdapter(RETRIEVE_ATTRIBUTE.attributeLocator(completeTime));
+
+ public QueueModel() {
+ this(pjq(""));
+ }
+
+ public QueueModel(JQueryLocator queueRoot) {
+ form.setLocator(queueRoot);
+ }
+
+ private boolean isEvent2Present() {
+ if (event2Present == null) {
+ event2Present = selenium.isElementPresent(input2);
+ assertEquals((boolean) event2Present,
selenium.isElementPresent(event2Time.getAssociatedElement()));
+ }
+ return event2Present;
+ }
+
+ public void fireEvent(int countOfEvents) {
+ fireEvent(Input.FIRST, countOfEvents);
+ }
+
+ public void fireEvent(Input event, int countOfEvents) {
+ ElementLocator<?> input = (event == Input.FIRST) ? input1 : input2;
+ for (int i = 0; i < countOfEvents; i++) {
+ selenium.fireEvent(input, KEYPRESS);
+ }
+ }
+
+ public void initializeCounts() {
+ retrieveEvent1Count.initializeValue();
+ retrieveRequestCount.initializeValue();
+ retrieveDOMUpdateCount.initializeValue();
+ if (isEvent2Present()) {
+ retrieveEvent2Count.initializeValue();
+ }
+ }
+
+ public void checkCounts(int events1, int requests, int domUpdates) {
+ assertChangeIfNotEqualToOldValue(retrieveEvent1Count, events1,
"event1Count");
+ assertChangeIfNotEqualToOldValue(retrieveRequestCount, requests,
"requestCount");
+ assertChangeIfNotEqualToOldValue(retrieveDOMUpdateCount, domUpdates,
"domUpdates");
+ }
+
+ public void checkCounts(int events1, int events2, int requests, int domUpdates) {
+ assertChangeIfNotEqualToOldValue(retrieveEvent1Count, events1,
"event1Count");
+
+ assertChangeIfNotEqualToOldValue(retrieveRequestCount, requests,
"requestCount");
+ assertChangeIfNotEqualToOldValue(retrieveDOMUpdateCount, domUpdates,
"domUpdates");
+ if (isEvent2Present()) {
+ assertChangeIfNotEqualToOldValue(retrieveEvent2Count, events2,
"event2Count");
+ }
+ }
+
+ private void assertChangeIfNotEqualToOldValue(Retriever<Integer> retrieveCount,
Integer eventCount, String eventType) {
+ if (!eventCount.equals(retrieveCount.getValue())) {
+
assertEquals(waitAjax.failWith(eventType).waitForChangeAndReturn(retrieveCount),
eventCount);
+ } else {
+ assertEquals(retrieveCount.retrieve(), eventCount);
+ }
+ }
+
+ public void initializeTimes() {
+ deviationTotal = 0;
+ deviationCount = 0;
+ retrieveEvent1Time.initializeValue();
+ retrieveBeginTime.initializeValue();
+ retrieveCompleteTime.initializeValue();
+ if (isEvent2Present()) {
+ retrieveEvent2Time.initializeValue();
+ }
+ }
+
+ public void checkTimes(long requestDelay) {
+ checkTimes(Input.FIRST, requestDelay);
+ }
+
+ public void checkTimes(Input event, long requestDelay) {
+ Retriever<Long> retrieveEventTime = (event == Input.FIRST) ?
retrieveEvent1Time : retrieveEvent2Time;
+ long eventTime = waitAjax.waitForChangeAndReturn(retrieveEventTime);
+ long beginTime = waitAjax.waitForChangeAndReturn(retrieveBeginTime);
+ long actualDelay = beginTime - eventTime;
+ long deviation = Math.abs(actualDelay - requestDelay);
+ long maxDeviation = Math.max(100, requestDelay);
+
+ if (isSeleniumDebug()) {
+ System.out.println(format("deviation for requestDelay {0}: {1}",
requestDelay, deviation));
+ }
+
+ assertTrue(
+ deviation <= maxDeviation,
+ format("Deviation ({0}) is greater than maxDeviation ({1}) for
requestDelay {2}", deviation, maxDeviation,
+ requestDelay));
+
+ deviationTotal += deviation;
+ deviationCount += 1;
+ }
+
+ public void checkAvgDeviation(long requestDelay) {
+ long maximumAvgDeviation = Math.max(25, Math.min(50, requestDelay / 4));
+ long averageDeviation = deviationTotal / deviationCount;
+ if (isSeleniumDebug()) {
+ System.out.println("averageDeviation: " + averageDeviation);
+ }
+ assertTrue(
+ averageDeviation <= maximumAvgDeviation,
+ format(
+ "Average deviation for all tests of requestDelay ({0}) should not be
greater than defined maximum {1}",
+ averageDeviation, maximumAvgDeviation));
+ }
+
+ public static enum Input {
+ FIRST, SECOND;
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestFormQueue.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestFormQueue.java 2010-09-14
11:19:55 UTC (rev 19191)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestFormQueue.java 2010-09-14
13:24:47 UTC (rev 19192)
@@ -21,19 +21,14 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.a4jQueue;
-import static org.jboss.test.selenium.dom.Event.KEYPRESS;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
-import static org.richfaces.tests.metamer.ftest.AbstractMetamerTest.pjq;
-import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URL;
import org.jboss.cheiron.halt.XHRHalter;
-import org.jboss.test.selenium.locator.ElementLocator;
-import org.jboss.test.selenium.waiting.retrievers.Retriever;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.a4jQueue.QueueModel.Input;
import org.testng.annotations.Test;
/**
@@ -46,18 +41,22 @@
static final Long DELAY_A = 3000L;
static final Long DELAY_B = 5000L;
- int deviationTotal;
- int deviationCount;
+ QueueModel queueA = prepareLocators("formQueue1");
+ QueueModel queueB = prepareLocators("formQueue2");
+ QueueModel globalQueue = prepareLocators("globalQueue");
- QueueLocators formQueueA = prepareLocators("formQueue1");
- QueueLocators formQueueB = prepareLocators("formQueue2");
- QueueLocators globalQueue = prepareLocators("globalQueue");
+ QueueAttributes attributesQueueA = prepareAttributes("formQueue1");
+ QueueAttributes attributesQueueB = prepareAttributes("formQueue2");
+ QueueAttributes attributesGlobalQueue = prepareAttributes("globalQueue");
- private static QueueLocators prepareLocators(String identifier) {
- return new QueueLocators(identifier,
pjq("div.rf-p[id$={0}Panel]").format(identifier), pjq(
- "div.rf-p[id$={0}AttributesPanel]").format(identifier));
+ private static QueueModel prepareLocators(String identifier) {
+ return new
QueueModel(pjq("div.rf-p[id$={0}Panel]").format(identifier));
}
+ private static QueueAttributes prepareAttributes(String identifier) {
+ return new
QueueAttributes(pjq("div.rf-p[id$={0}AttributesPanel]").format(identifier));
+ }
+
@Override
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/a4jQueue/formQueue.xhtml");
@@ -78,22 +77,22 @@
*/
@Test
public void testTimingOneQueueTwoEvents() {
- formQueueA.attributes.setRequestDelay(DELAY_A);
- globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+ attributesQueueA.setRequestDelay(DELAY_A);
+ attributesGlobalQueue.setRequestDelay(GLOBAL_DELAY);
- initializeTimes(formQueueA);
+ queueA.initializeTimes();
XHRHalter.enable();
- fireEvent(formQueueA, Event.FIRST, 2);
- fireEvent(formQueueA, Event.SECOND, 3);
+ queueA.fireEvent(Input.FIRST, 2);
+ queueA.fireEvent(Input.SECOND, 3);
XHRHalter halter = XHRHalter.getHandleBlocking();
halter.complete();
halter.waitForOpen();
halter.complete();
- checkTimes(formQueueA, Event.SECOND, DELAY_A);
+ queueA.checkTimes(Input.SECOND, DELAY_A);
}
/**
@@ -111,26 +110,26 @@
*/
@Test
public void testCountsOneQueueTwoEvents() {
- formQueueA.attributes.setRequestDelay(DELAY_A);
- globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+ attributesQueueA.setRequestDelay(DELAY_A);
+ attributesGlobalQueue.setRequestDelay(GLOBAL_DELAY);
- initializeCounts(formQueueA);
+ queueA.initializeCounts();
XHRHalter.enable();
- fireEvent(formQueueA, Event.FIRST, 2);
- checkCounts(formQueueA, 2, 0, 0, 0);
- fireEvent(formQueueA, Event.SECOND, 3);
- checkCounts(formQueueA, 2, 3, 1, 0);
+ queueA.fireEvent(Input.FIRST, 2);
+ queueA.checkCounts(2, 0, 0, 0);
+ queueA.fireEvent(Input.SECOND, 3);
+ queueA.checkCounts(2, 3, 1, 0);
XHRHalter halter = XHRHalter.getHandleBlocking();
- checkCounts(formQueueA, 2, 3, 1, 0);
+ queueA.checkCounts(2, 3, 1, 0);
halter.complete();
- checkCounts(formQueueA, 2, 3, 2, 1);
+ queueA.checkCounts(2, 3, 2, 1);
halter.waitForOpen();
- checkCounts(formQueueA, 2, 3, 2, 1);
+ queueA.checkCounts(2, 3, 2, 1);
halter.complete();
- checkCounts(formQueueA, 2, 3, 2, 2);
+ queueA.checkCounts(2, 3, 2, 2);
}
/**
@@ -149,19 +148,19 @@
*/
@Test
public void testTimingTwoQueuesFourEvents() {
- formQueueA.attributes.setRequestDelay(DELAY_A);
- formQueueB.attributes.setRequestDelay(DELAY_B);
- globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+ attributesQueueA.setRequestDelay(DELAY_A);
+ attributesQueueB.setRequestDelay(DELAY_B);
+ attributesGlobalQueue.setRequestDelay(GLOBAL_DELAY);
- initializeTimes(formQueueA);
- initializeTimes(formQueueB);
+ queueA.initializeTimes();
+ queueB.initializeTimes();
XHRHalter.enable();
- fireEvent(formQueueA, Event.FIRST, 1);
- fireEvent(formQueueA, Event.SECOND, 1);
- fireEvent(formQueueB, Event.FIRST, 1);
- fireEvent(formQueueB, Event.SECOND, 1);
+ queueA.fireEvent(Input.FIRST, 1);
+ queueA.fireEvent(Input.SECOND, 1);
+ queueB.fireEvent(Input.FIRST, 1);
+ queueB.fireEvent(Input.SECOND, 1);
XHRHalter halter = XHRHalter.getHandleBlocking();
halter.complete();
@@ -172,11 +171,11 @@
halter.waitForOpen();
halter.complete();
- checkTimes(formQueueB, Event.SECOND, DELAY_B);
+ queueB.checkTimes(Input.SECOND, DELAY_B);
- assertTrue(formQueueA.retrieveBeginTime.retrieve() -
formQueueA.retrieveEvent1Time.retrieve() < 1000);
- assertTrue(formQueueA.retrieveBeginTime.retrieve() -
formQueueA.retrieveEvent2Time.retrieve() < 1000);
- assertTrue(formQueueB.retrieveBeginTime.retrieve() -
formQueueB.retrieveEvent1Time.retrieve() > 3000);
+ assertTrue(queueA.retrieveBeginTime.retrieve() -
queueA.retrieveEvent1Time.retrieve() < 1000);
+ assertTrue(queueA.retrieveBeginTime.retrieve() -
queueA.retrieveEvent2Time.retrieve() < 1000);
+ assertTrue(queueB.retrieveBeginTime.retrieve() -
queueB.retrieveEvent1Time.retrieve() > 3000);
}
/**
@@ -194,104 +193,41 @@
*/
@Test
public void testCountsTwoQueuesThreeEvents() {
- formQueueA.attributes.setRequestDelay(DELAY_A);
- formQueueB.attributes.setRequestDelay(DELAY_B);
- globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+ attributesQueueA.setRequestDelay(DELAY_A);
+ attributesQueueB.setRequestDelay(DELAY_B);
+ attributesGlobalQueue.setRequestDelay(GLOBAL_DELAY);
- initializeCounts(formQueueA);
- initializeCounts(formQueueB);
+ queueA.initializeCounts();
+ queueB.initializeCounts();
XHRHalter.enable();
- fireEvent(formQueueA, Event.FIRST, 1);
- checkCounts(formQueueA, 1, 0, 0, 0);
- fireEvent(formQueueA, Event.SECOND, 1);
- checkCounts(formQueueA, 1, 1, 1, 0);
- fireEvent(formQueueB, Event.FIRST, 1);
- checkCounts(formQueueB, 1, 0, 0, 0);
- fireEvent(formQueueB, Event.SECOND, 1);
+ queueA.fireEvent(Input.FIRST, 1);
+ queueA.checkCounts(1, 0, 0, 0);
+ queueA.fireEvent(Input.SECOND, 1);
+ queueA.checkCounts(1, 1, 1, 0);
+ queueB.fireEvent(Input.FIRST, 1);
+ queueB.checkCounts(1, 0, 0, 0);
+ queueB.fireEvent(Input.SECOND, 1);
- checkCounts(formQueueA, 1, 1, 1, 0);
- checkCounts(formQueueB, 1, 1, 0, 0);
+ queueA.checkCounts(1, 1, 1, 0);
+ queueB.checkCounts(1, 1, 0, 0);
XHRHalter halter = XHRHalter.getHandleBlocking();
halter.complete();
- checkCounts(formQueueA, 1, 1, 2, 1);
+ queueA.checkCounts(1, 1, 2, 1);
halter.waitForOpen();
halter.complete();
- checkCounts(formQueueA, 1, 1, 2, 2);
- checkCounts(formQueueB, 1, 1, 1, 0);
+ queueA.checkCounts(1, 1, 2, 2);
+ queueB.checkCounts(1, 1, 1, 0);
halter.waitForOpen();
halter.complete();
halter.waitForOpen();
- checkCounts(formQueueB, 1, 1, 2, 1);
+ queueB.checkCounts(1, 1, 2, 1);
halter.complete();
- checkCounts(formQueueA, 1, 1, 2, 2);
- checkCounts(formQueueB, 1, 1, 2, 2);
+ queueA.checkCounts(1, 1, 2, 2);
+ queueB.checkCounts(1, 1, 2, 2);
}
- private void initializeTimes(QueueLocators formQueueLocators) {
- deviationTotal = 0;
- deviationCount = 0;
- formQueueLocators.retrieveEvent1Time.initializeValue();
- formQueueLocators.retrieveEvent2Time.initializeValue();
- formQueueLocators.retrieveBeginTime.initializeValue();
- formQueueLocators.retrieveCompleteTime.initializeValue();
- }
-
- private void fireEvent(QueueLocators formQueueLocators, Event event, int
countOfEvents) {
- ElementLocator<?> input = (event == Event.FIRST) ? formQueueLocators.input1
: formQueueLocators.input2;
- for (int i = 0; i < countOfEvents; i++) {
- selenium.fireEvent(input, KEYPRESS);
- }
- }
-
- private void initializeCounts(QueueLocators formQueueLocators) {
- formQueueLocators.retrieveEvent1Count.initializeValue();
- formQueueLocators.retrieveEvent2Count.initializeValue();
- formQueueLocators.retrieveRequestCount.initializeValue();
- formQueueLocators.retrieveDOMUpdateCount.initializeValue();
- }
-
- private void checkCounts(QueueLocators formQueueLocators, int events1, int events2,
int requests, int domUpdates) {
- assertChangeIfNotEqualToOldValue(formQueueLocators.retrieveEvent1Count, events1,
"event1Count");
- assertChangeIfNotEqualToOldValue(formQueueLocators.retrieveEvent2Count, events2,
"event2Count");
- assertChangeIfNotEqualToOldValue(formQueueLocators.retrieveRequestCount,
requests, "requestCount");
- assertChangeIfNotEqualToOldValue(formQueueLocators.retrieveDOMUpdateCount,
domUpdates, "domUpdates");
- }
-
- private void assertChangeIfNotEqualToOldValue(Retriever<Integer> retrieveCount,
Integer eventCount, String eventType) {
- if (!eventCount.equals(retrieveCount.getValue())) {
-
assertEquals(waitAjax.failWith(eventType).waitForChangeAndReturn(retrieveCount),
eventCount);
- } else {
- assertEquals(retrieveCount.retrieve(), eventCount);
- }
- }
-
- private void checkTimes(QueueLocators formQueueLocators, Event event, long
requestDelay) {
- Retriever<Long> retrieveEventTime = (event == Event.FIRST) ?
formQueueLocators.retrieveEvent1Time
- : formQueueLocators.retrieveEvent2Time;
- long eventTime = waitAjax.waitForChangeAndReturn(retrieveEventTime);
- long beginTime =
waitAjax.waitForChangeAndReturn(formQueueLocators.retrieveBeginTime);
- long actualDelay = beginTime - eventTime;
- long deviation = Math.abs(actualDelay - requestDelay);
- long maxDeviation = Math.max(100, requestDelay);
-
- if (seleniumDebug) {
- System.out.println(format("deviation for requestDelay {0}: {1}",
requestDelay, deviation));
- }
-
- assertTrue(
- deviation <= maxDeviation,
- format("Deviation ({0}) is greater than maxDeviation ({1}) for
requestDelay {2}", deviation, maxDeviation,
- requestDelay));
-
- deviationTotal += deviation;
- deviationCount += 1;
- }
-
- private enum Event {
- FIRST, SECOND;
- }
}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestGlobalQueue.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestGlobalQueue.java 2010-09-14
11:19:55 UTC (rev 19191)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestGlobalQueue.java 2010-09-14
13:24:47 UTC (rev 19192)
@@ -21,17 +21,12 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.a4jQueue;
-import static org.jboss.test.selenium.dom.Event.KEYPRESS;
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.assertTrue;
import java.net.URL;
import org.jboss.cheiron.halt.XHRHalter;
import org.jboss.cheiron.halt.XHRState;
-import org.jboss.test.selenium.waiting.retrievers.Retriever;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.richfaces.tests.metamer.ftest.annotations.Inject;
import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
@@ -44,17 +39,13 @@
*/
public class TestGlobalQueue extends AbstractMetamerTest {
- QueueLocators queue = new QueueLocators("globalQueue", pjq(""),
pjq("#attributeForm"));
-
+ QueueModel queue = new QueueModel();
QueueAttributes attributes = new QueueAttributes();
@Inject
@Use(empty = false)
Integer requestDelay;
- int deviationTotal;
- int deviationCount;
-
@Override
public URL getTestUrl() {
return buildUrl(contextPath,
"faces/components/a4jQueue/globalQueue.xhtml");
@@ -68,12 +59,14 @@
public void testRequestDelay() {
attributes.setRequestDelay(requestDelay);
- initializeTimes();
+ queue.initializeTimes();
+
for (int i = 0; i < 5; i++) {
- fireEvents(1);
- checkTimes();
+ queue.fireEvent(1);
+ queue.checkTimes(requestDelay);
}
- checkAvgDeviation();
+
+ queue.checkAvgDeviation(requestDelay);
}
/**
@@ -83,23 +76,23 @@
public void testMultipleRequestsWithDelay() {
attributes.setRequestDelay(3000);
- initializeCounts();
+ queue.initializeCounts();
XHRHalter.enable();
- fireEvents(4);
+ queue.fireEvent(4);
XHRHalter handle = XHRHalter.getHandleBlocking();
handle.send();
handle.complete();
- checkCounts(4, 1, 1);
+ queue.checkCounts(4, 1, 1);
- fireEvents(3);
+ queue.fireEvent(3);
handle.waitForOpen();
handle.send();
handle.complete();
- checkCounts(7, 2, 2);
+ queue.checkCounts(7, 2, 2);
XHRHalter.disable();
}
@@ -117,59 +110,59 @@
public void testMultipleRequestsWithNoDelay() {
attributes.setRequestDelay(0);
- initializeCounts();
+ queue.initializeCounts();
XHRHalter.enable();
- fireEvents(1);
- checkCounts(1, 1, 0);
+ queue.fireEvent(1);
+ queue.checkCounts(1, 1, 0);
XHRHalter handle = XHRHalter.getHandleBlocking();
handle.send();
- fireEvents(1);
- checkCounts(2, 1, 0);
+ queue.fireEvent(1);
+ queue.checkCounts(2, 1, 0);
handle.complete();
- checkCounts(2, 2, 1);
+ queue.checkCounts(2, 2, 1);
handle.waitForOpen();
handle.send();
- fireEvents(4);
- checkCounts(6, 2, 1);
+ queue.fireEvent(4);
+ queue.checkCounts(6, 2, 1);
handle.complete();
- checkCounts(6, 3, 2);
+ queue.checkCounts(6, 3, 2);
handle.waitForOpen();
handle.send();
- fireEvents(1);
- checkCounts(7, 3, 2);
+ queue.fireEvent(1);
+ queue.checkCounts(7, 3, 2);
handle.complete();
- checkCounts(7, 4, 3);
+ queue.checkCounts(7, 4, 3);
handle.waitForOpen();
handle.send();
- checkCounts(7, 4, 3);
+ queue.checkCounts(7, 4, 3);
handle.complete();
- checkCounts(7, 4, 4);
+ queue.checkCounts(7, 4, 4);
XHRHalter.disable();
}
-
+
@Test
@IssueTracking("https://jira.jboss.org/browse/RF-9328")
public void testRendered() {
attributes.setRequestDelay(1500);
attributes.setRendered(false);
-
- initializeTimes();
- fireEvents(1);
-
+
+ queue.initializeTimes();
+ queue.fireEvent(1);
+
// check that no requestDelay is applied while renderer=false
- checkTimes(0);
+ queue.checkTimes(0);
// TODO should check that no attributes is applied with renderes=false
}
@@ -180,10 +173,10 @@
XHRHalter.enable();
- fireEvents(1);
+ queue.fireEvent(1);
XHRHalter handle = XHRHalter.getHandleBlocking();
handle.continueBefore(XHRState.COMPLETE);
- fireEvents(10);
+ queue.fireEvent(10);
XHRHalter.disable();
@@ -196,82 +189,11 @@
attributes.setIgnoreDupResponses(true);
XHRHalter.enable();
- fireEvents(1);
+ queue.fireEvent(1);
XHRHalter handle = XHRHalter.getHandleBlocking();
handle.send();
- fireEvents(1);
+ queue.fireEvent(1);
handle.complete();
handle.waitForOpen();
}
-
- private void initializeTimes() {
- deviationTotal = 0;
- deviationCount = 0;
- queue.retrieveEvent1Time.initializeValue();
- queue.retrieveBeginTime.initializeValue();
- queue.retrieveCompleteTime.initializeValue();
- }
-
- private void fireEvents(int countOfEvents) {
- for (int i = 0; i < countOfEvents; i++) {
- selenium.fireEvent(queue.input1, KEYPRESS);
- }
- }
-
- private void initializeCounts() {
- queue.retrieveEvent1Count.initializeValue();
- queue.retrieveRequestCount.initializeValue();
- queue.retrieveDOMUpdateCount.initializeValue();
- }
-
- private void checkCounts(int events, int requests, int domUpdates) {
- assertChangeIfNotEqualToOldValue(queue.retrieveEvent1Count, events,
"eventCount");
- assertChangeIfNotEqualToOldValue(queue.retrieveRequestCount, requests,
"requestCount");
- assertChangeIfNotEqualToOldValue(queue.retrieveDOMUpdateCount, domUpdates,
"domUpdates");
- }
-
- private void assertChangeIfNotEqualToOldValue(Retriever<Integer> retrieveCount,
Integer eventCount, String eventType) {
- if (!eventCount.equals(retrieveCount.getValue())) {
-
assertEquals(waitAjax.failWith(eventType).waitForChangeAndReturn(retrieveCount),
eventCount);
- } else {
- assertEquals(retrieveCount.retrieve(), eventCount);
- }
- }
-
- private void checkTimes() {
- checkTimes(requestDelay);
- }
-
- private void checkTimes(long requestDelay) {
- long eventTime = waitAjax.waitForChangeAndReturn(queue.retrieveEvent1Time);
- long beginTime = waitAjax.waitForChangeAndReturn(queue.retrieveBeginTime);
- long actualDelay = beginTime - eventTime;
- long deviation = Math.abs(actualDelay - requestDelay);
- long maxDeviation = Math.max(50, requestDelay);
-
- if (seleniumDebug) {
- System.out.println(format("deviation for requestDelay {0}: {1}",
requestDelay, deviation));
- }
-
- assertTrue(
- deviation <= maxDeviation,
- format("Deviation ({0}) is greater than maxDeviation ({1}) for
requestDelay {2}", deviation, maxDeviation,
- requestDelay));
-
- deviationTotal += deviation;
- deviationCount += 1;
- }
-
- private void checkAvgDeviation() {
- long maximumAvgDeviation = Math.max(25, Math.min(50, requestDelay / 4));
- long averageDeviation = deviationTotal / deviationCount;
- if (seleniumDebug) {
- System.out.println("averageDeviation: " + averageDeviation);
- }
- assertTrue(
- averageDeviation <= maximumAvgDeviation,
- format(
- "Average deviation for all tests of requestDelay ({0}) should not be
greater than defined maximum {1}",
- averageDeviation, maximumAvgDeviation));
- }
}
\ No newline at end of file