Author: lfryc(a)redhat.com
Date: 2010-09-13 07:58:36 -0400 (Mon, 13 Sep 2010)
New Revision: 19167
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/formQueue.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/globalQueue.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueAttributes.java
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/TestFormQueue.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestGlobalQueue.java
Removed:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/simple.xhtml
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JQueueBean.java
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/list.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTime.xhtml
Log:
a4j:queue - modified global queue test; added form queues interleaving test (RFPL-733)
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JQueueBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JQueueBean.java 2010-09-13
11:54:19 UTC (rev 19166)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/A4JQueueBean.java 2010-09-13
11:58:36 UTC (rev 19167)
@@ -34,7 +34,7 @@
/**
* Managed bean for a4j:queue.
- *
+ *
* @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
* @version $Revision$
*/
@@ -47,6 +47,10 @@
private Attributes attributes;
private String text;
+ private A4JQueueBean globalQueue;
+ private A4JQueueBean formQueue1;
+ private A4JQueueBean formQueue2;
+
/**
* Initializes the managed bean.
*/
@@ -58,8 +62,13 @@
// initialize attributes
attributes = Attributes.getUIComponentAttributes(UIQueue.class, getClass());
attributes.setAttribute("rendered", true);
- attributes.setAttribute("requestDelay", 1500);
+ // hidden attributes
+ attributes.remove("status");
+
+ // TODO attributes not implemented yet
+ attributes.remove("timeout");
+ attributes.remove("ignoreDupResponses");
}
public Attributes getAttributes() {
@@ -70,6 +79,37 @@
this.attributes = attributes;
}
+ public A4JQueueBean getGlobalQueue() {
+ if (globalQueue == null) {
+ globalQueue = new A4JQueueBean();
+ globalQueue.init();
+ globalQueue.attributes.setAttribute("requestDelay", 10000);
+ }
+ return globalQueue;
+ }
+
+ public A4JQueueBean getFormQueue1() {
+ if (formQueue1 == null) {
+ formQueue1 = new A4JQueueBean();
+ formQueue1.init();
+ formQueue1.attributes.setAttribute("requestDelay", 500);
+ }
+ return formQueue1;
+ }
+
+ public A4JQueueBean getFormQueue2() {
+ if (formQueue2 == null) {
+ formQueue2 = new A4JQueueBean();
+ formQueue2.init();
+ formQueue2.attributes.setAttribute("requestDelay", 2000);
+ }
+ return formQueue2;
+ }
+
+ public A4JQueueBean[] getFormQueues() {
+ return new A4JQueueBean[]{getFormQueue1(), getFormQueue2()};
+ }
+
public String getText() {
return text;
}
Added:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/formQueue.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/formQueue.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/formQueue.xhtml 2010-09-13
11:58:36 UTC (rev 19167)
@@ -0,0 +1,138 @@
+<!--
+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.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
xmlns:rich="http://richfaces.org/rich"
+
xmlns:c="http://java.sun.com/jsp/jstl/core">
+
+<ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ <c:set var="dontRenderForm" value="#{true}" />
+ </f:metadata>
+ <h:outputStylesheet library="css" name="a4jQueue.css"
/>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+
+ <a4j:queue id="globalQueue"
ignoreDupResponses="#{a4jQueueBean.globalQueue.attributes['ignoreDupResponses'].value}"
+
name="#{a4jQueueBean.globalQueue.attributes['name'].value}"
+
onbeforedomupdate="#{a4jQueueBean.globalQueue.attributes['onbeforedomupdate'].value}"
+
oncomplete="#{a4jQueueBean.globalQueue.attributes['oncomplete'].value}"
+
onerror="#{a4jQueueBean.globalQueue.attributes['onerror'].value}"
onevent="#{a4jQueueBean.globalQueue.attributes['event'].value}"
+
onrequestdequeue="#{a4jQueueBean.globalQueue.attributes['onrequestdequeue'].value}"
+
onrequestqueue="#{a4jQueueBean.globalQueue.attributes['onrequestqueue'].value}"
+
onsubmit="#{a4jQueueBean.globalQueue.attributes['onsubmit'].value}"
+
rendered="#{a4jQueueBean.globalQueue.attributes['rendered'].value}"
+
requestDelay="#{a4jQueueBean.globalQueue.attributes['requestDelay'].value}"
+
timeout="#{a4jQueueBean.globalQueue.attributes['timeout'].value}" />
+
+ <c:forEach var="i" begin="1" end="2"
step="1">
+ <rich:panel id="formQueue${i}Panel" header="Form Based
Queue ${i}">
+ <h:form id="formQueue${i}Form">
+
+ <a4j:queue id="queue"
+
ignoreDupResponses="#{a4jQueueBean.formQueues[i-1].attributes['ignoreDupResponses'].value}"
+
name="#{a4jQueueBean.formQueues[i-1].attributes['name'].value}"
+
onbeforedomupdate="#{a4jQueueBean.formQueues[i-1].attributes['onbeforedomupdate'].value}"
+
oncomplete="#{a4jQueueBean.formQueues[i-1].attributes['oncomplete'].value}"
+
onerror="#{a4jQueueBean.formQueues[i-1].attributes['onerror'].value}"
+
onevent="#{a4jQueueBean.formQueues[i-1].attributes['event'].value}"
+
onrequestdequeue="#{a4jQueueBean.formQueues[i-1].attributes['onrequestdequeue'].value}"
+
onrequestqueue="#{a4jQueueBean.formQueues[i-1].attributes['onrequestqueue'].value}"
+
onsubmit="#{a4jQueueBean.formQueues[i-1].attributes['onsubmit'].value}"
+
rendered="#{a4jQueueBean.formQueues[i-1].attributes['rendered'].value}"
+
requestDelay="#{a4jQueueBean.formQueues[i-1].attributes['requestDelay'].value}"
+
timeout="#{a4jQueueBean.formQueues[i-1].attributes['timeout'].value}"
/>
+
+ <script type="text/javascript">
+ function add(element) {
+ element.innerHTML = 1 + parseInt(element.innerHTML);
+ }
+ </script>
+
+ <h:panelGrid columns="2">
+ <h:outputText value="Event 1:" />
+ <h:inputText id="input1"
value="#{a4jQueueBean.text}"
onkeypress="add(#{rich:element('events1')});
refresh(#{rich:element('eventTime1:outputTime')}); "
+ disabled="#{not
(facesContext.maximumSeverity==null)}">
+ <a4j:ajax event="keypress"
onbegin="add(#{rich:element('requests')});
refresh(#{rich:element('beginTime:outputTime')}); "
render="outtext"
+
oncomplete="refresh(#{rich:element('completeTime:outputTime')});"
onbeforedomupdate="add(#{rich:element('updates')}); " />
+ </h:inputText>
+ <h:outputText value="Event 2:" />
+ <h:inputText id="input2"
value="#{a4jQueueBean.text}"
onkeypress="add(#{rich:element('events2')});
refresh(#{rich:element('eventTime2:outputTime')}); "
+ disabled="#{not
(facesContext.maximumSeverity==null)}">
+ <a4j:ajax event="keypress"
onbegin="add(#{rich:element('requests')});
refresh(#{rich:element('beginTime:outputTime')}); "
render="outtext"
+
oncomplete="refresh(#{rich:element('completeTime:outputTime')});"
onbeforedomupdate="add(#{rich:element('updates')}); " />
+ </h:inputText>
+
+
+ <h:outputText value="Repeated text:" />
+ <h:outputText value="#{a4jQueueBean.text}"
id="outtext" style="font-weight:bold;" />
+ <h:outputText value="Event 1 count:" />
+ <h:outputText value="0" id="events1"
/>
+ <h:outputText value="Event 2 count:" />
+ <h:outputText value="0" id="events2"
/>
+ <h:outputText value="Requests count:" />
+ <h:outputText value="0" id="requests"
/>
+ <h:outputText value="DOM updates count:" />
+ <h:outputText value="0" id="updates"
/>
+
+ </h:panelGrid>
+
+ <h:panelGrid columns="1">
+ <metamer:clientTime id="eventTime1"
label="Event 1 Time:" />
+ <metamer:clientTime id="eventTime2"
label="Event 2 Time:" />
+ <metamer:clientTime id="beginTime" label="Begin
Time:" />
+ <metamer:clientTime id="completeTime"
label="Complete Time:" />
+ </h:panelGrid>
+ </h:form>
+ </rich:panel>
+
+ </c:forEach>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <h:form id="attributeForm">
+ <rich:panel id="formQueue1AttributesPanel" header="Form
Queue 1 Attributes">
+ <metamer:attributes
value="#{a4jQueueBean.formQueue1.attributes}"
id="formQueue1Attributes" />
+ </rich:panel>
+ <rich:panel id="formQueue2AttributesPanel" header="Form
Queue 2 Attributes">
+ <metamer:attributes
value="#{a4jQueueBean.formQueue2.attributes}"
id="formQueue2Attributes" />
+ </rich:panel>
+ <rich:panel id="globalQueueAttributesPanel" header="Global
Queue Attributes">
+ <metamer:attributes
value="#{a4jQueueBean.globalQueue.attributes}"
id="globalQueueAttributes" />
+ </rich:panel>
+ </h:form>
+ </ui:define>
+
+</ui:composition>
+</html>
\ No newline at end of file
Copied:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/globalQueue.xhtml
(from rev 19087,
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/simple.xhtml)
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/globalQueue.xhtml
(rev 0)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/globalQueue.xhtml 2010-09-13
11:58:36 UTC (rev 19167)
@@ -0,0 +1,101 @@
+<!--
+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.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
xmlns:rich="http://richfaces.org/rich"
+
xmlns:c="http://java.sun.com/jsp/jstl/core">
+
+<ui:composition template="/templates/template.xhtml">
+
+ <ui:define name="head">
+ <f:metadata>
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
+ </f:viewParam>
+ <c:set var="dontRenderForm" value="#{true}" />
+ </f:metadata>
+ <h:outputStylesheet library="css" name="a4jQueue.css"
/>
+ <script type="text/javascript">
+ function add(element) {
+ element.innerHTML = 1 + parseInt(element.innerHTML);
+ }
+ </script>
+ </ui:define>
+
+ <ui:define name="outOfTemplateBefore">
+ </ui:define>
+
+ <ui:define name="component">
+
+
+ <a4j:queue id="a4jQueue"
ignoreDupResponses="#{a4jQueueBean.attributes['ignoreDupResponses'].value}"
+ name="#{a4jQueueBean.attributes['name'].value}"
+
onbeforedomupdate="#{a4jQueueBean.attributes['onbeforedomupdate'].value}"
+
oncomplete="#{a4jQueueBean.attributes['oncomplete'].value}"
+ onerror="#{a4jQueueBean.attributes['onerror'].value}"
onevent="#{a4jQueueBean.attributes['event'].value}"
+
onrequestdequeue="#{a4jQueueBean.attributes['onrequestdequeue'].value}"
+
onrequestqueue="#{a4jQueueBean.attributes['onrequestqueue'].value}"
+ onsubmit="#{a4jQueueBean.attributes['onsubmit'].value}"
+ rendered="#{a4jQueueBean.attributes['rendered'].value}"
+
requestDelay="#{a4jQueueBean.attributes['requestDelay'].value}"
status="status1"
+ timeout="#{a4jQueueBean.attributes['timeout'].value}"
/>
+
+ <h:form name="queueTestForm">
+ <h:panelGrid columns="2">
+ <h:outputText value="Type here:" />
+ <h:inputText id="input1"
value="#{a4jQueueBean.text}"
onkeypress="add(#{rich:element('events1')});
refresh(#{rich:element('eventTime1:outputTime')}); "
+ disabled="#{not (facesContext.maximumSeverity==null)}">
+ <a4j:ajax event="keypress"
onbegin="add(#{rich:element('requests')});
refresh(#{rich:element('beginTime:outputTime')}); "
render="outtext"
oncomplete="refresh(#{rich:element('completeTime:outputTime')}); "
+
onbeforedomupdate="add(#{rich:element('updates')});"/>
+ </h:inputText>
+
+ <h:outputText value="Repeated text:" />
+ <h:outputText value="#{a4jQueueBean.text}"
id="outtext" style="font-weight:bold;" />
+ <h:outputText value="Events count:" />
+ <h:outputText value="0" id="events1" />
+ <h:outputText value="Requests count:" />
+ <h:outputText value="0" id="requests" />
+ <h:outputText value="DOM updates count:" />
+ <h:outputText value="0" id="updates" />
+
+ </h:panelGrid>
+
+ <h:panelGrid columns="1">
+ <metamer:clientTime id="eventTime1" label="Event
Time:" />
+ <metamer:clientTime id="beginTime" label="Begin
Time:" />
+ <metamer:clientTime id="completeTime" label="Complete
Time:" />
+ </h:panelGrid>
+
+ </h:form>
+
+ </ui:define>
+
+ <ui:define name="outOfTemplateAfter">
+ <h:form id="attributeForm">
+ <metamer:attributes value="#{a4jQueueBean.attributes}"
id="attributes" />
+ </h:form>
+ </ui:define>
+
+</ui:composition>
+</html>
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/list.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/list.xhtml 2010-09-13
11:54:19 UTC (rev 19166)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/list.xhtml 2010-09-13
11:58:36 UTC (rev 19167)
@@ -30,9 +30,15 @@
<ui:define name="links">
- <metamer:testPageLink id="simple" outcome="simple"
value="Simple">
- Simple page that contains <b>a4j:queue</b> and input boxes
for all its attributes.
+ <metamer:testPageLink id="globalQueue"
outcome="globalQueue" value="Global Queue">
+ Simple page that contains <b>a4j:queue</b> outside of any
form (<b>global queue</b>) and input boxes for all its attributes.
</metamer:testPageLink>
+
+ <metamer:testPageLink id="formQueue"
outcome="formQueue" value="Form Queue">
+ <div>There are three <b>a4j:queue</b>s defined: two
inside forms (<b>form based queues</b>) and also <b>global
queue</b>.</div>
+ <div>The <b>form based queues</b> should not inherit
any attributes from <b>global queue</b>.</div>
+
+ </metamer:testPageLink>
</ui:define>
Deleted:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/simple.xhtml 2010-09-13
11:54:19 UTC (rev 19166)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jQueue/simple.xhtml 2010-09-13
11:58:36 UTC (rev 19167)
@@ -1,104 +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.
--->
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:metamer="http://java.sun.com/jsf/composite/metamer"
xmlns:rich="http://richfaces.org/rich">
-
- <ui:composition template="/templates/template.xhtml">
-
- <ui:define name="head">
- <f:metadata>
- <f:viewParam name="templates"
value="#{templateBean.templates}">
- <f:converter converterId="templatesListConverter" />
- </f:viewParam>
- </f:metadata>
- <h:outputStylesheet library="css" name="a4jQueue.css"
/>
- <script type="text/javascript">
- var events = 0;
- var updates = 0;
- var requests = 0;
-
- function addEvent() {
- events++;
- }
- function addUpdate() {
- updates++;
- }
- function addRequest() {
- requests++;
- }
-
- function printCounts() {
- #{rich:element('events')}.innerHTML=events;
- #{rich:element('updates')}.innerHTML=updates;
- #{rich:element('requests')}.innerHTML=requests;
- }
- </script>
- </ui:define>
-
- <ui:define name="outOfTemplateBefore">
- </ui:define>
-
- <ui:define name="component">
-
- <a4j:queue id="a4jQueue"
-
ignoreDupResponses="#{a4jQueueBean.attributes['ignoreDupResponses'].value}"
- name="#{a4jQueueBean.attributes['name'].value}"
-
onbeforedomupdate="#{a4jQueueBean.attributes['onbeforedomupdate'].value}"
-
oncomplete="#{a4jQueueBean.attributes['oncomplete'].value}"
-
onerror="#{a4jQueueBean.attributes['onerror'].value}"
-
onevent="#{a4jQueueBean.attributes['event'].value}"
-
onrequestdequeue="#{a4jQueueBean.attributes['onrequestdequeue'].value}"
-
onrequestqueue="#{a4jQueueBean.attributes['onrequestqueue'].value}"
-
onsubmit="#{a4jQueueBean.attributes['onsubmit'].value}"
-
rendered="#{a4jQueueBean.attributes['rendered'].value}"
-
requestDelay="#{a4jQueueBean.attributes['requestDelay'].value}"
-
status="#{a4jQueueBean.attributes['status'].value}"
-
timeout="#{a4jQueueBean.attributes['timeout'].value}"/>
-
- <h:panelGrid columns="2">
- <h:outputText value="Type here:" />
- <h:inputText id="input"
value="#{a4jQueueBean.text}" onkeyup="addEvent();"
disabled="#{not (facesContext.maximumSeverity==null)}">
- <a4j:ajax onbegin="addRequest();"
event="keyup" render="outtext" oncomplete="printCounts()"
onbeforedomupdate="addUpdate()" />
- </h:inputText>
-
- <h:outputText value="Repeated text:" />
- <h:outputText value="#{a4jQueueBean.text}"
id="outtext"
- style="font-weight:bold;" />
- <h:outputText value="Events count:" />
- <h:outputText value="0" id="events" />
- <h:outputText value="Requests count:" />
- <h:outputText value="0" id="requests" />
- <h:outputText value="DOM updates count:" />
- <h:outputText value="0" id="updates" />
- </h:panelGrid>
-
- </ui:define>
-
- <ui:define name="outOfTemplateAfter">
- <metamer:attributes value="#{a4jQueueBean.attributes}"
id="attributes" />
- </ui:define>
-
- </ui:composition>
-</html>
\ No newline at end of file
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTime.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTime.xhtml 2010-09-13
11:54:19 UTC (rev 19166)
+++
modules/tests/metamer/trunk/application/src/main/webapp/resources/metamer/clientTime.xhtml 2010-09-13
11:58:36 UTC (rev 19167)
@@ -1,26 +1,26 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:a4j="http://richfaces.org/a4j">
+
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:body>
<composite:interface>
+ <composite:attribute name="id" type="java.lang.String"
required="true" />
<composite:attribute name="label"
type="java.lang.String" required="true" />
- <composite:attribute name="name"
type="java.lang.String" default="metamerOutputTime" />
</composite:interface>
<composite:implementation>
- <h:outputLabel value="#{cc.attrs.label}"
for="#{cc.attrs.name}" />
- <h:outputText styleClass="metamerOutputTime"
id="#{cc.attrs.name}" value="" title="" />
+ <h:outputLabel value="#{cc.attrs.label}" />
+ <h:outputText id="outputTime" value=""
title="" />
<h:outputScript library="script" name="date-format.js"
/>
<script type="text/javascript">
//<![CDATA[
- function #{cc.attrs.name}Refresh() {
+ function refresh(element) {
var now = new Date();
- jQuery("span.metamerOutputTime[id$=#{cc.attrs.name}]")
+ jQuery(element)
.text(now.format("dd.mm.yyyy HH:MM:ss.l", false))
.attr("title", now.getTime());
}
- #{cc.attrs.name}Refresh();
+ refresh(#{rich:element('outputTime')});
//]]>
</script>
</composite:implementation>
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueAttributes.java 2010-09-13
11:58:36 UTC (rev 19167)
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.a4jQueue;
+
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.ExtendedLocator;
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class QueueAttributes extends AbstractComponentAttributes {
+
+ public QueueAttributes() {
+ }
+
+ public QueueAttributes(ExtendedLocator<JQueryLocator> root) {
+ super(root);
+ }
+
+ public void setIgnoreDupResponses(boolean ignoreDupResponses) {
+ setProperty("ignoreDupResponses", ignoreDupResponses);
+ }
+
+ public void setName(String name) {
+ setProperty("name", name);
+ }
+
+ public void setOnBeforeDomUpdate(JavaScript onBeforeDomUpdate) {
+ setProperty("onbeforedomupdate", onBeforeDomUpdate);
+ }
+
+ public void setOnComplete(JavaScript onComplete) {
+ setProperty("oncomplete", onComplete);
+ }
+
+ public void setOnEvent(JavaScript onEvent) {
+ setProperty("onevent", onEvent);
+ }
+
+ public void setOnError(JavaScript onError) {
+ setProperty("onerror", onError);
+ }
+
+ public void setOnRequestDequeue(JavaScript onRequestDequeue) {
+ setProperty("onrequestdequeue", onRequestDequeue);
+ }
+
+ public void setOnRequestQueue(JavaScript onRequestQueue) {
+ setProperty("onrequestqueue", onRequestQueue);
+ }
+
+ public void setOnSubmit(JavaScript onSubmit) {
+ setProperty("onsubmit", onSubmit);
+ }
+
+ public void setRendered(boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+
+ public void setRequestDelay(long requestDelay) {
+ setProperty("requestDelay", requestDelay);
+ }
+
+ public void setTimeout(long timeout) {
+ setProperty("timeout", timeout);
+ }
+
+}
Added:
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/QueueLocators.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/QueueLocators.java 2010-09-13
11:58:36 UTC (rev 19167)
@@ -0,0 +1,93 @@
+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.locator.Attribute.TITLE;
+import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
+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 org.jboss.test.selenium.locator.AttributeLocator;
+import org.jboss.test.selenium.locator.ElementLocator;
+import org.jboss.test.selenium.locator.ExtendedLocator;
+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 QueueLocators {
+
+ LocatorReference<JQueryLocator> form = new
LocatorReference<JQueryLocator>(null);
+ LocatorReference<JQueryLocator> attributesPanel = new
LocatorReference<JQueryLocator>(null);
+
+ ReferencedLocator<JQueryLocator> input1 = ref(form,
"input:text[id$=input1]");
+ ReferencedLocator<JQueryLocator> input2 = ref(form,
"input:text[id$=input2]");
+ ReferencedLocator<JQueryLocator> attributesTable = ref(attributesPanel,
"table.attributes");
+
+ QueueAttributes attributes = new QueueAttributes(attributesTable);
+
+ 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));
+
+ private String identifier;
+
+ public QueueLocators(String identifier, JQueryLocator queueRoot, JQueryLocator
queueAttributesPanel) {
+ this.identifier = identifier;
+
+ form.setLocator(queueRoot);
+ attributesPanel.setLocator(queueAttributesPanel);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ QueueLocators other = (QueueLocators) obj;
+ if (identifier == null) {
+ if (other.identifier != null) {
+ return false;
+ }
+ } else if (!identifier.equals(other.identifier)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "FormQueueLocators [identifier=" + identifier + "]";
+ }
+}
Added:
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
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestFormQueue.java 2010-09-13
11:58:36 UTC (rev 19167)
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * 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.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.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestFormQueue extends AbstractMetamerTest {
+
+ static final Long GLOBAL_DELAY = 10000L;
+ static final Long DELAY_A = 3000L;
+ static final Long DELAY_B = 5000L;
+
+ int deviationTotal;
+ int deviationCount;
+
+ QueueLocators formQueueA = prepareLocators("formQueue1");
+ QueueLocators formQueueB = prepareLocators("formQueue2");
+ QueueLocators globalQueue = prepareLocators("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));
+ }
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/a4jQueue/formQueue.xhtml");
+ }
+
+ @Test
+ public void testTimingOneQueueTwoEvents() {
+ formQueueA.attributes.setRequestDelay(DELAY_A);
+ globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+
+ initializeTimes(formQueueA);
+
+ XHRHalter.enable();
+
+ fireEvent(formQueueA, Event.FIRST, 2);
+ fireEvent(formQueueA, Event.SECOND, 3);
+
+ XHRHalter halter = XHRHalter.getHandleBlocking();
+ halter.complete();
+ halter.waitForOpen();
+ halter.complete();
+
+ checkTimes(formQueueA, Event.SECOND, DELAY_A);
+ }
+
+ @Test
+ public void testCountsOneQueueTwoEvents() {
+ formQueueA.attributes.setRequestDelay(DELAY_A);
+ globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+
+ initializeCounts(formQueueA);
+
+ XHRHalter.enable();
+
+ fireEvent(formQueueA, Event.FIRST, 2);
+ checkCounts(formQueueA, 2, 0, 0, 0);
+ fireEvent(formQueueA, Event.SECOND, 3);
+ checkCounts(formQueueA, 2, 3, 1, 0);
+
+ XHRHalter halter = XHRHalter.getHandleBlocking();
+ checkCounts(formQueueA, 2, 3, 1, 0);
+ halter.complete();
+ checkCounts(formQueueA, 2, 3, 2, 1);
+ halter.waitForOpen();
+ checkCounts(formQueueA, 2, 3, 2, 1);
+ halter.complete();
+ checkCounts(formQueueA, 2, 3, 2, 2);
+ }
+
+ @Test
+ public void testTimingTwoQueuesFourEvents() {
+ formQueueA.attributes.setRequestDelay(DELAY_A);
+ formQueueB.attributes.setRequestDelay(DELAY_B);
+ globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+
+ initializeTimes(formQueueA);
+ initializeTimes(formQueueB);
+
+ XHRHalter.enable();
+
+ fireEvent(formQueueA, Event.FIRST, 1);
+ fireEvent(formQueueA, Event.SECOND, 1);
+ fireEvent(formQueueB, Event.FIRST, 1);
+ fireEvent(formQueueB, Event.SECOND, 1);
+
+ XHRHalter halter = XHRHalter.getHandleBlocking();
+ halter.complete();
+ halter.waitForOpen();
+ halter.complete();
+ halter.waitForOpen();
+ halter.complete();
+ halter.waitForOpen();
+ halter.complete();
+
+ checkTimes(formQueueB, Event.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);
+ }
+
+ @Test
+ public void testCountsTwoQueuesThreeEvents() {
+ formQueueA.attributes.setRequestDelay(DELAY_A);
+ formQueueB.attributes.setRequestDelay(DELAY_B);
+ globalQueue.attributes.setRequestDelay(GLOBAL_DELAY);
+
+ initializeCounts(formQueueA);
+ initializeCounts(formQueueB);
+
+ 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);
+
+ checkCounts(formQueueA, 1, 1, 1, 0);
+ checkCounts(formQueueB, 1, 1, 0, 0);
+
+ XHRHalter halter = XHRHalter.getHandleBlocking();
+ halter.complete();
+ checkCounts(formQueueA, 1, 1, 2, 1);
+ halter.waitForOpen();
+ halter.complete();
+ checkCounts(formQueueA, 1, 1, 2, 2);
+ checkCounts(formQueueB, 1, 1, 1, 0);
+ halter.waitForOpen();
+ halter.complete();
+ halter.waitForOpen();
+ checkCounts(formQueueB, 1, 1, 2, 1);
+ halter.complete();
+
+ checkCounts(formQueueA, 1, 1, 2, 2);
+ checkCounts(formQueueB, 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
Added:
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
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jQueue/TestGlobalQueue.java 2010-09-13
11:58:36 UTC (rev 19167)
@@ -0,0 +1,243 @@
+/*******************************************************************************
+ * 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.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.Use;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestGlobalQueue extends AbstractMetamerTest {
+
+ QueueLocators queue = new QueueLocators("globalQueue", pjq(""),
pjq("#attributeForm"));
+
+ 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");
+ }
+
+ @Test
+ @Use(field = "requestDelay", ints = { 0, 500, 1500, 5000 })
+ public void testRequestDelay() {
+ attributes.setRequestDelay(requestDelay);
+
+ initializeTimes();
+ for (int i = 0; i < 5; i++) {
+ fireEvents(1);
+ checkTimes();
+ }
+ checkAvgDeviation();
+ }
+
+ @Test
+ public void testMultipleRequestsWithDelay() {
+ attributes.setRequestDelay(3000);
+
+ initializeCounts();
+
+ XHRHalter.enable();
+
+ fireEvents(4);
+ XHRHalter handle = XHRHalter.getHandleBlocking();
+ handle.send();
+ handle.complete();
+
+ checkCounts(4, 1, 1);
+
+ fireEvents(3);
+ handle.waitForOpen();
+ handle.send();
+ handle.complete();
+
+ checkCounts(7, 2, 2);
+
+ XHRHalter.disable();
+ }
+
+ @Test
+ public void testMultipleRequestsWithNoDelay() {
+ attributes.setRequestDelay(0);
+
+ initializeCounts();
+
+ XHRHalter.enable();
+
+ fireEvents(1);
+ checkCounts(1, 1, 0);
+
+ XHRHalter handle = XHRHalter.getHandleBlocking();
+ handle.send();
+
+ fireEvents(1);
+ checkCounts(2, 1, 0);
+
+ handle.complete();
+ checkCounts(2, 2, 1);
+
+ handle.waitForOpen();
+ handle.send();
+ fireEvents(4);
+ checkCounts(6, 2, 1);
+
+ handle.complete();
+ checkCounts(6, 3, 2);
+
+ handle.waitForOpen();
+ handle.send();
+ fireEvents(1);
+ checkCounts(7, 3, 2);
+
+ handle.complete();
+ checkCounts(7, 4, 3);
+
+ handle.waitForOpen();
+ handle.send();
+ checkCounts(7, 4, 3);
+
+ handle.complete();
+ checkCounts(7, 4, 4);
+
+ XHRHalter.disable();
+ }
+
+ // TODO not implemented yet
+ public void testTimeout() {
+ attributes.setRequestDelay(0);
+ attributes.setTimeout(1000);
+
+ XHRHalter.enable();
+
+ fireEvents(1);
+ XHRHalter handle = XHRHalter.getHandleBlocking();
+ handle.continueBefore(XHRState.COMPLETE);
+ fireEvents(10);
+
+ XHRHalter.disable();
+
+ // fireEvents(1);
+ // fireEvents(1);
+ }
+
+ // TODO not implemented yet
+ public void testIgnoreDuplicatedResponses() {
+ attributes.setIgnoreDupResponses(true);
+
+ XHRHalter.enable();
+ fireEvents(1);
+ XHRHalter handle = XHRHalter.getHandleBlocking();
+ handle.send();
+ fireEvents(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() {
+ 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