Author: jpapouse
Date: 2011-09-22 04:14:55 -0400 (Thu, 22 Sep 2011)
New Revision: 22729
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/AbstractAttachQueueTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestExtendingAttachQueue.java
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAttachQueue/extending.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestNestedAttachQueue.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java
Log:
RFPL-927 (a4j:attachQueue): updated 'extending' sample and created selenium test
for it
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAttachQueue/extending.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAttachQueue/extending.xhtml 2011-09-20
13:18:45 UTC (rev 22728)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jAttachQueue/extending.xhtml 2011-09-22
08:14:55 UTC (rev 22729)
@@ -62,12 +62,12 @@
<fieldset>
<legend><a4j:ajax event="keyup"
></legend>
- <a4j:ajax event="keyup" render="output1, output2"
execute="@form" onbegin="add(#{rich:element('requests')});
#{rich:element('timeWatcher:grid')}.begin(); "
+ <a4j:ajax event="keypress" render="output1"
execute="@form" onbegin="add(#{rich:element('requests')});
#{rich:element('timeWatcher:grid')}.begin(); "
oncomplete="#{rich:element('timeWatcher:grid')}.complete();
#{rich:element('timeWatcher:grid')}.difference();"
onbeforedomupdate="add(#{rich:element('updates')});">
- <div><a4j:attachQueue /></div>
+ <div><a4j:attachQueue 1 /></div>
- <a4j:attachQueue id="a4jAttachQueue"
+ <a4j:attachQueue id="a4jAttachQueue1"
ignoreDupResponses="#{a4jAttachQueueBean.attributes['ignoreDupResponses'].value}"
name="#{a4jAttachQueueBean.attributes['name'].value}"
onrequestdequeue="#{a4jAttachQueueBean.attributes['onrequestdequeue'].value}"
@@ -77,10 +77,26 @@
requestGroupingId="#{a4jAttachQueueBean.attributes['requestGroupingId'].value}"
/>
- <h:inputText id="input1"
value="#{a4jAttachQueueBean.text1}"
onkeyup="add(#{rich:element('events')});
#{rich:element('timeWatcher:grid')}.event();"/>
- <h:inputText id="input2"
value="#{a4jAttachQueueBean.text2}"
onkeyup="add(#{rich:element('events')});
#{rich:element('timeWatcher:grid')}.event();"/>
+ <h:inputText id="input1"
value="#{a4jAttachQueueBean.text1}"
onkeypress="add(#{rich:element('events1')});
#{rich:element('timeWatcher:grid')}.event(1); " />
</a4j:ajax>
+ <a4j:ajax event="keypress" render="output2"
execute="@form" onbegin="add(#{rich:element('requests')});
#{rich:element('timeWatcher:grid')}.begin(); "
+
oncomplete="#{rich:element('timeWatcher:grid')}.complete();
#{rich:element('timeWatcher:grid')}.difference();"
onbeforedomupdate="add(#{rich:element('updates')});">
+ <div><a4j:attachQueue 2 /></div>
+
+ <a4j:attachQueue id="a4jAttachQueue2"
+
ignoreDupResponses="#{a4jAttachQueueBean.attributes['ignoreDupResponses'].value}"
+
name="#{a4jAttachQueueBean.attributes['name'].value}"
+
onrequestdequeue="#{a4jAttachQueueBean.attributes['onrequestdequeue'].value}"
+
onrequestqueue="#{a4jAttachQueueBean.attributes['onrequestqueue'].value}"
+
rendered="#{a4jAttachQueueBean.attributes['rendered'].value}"
+
requestDelay="#{a4jAttachQueueBean.attributes['requestDelay'].value}"
+
requestGroupingId="#{a4jAttachQueueBean.attributes['requestGroupingId'].value}"
+ />
+ <h:inputText id="input2"
value="#{a4jAttachQueueBean.text2}"
onkeypress="add(#{rich:element('events2')});
#{rich:element('timeWatcher:grid')}.event(2); " />
+ </a4j:ajax>
+
+
</fieldset>
<h:panelGrid columns="2">
@@ -88,24 +104,29 @@
<h:outputText id="output1"
value="#{a4jAttachQueueBean.text1}" style="font-weight:bold;"/>
Output 2:
<h:outputText id="output2"
value="#{a4jAttachQueueBean.text2}" style="font-weight:bold;"/>
- Events count:
- <h:outputText value="0" id="events" />
+ Event 1 count:
+ <h:outputText value="0" id="events1" />
+ Event 2 count:
+ <h:outputText value="0" id="events2" />
Requests count:
<h:outputText value="0" id="requests" />
DOM updates count:
<h:outputText value="0" id="updates" />
</h:panelGrid>
- <metamer:clientTimeWatcher id="timeWatcher" />
+ <metamer:clientTimeWatcher id="timeWatcher" events="2"
/>
</ui:define>
<ui:define name="outOfTemplateAfter">
- Attributes for wrapping attach queue
- <metamer:attributes value="#{a4jAttachQueueBean.attributes}"
id="attributes" />
+ Attributes for wrapping attach queue 1
+ <metamer:attributes value="#{a4jAttachQueueBean.attributes}"
id="attributes1" />
<br />
+ Attributes for wrapping attach queue 2
+ <metamer:attributes value="#{a4jAttachQueueBean.attributes2}"
id="attributes2" />
+ <br />
Attributes for queue1
<br />
<metamer:attributes value="#{a4jQueueBean.attributes}"
id="queueAttributes" />
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/AbstractAttachQueueTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/AbstractAttachQueueTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/AbstractAttachQueueTest.java 2011-09-22
08:14:55 UTC (rev 22729)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.a4jAttachQueue;
+
+import static
org.richfaces.tests.metamer.ftest.a4jAttachQueue.AttachQueueAttributes.onrequestdequeue;
+import static
org.richfaces.tests.metamer.ftest.a4jAttachQueue.AttachQueueAttributes.onrequestqueue;
+import static
org.richfaces.tests.metamer.ftest.a4jAttachQueue.AttachQueueAttributes.rendered;
+import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.attachQueueAttrs1;
+import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.attachQueueAttrs2;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+
+import org.jboss.cheiron.halt.XHRHalter;
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.a4jQueue.QueueModel;
+import org.richfaces.tests.metamer.ftest.a4jQueue.QueueModel.Input;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public abstract class AbstractAttachQueueTest extends AbstractMetamerTest {
+
+ protected static final Long GLOBAL_DELAY = 10000L;
+ protected static final Long DELAY_A = 3000L;
+ protected static final Long DELAY_B = 5000L;
+
+ private QueueModel queue = new QueueModel();
+
+ protected QueueModel getQueue() {
+ return queue;
+ }
+
+ protected void testDelay() {
+ queue.initializeTimes();
+ queue.fireEvent(Input.FIRST, 1);
+ queue.checkTimes(Input.FIRST, DELAY_A);
+ }
+
+ protected void testNoDelay() {
+ attachQueueAttrs1.set(AttachQueueAttributes.requestDelay, 0);
+
+ queue.initializeCounts();
+
+ XHRHalter.enable();
+
+ queue.fireEvent(Input.FIRST, 4);
+ queue.checkCounts(4, 0, 1, 0);
+
+ XHRHalter halter = XHRHalter.getHandleBlocking();
+ queue.checkCounts(4, 0, 1, 0);
+
+ halter.complete();
+ queue.checkCounts(4, 0, 2, 1);
+
+ halter.waitForOpen();
+ queue.checkCounts(4, 0, 2, 1);
+
+ halter.complete();
+ queue.checkCounts(4, 0, 2, 2);
+ }
+
+ protected void testTimingOneQueueTwoEvents() {
+ queue.initializeTimes();
+
+ XHRHalter.enable();
+
+ queue.fireEvent(Input.FIRST, 3);
+ queue.fireEvent(Input.SECOND, 1);
+
+ XHRHalter halter = XHRHalter.getHandleBlocking();
+ halter.complete();
+ halter.waitForOpen();
+ halter.complete();
+
+ queue.checkTimes(Input.SECOND, DELAY_B);
+ queue.checkNoDelayBetweenEvents();
+ }
+
+ protected void testRendered() {
+ attachQueueAttrs1.set(AttachQueueAttributes.requestDelay, 1500);
+ attachQueueAttrs1.set(onrequestqueue,
JavaScript.js("alert('requestQueued')"));
+ attachQueueAttrs1.set(onrequestdequeue,
JavaScript.js("alert('requestDequeued')"));
+ attachQueueAttrs1.set(rendered, false);
+
+ queue.initializeTimes();
+ queue.fireEvent(1);
+
+ // check that no requestDelay is applied while renderer=false
+ queue.checkTimes(0);
+ assertFalse(selenium.isAlertPresent());
+ }
+
+ protected void testQueueAndDequeueEvents() {
+ attachQueueAttrs1.set(AttachQueueAttributes.requestDelay, 0);
+ attachQueueAttrs2.set(AttachQueueAttributes.requestDelay, 0);
+
+ attachQueueAttrs1.set(AttachQueueAttributes.onrequestqueue, "metamerEvents
+= \"requestqueue \"");
+ attachQueueAttrs1.set(AttachQueueAttributes.onrequestdequeue, "metamerEvents
+= \"requestdequeue \"");
+ selenium.getEval(new JavaScript("window.metamerEvents =
\"\";"));
+
+ queue.fireEvent(Input.FIRST, 1);
+
+ String[] events = selenium.getEval(new
JavaScript("window.metamerEvents")).split(" ");
+ assertEquals(events.length, 2, "2 events should be fired, was [" +
selenium.getEval(new JavaScript("window.metamerEvents")) + "]");
+ assertEquals(events[0], "requestqueue", "Attribute onrequestqueue
doesn't work");
+ assertEquals(events[1], "requestdequeue", "Attribute
onrequestdequeue doesn't work");
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestExtendingAttachQueue.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestExtendingAttachQueue.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestExtendingAttachQueue.java 2011-09-22
08:14:55 UTC (rev 22729)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.a4jAttachQueue;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.attachQueueAttrs1;
+import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.attachQueueAttrs2;
+import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.queueAttributes;
+
+import java.net.URL;
+
+import org.richfaces.tests.metamer.ftest.a4jQueue.QueueAttributes;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestExtendingAttachQueue extends AbstractAttachQueueTest {
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/a4jAttachQueue/extending.xhtml");
+ }
+
+ @BeforeMethod
+ public void setupDelays() {
+ attachQueueAttrs1.set(AttachQueueAttributes.requestDelay, DELAY_A);
+ attachQueueAttrs2.set(AttachQueueAttributes.requestDelay, DELAY_B);
+ queueAttributes.set(QueueAttributes.requestDelay, GLOBAL_DELAY);
+ }
+
+ @Test
+ public void testDelay() {
+ super.testDelay();
+ }
+
+ @Test
+ public void testNoDelay() {
+ super.testNoDelay();
+ }
+
+ @Test
+ public void testTimingOneQueueTwoEvents() {
+ super.testTimingOneQueueTwoEvents();
+ }
+
+ @Test
+ public void testRendered() {
+ super.testRendered();
+ }
+
+ @Test
+ public void testQueueAndDequeueEvents() {
+ super.testQueueAndDequeueEvents();
+ }
+}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestNestedAttachQueue.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestNestedAttachQueue.java 2011-09-20
13:18:45 UTC (rev 22728)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jAttachQueue/TestNestedAttachQueue.java 2011-09-22
08:14:55 UTC (rev 22729)
@@ -22,38 +22,21 @@
package org.richfaces.tests.metamer.ftest.a4jAttachQueue;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-import static
org.richfaces.tests.metamer.ftest.a4jAttachQueue.AttachQueueAttributes.onrequestdequeue;
-import static
org.richfaces.tests.metamer.ftest.a4jAttachQueue.AttachQueueAttributes.onrequestqueue;
-import static
org.richfaces.tests.metamer.ftest.a4jAttachQueue.AttachQueueAttributes.rendered;
import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.attachQueueAttrs1;
import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.attachQueueAttrs2;
import static
org.richfaces.tests.metamer.ftest.attributes.AttributeList.queueAttributes;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import java.io.InputStream;
import java.net.URL;
-import org.jboss.cheiron.halt.XHRHalter;
-import org.jboss.test.selenium.encapsulated.JavaScript;
-import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
import org.richfaces.tests.metamer.ftest.a4jQueue.QueueAttributes;
-import org.richfaces.tests.metamer.ftest.a4jQueue.QueueModel;
-import org.richfaces.tests.metamer.ftest.a4jQueue.QueueModel.Input;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
- * @version $Revision$
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
*/
-public class TestNestedAttachQueue extends AbstractMetamerTest {
-
- static final Long GLOBAL_DELAY = 10000L;
- static final Long DELAY_A = 3000L;
- static final Long DELAY_B = 5000L;
-
- QueueModel queue = new QueueModel();
+public class TestNestedAttachQueue extends AbstractAttachQueueTest {
@Override
public URL getTestUrl() {
@@ -66,87 +49,29 @@
attachQueueAttrs2.set(AttachQueueAttributes.requestDelay, DELAY_B);
queueAttributes.set(QueueAttributes.requestDelay, GLOBAL_DELAY);
}
-
+
@Test
public void testDelay() {
- queue.initializeTimes();
-
- queue.fireEvent(Input.FIRST, 1);
-
- queue.checkTimes(Input.FIRST, DELAY_A);
+ super.testDelay();
}
@Test
public void testNoDelay() {
- attachQueueAttrs1.set(AttachQueueAttributes.requestDelay, 0);
-
- queue.initializeCounts();
-
- XHRHalter.enable();
-
- queue.fireEvent(Input.FIRST, 4);
- queue.checkCounts(4, 0, 1, 0);
-
- XHRHalter halter = XHRHalter.getHandleBlocking();
- queue.checkCounts(4, 0, 1, 0);
-
- halter.complete();
- queue.checkCounts(4, 0, 2, 1);
-
- halter.waitForOpen();
- queue.checkCounts(4, 0, 2, 1);
-
- halter.complete();
- queue.checkCounts(4, 0, 2, 2);
+ super.testNoDelay();
}
@Test
public void testTimingOneQueueTwoEvents() {
- queue.initializeTimes();
-
- XHRHalter.enable();
-
- queue.fireEvent(Input.FIRST, 3);
- queue.fireEvent(Input.SECOND, 1);
-
- XHRHalter halter = XHRHalter.getHandleBlocking();
- halter.complete();
- halter.waitForOpen();
- halter.complete();
-
- queue.checkTimes(Input.SECOND, DELAY_B);
- queue.checkNoDelayBetweenEvents();
+ super.testTimingOneQueueTwoEvents();
}
@Test
public void testRendered() {
- attachQueueAttrs1.set(AttachQueueAttributes.requestDelay, 1500);
- attachQueueAttrs1.set(onrequestqueue,
JavaScript.js("alert('requestQueued')"));
- attachQueueAttrs1.set(onrequestdequeue,
JavaScript.js("alert('requestDequeued')"));
- attachQueueAttrs1.set(rendered, false);
-
- queue.initializeTimes();
- queue.fireEvent(1);
-
- // check that no requestDelay is applied while renderer=false
- queue.checkTimes(0);
- assertFalse(selenium.isAlertPresent());
+ super.testRendered();
}
@Test
public void testQueueAndDequeueEvents() {
- attachQueueAttrs1.set(AttachQueueAttributes.requestDelay, 0);
- attachQueueAttrs2.set(AttachQueueAttributes.requestDelay, 0);
-
- attachQueueAttrs1.set(AttachQueueAttributes.onrequestqueue, "metamerEvents
+= \"requestqueue \"");
- attachQueueAttrs1.set(AttachQueueAttributes.onrequestdequeue, "metamerEvents
+= \"requestdequeue \"");
- selenium.getEval(new JavaScript("window.metamerEvents =
\"\";"));
-
- queue.fireEvent(Input.FIRST, 1);
-
- String[] events = selenium.getEval(new
JavaScript("window.metamerEvents")).split(" ");
- assertEquals(events.length, 2, "2 events should be fired, was [" +
selenium.getEval(new JavaScript("window.metamerEvents")) + "]");
- assertEquals(events[0], "requestqueue", "Attribute onrequestqueue
doesn't work");
- assertEquals(events[1], "requestdequeue", "Attribute
onrequestdequeue doesn't work");
- }
+ super.testQueueAndDequeueEvents();
+ }
}
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java 2011-09-20
13:18:45 UTC (rev 22728)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueModel.java 2011-09-22
08:14:55 UTC (rev 22729)
@@ -157,7 +157,8 @@
long actualDelay = beginTime - eventTime;
long deviation = Math.abs(actualDelay - requestDelay);
long maxDeviation = Math.max(300, requestDelay / 2);
-
+ System.err.println(actualDelay);
+ System.err.println(requestDelay);
checkDeviation(deviation, maxDeviation);
deviations.add(deviation);