Author: jjamrich
Date: 2011-12-07 17:54:32 -0500 (Wed, 07 Dec 2011)
New Revision: 23060
Removed:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/PushAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPush/simple.xhtml
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/push.js
Log:
RFPL-1572: add message pushed without user action
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/JMSInitializer.java 2011-12-07
22:54:32 UTC (rev 23060)
@@ -23,7 +23,6 @@
import static org.richfaces.demo.push.JMSMessageProducer.PUSH_JMS_TOPIC;
import static
org.richfaces.demo.push.TopicsContextMessageProducer.PUSH_TOPICS_CONTEXT_TOPIC;
-import static org.richfaces.tests.metamer.bean.a4j.A4JPushBean.METAMER_TOPIC;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
@@ -71,7 +70,6 @@
if (provider != null) {
createTopic(PUSH_JMS_TOPIC, "/topic/" + PUSH_JMS_TOPIC);
createTopic(PUSH_TOPICS_CONTEXT_TOPIC, "/topic/" +
PUSH_TOPICS_CONTEXT_TOPIC);
- createTopic(METAMER_TOPIC, "/topic/" + METAMER_TOPIC);
}
}
@@ -165,4 +163,4 @@
}
}
-}
\ No newline at end of file
+}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsContextMessageProducer.java 2011-12-07
22:54:32 UTC (rev 23060)
@@ -21,9 +21,14 @@
*/
package org.richfaces.demo.push;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
import org.richfaces.application.push.MessageException;
import org.richfaces.application.push.TopicKey;
import org.richfaces.application.push.TopicsContext;
+import org.richfaces.tests.metamer.Message;
/**
* Sends message to topic using TopicsContext.
@@ -33,6 +38,9 @@
public class TopicsContextMessageProducer implements MessageProducer {
public static final String PUSH_TOPICS_CONTEXT_TOPIC =
"pushTopicsContext";
+
+ private String text = "Servus!";
+ private String author = "Janko Hrasko";
/*
* (non-Javadoc)
@@ -41,9 +49,14 @@
*/
public void sendMessage() throws Exception {
try {
- TopicKey topicKey = new TopicKey(PUSH_TOPICS_CONTEXT_TOPIC);
+ TopicKey topicKey = new TopicKey(PUSH_TOPICS_CONTEXT_TOPIC,
"xxx");
TopicsContext topicsContext = TopicsContext.lookup();
- topicsContext.publish(topicKey, "message");
+
+ DateFormat dateFormat = DateFormat.getDateTimeInstance();
+ dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
+ String dateMessage = dateFormat.format(new Date());
+
+ topicsContext.publish(topicKey, new Message(text, author, dateMessage));
} catch (MessageException e) {
if (!e.getMessage().matches("^Topic .* not found$")) {
throw e;
@@ -67,4 +80,20 @@
*/
public void finalizeProducer() {
}
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
}
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/demo/push/TopicsInitializer.java 2011-12-07
22:54:32 UTC (rev 23060)
@@ -23,7 +23,6 @@
import static org.richfaces.demo.push.JMSMessageProducer.PUSH_JMS_TOPIC;
import static
org.richfaces.demo.push.TopicsContextMessageProducer.PUSH_TOPICS_CONTEXT_TOPIC;
-import static org.richfaces.tests.metamer.bean.a4j.A4JPushBean.METAMER_TOPIC;
import java.util.logging.Logger;
@@ -56,7 +55,6 @@
new RegisterTopicThread(PUSH_JMS_TOPIC).start();
new RegisterTopicThread(PUSH_TOPICS_CONTEXT_TOPIC).start();
- new RegisterTopicThread(METAMER_TOPIC).start();
}
private class RegisterTopicThread extends Thread {
Modified:
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java
===================================================================
---
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/application/src/main/java/org/richfaces/tests/metamer/bean/a4j/A4JPushBean.java 2011-12-07
22:54:32 UTC (rev 23060)
@@ -37,6 +37,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static
org.richfaces.demo.push.TopicsContextMessageProducer.PUSH_TOPICS_CONTEXT_TOPIC;
+
/**
* Managed bean for a4j:push.
*
@@ -48,7 +50,6 @@
public class A4JPushBean implements Serializable {
private static final long serialVersionUID = 4810889475400649809L;
- public static final String METAMER_TOPIC = "metamer";
public static final String METAMER_SUBTOPIC = "xxx";
private static Logger logger;
@@ -131,7 +132,7 @@
try {
logger.info("sending message \"" + message + "\" by
user " + username);
Message msg = new Message(message, username, new Date().toString());
- getTopicsContext().publish(new TopicKey(METAMER_TOPIC, METAMER_SUBTOPIC),
msg);
+ getTopicsContext().publish(new TopicKey(PUSH_TOPICS_CONTEXT_TOPIC,
METAMER_SUBTOPIC), msg);
} catch (MessageException messageException) {
logger.error("Could not send message \"" + message +
"\" by user " + username + ".", messageException);
}
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/application/src/main/webapp/WEB-INF/faces-config.xml 2011-12-07
22:54:32 UTC (rev 23060)
@@ -13,14 +13,14 @@
<system-event-listener-class>org.richfaces.demo.push.TopicsInitializer</system-event-listener-class>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
</system-event-listener>
- <!-- system-event-listener>
+ <system-event-listener>
<system-event-listener-class>org.richfaces.demo.push.JMSMessageProducerInitializer</system-event-listener-class>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
- </system-event-listener-->
- <!-- system-event-listener>
+ </system-event-listener>
+ <system-event-listener>
<system-event-listener-class>org.richfaces.demo.push.TopicsContextMessageProducerInitializer</system-event-listener-class>
<system-event-class>javax.faces.event.PostConstructApplicationEvent</system-event-class>
- </system-event-listener-->
+ </system-event-listener>
</application>
<lifecycle>
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPush/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPush/simple.xhtml 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/a4jPush/simple.xhtml 2011-12-07
22:54:32 UTC (rev 23060)
@@ -45,7 +45,7 @@
<ul class="push-list"></ul>
- <a4j:push address="xxx@metamer" onerror="alert('Error:
' + event.rf.data)"
+ <a4j:push address="xxx@pushTopicsContext"
onerror="alert('Error: ' + event.rf.data)"
ondataavailable="updateList(event.rf.data)" >
</a4j:push>
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/push.js
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/push.js 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/application/src/main/webapp/resources/script/push.js 2011-12-07
22:54:32 UTC (rev 23060)
@@ -1,5 +1,6 @@
function updateList(data) {
author = '<span style="font-weight:bold"
class="author">' + data.author + '</span>: ';
message = '<span class="message">' + data.text +
'</span>';
- jQuery("ul.push-list").append('<li>' + author + message +
'</li>');
+ timestamp = ' <span>[' + data.timestamp + ']</span>';
+ jQuery("ul.push-list").append('<li>' + author + message +
timestamp + '</li>');
}
Deleted:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/PushAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/PushAttributes.java 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/PushAttributes.java 2011-12-07
22:54:32 UTC (rev 23060)
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * 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.a4jPush;
-
-import static org.jboss.test.selenium.locator.LocatorFactory.id;
-import static org.jboss.test.selenium.SeleniumGetter.*;
-
-import org.jboss.test.selenium.framework.AjaxSelenium;
-import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
-import org.jboss.test.selenium.locator.IdLocator;
-
-/**
- * The control point for setting different attributes for a4j:push test page.
- *
- * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
- * @version $Revision$
- */
-public class PushAttributes {
-
- private AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
-
- private IdLocator attributeInterval = id("form:attributes:intervalInput");
-
- public void setInterval(long miliseconds) {
- selenium.type(attributeInterval, String.valueOf(miliseconds));
- selenium.waitForPageToLoad();
- }
-
- public long getInterval() {
- return getValue(attributeInterval).asLong();
- }
-}
Deleted:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java 2011-12-07
17:02:26 UTC (rev 23059)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jPush/TestInterval.java 2011-12-07
22:54:32 UTC (rev 23060)
@@ -1,199 +0,0 @@
-/*******************************************************************************
- * 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.a4jPush;
-
-import static org.jboss.test.selenium.utils.PrimitiveUtils.asLong;
-import static org.jboss.test.selenium.utils.text.SimplifiedFormat.format;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.io.IOException;
-
-import org.apache.commons.httpclient.HttpException;
-import org.jboss.test.selenium.locator.Attribute;
-import org.jboss.test.selenium.locator.AttributeLocator;
-import org.richfaces.tests.metamer.ftest.annotations.Inject;
-import org.richfaces.tests.metamer.ftest.annotations.Templates;
-import org.richfaces.tests.metamer.ftest.annotations.Use;
-import org.testng.annotations.Test;
-
-/**
- * Tests the interval attribute for a4j:push
- *
- * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
- * @version $Revision$
- */
-public class TestInterval extends AbstractPushTest {
-
- private static final int DEFAULT_COUNTER_STEP = 2;
- private static final int ITERATION_COUNT = 3;
- private static final int MULTIPLE_PUSH_COUNT = 5;
-
- @Inject
- int interval;
-
- AttributeLocator<?> clientTime =
pjq("span[id$=clientDate\\:outputTime]").getAttribute(Attribute.TITLE);
-
- long startTime;
- int counter;
- int counterStep;
-
- long deviationTotal = 0;
- long deviationCount = 0;
-
- /**
- * <p>
- * For interval 1000, test that the interval between push event triggered and event
observered by client haven't
- * greater deviation than the one interval.
- * </p>
- *
- * <p>
- * First set the given interval into the interval attribute.
- * </p>
- *
- * <p>
- * Then push and wait for result of update triggered by observation of push event.
- * </p>
- *
- * <p>
- * Then repeat push and wait 6 times with 1 event triggered and 5 fast events
triggered in sequence.
- * </p>
- */
- @Test(enabled = false)
- @Use(field = "interval", ints = { 1000 })
- public void testClientAllTemplates() throws HttpException, IOException {
- testClient();
- }
-
- /**
- * <p>
- * For interval two different values (small and big), test that the interval between
push event triggered and event
- * observered by client haven't greater deviation than the one interval.
- * </p>
- *
- * <p>
- * First set the given interval into the interval attribute.
- * </p>
- *
- * <p>
- * Then push and wait for result of update triggered by observation of push event.
- * </p>
- *
- * <p>
- * Then repeat push and wait 6 times with 1 event triggered and 5 fast events
triggered in sequence.
- * </p>
- */
- @Test(enabled = false)
- @Use(field = "interval", ints = { 500, 5000 })
- @Templates(value = "plain")
- public void testClientDifferentIntervals() throws HttpException, IOException {
- testClient();
- }
-
- private void testClient() throws HttpException, IOException {
- counterStep = DEFAULT_COUNTER_STEP;
- pushAttributes.setInterval(interval);
-
- pushAndWait(1);
- for (int i = 0; i < ITERATION_COUNT; i++) {
- startIntervalAndCounter();
- pushAndWait(1);
- validateIntervalAndCounter();
-
- startIntervalAndCounter();
- pushAndWait(MULTIPLE_PUSH_COUNT);
- validateIntervalAndCounter();
- }
-
- validateAverageDeviation();
- }
-
- /**
- * Remembers start of the time frame and current value of counter.
- */
- private void startIntervalAndCounter() {
- startTime = getClientTime();
- counter = getCounter();
- }
-
- /**
- * <p>
- * Obtains current value of counter and end of the time frame to compute the run
time.
- * </p>
- *
- * <p>
- * Validates that run time haven't greater deviation from given maximum {@link
#MAX_DEVIATION}.
- * </p>
- *
- * <p>
- * Remembers the deviation as part of total deviation for computing average value.
- * </p>
- *
- * <p>
- * Validates that counter have been increased by right value.
- * </p>
- */
- private void validateIntervalAndCounter() {
- long runTime = getClientTime() - startTime;
- long deviation = Math.abs(interval - runTime);
-
- if (seleniumDebug) {
- System.out.println(format("deviation for interval {0}: {1}",
interval, deviation));
- }
-
- assertTrue(deviation <= (2 * interval),
- format("Deviation ({0}) is greater than two intervals (2 * {1})",
deviation, interval));
-
- deviationTotal += deviation;
- deviationCount += 1;
-
- int newCounter = getCounter();
- assertEquals(newCounter, counter + counterStep);
- counter = newCounter;
-
- }
-
- /**
- * Validates the average deviations from intervals.
- */
- private void validateAverageDeviation() {
- long maximumAvgDeviation = Math.min(interval / 4, 1000);
- long averageDeviation = deviationTotal / deviationCount;
- if (seleniumDebug) {
- System.out.println("averageDeviation: " + averageDeviation);
- }
- assertTrue(
- averageDeviation <= maximumAvgDeviation,
- format("Average deviation for all the intervals ({0}) should not be
greater than defined maximum {1}",
- averageDeviation, maximumAvgDeviation));
- }
-
- /**
- * Returns the time of push event (the time when arrived the response from server)
- *
- * @return the time of push event (the time when arrived the response from server)
- */
- private long getClientTime() {
- waitGui.until(attributePresent.locator(clientTime));
- return asLong(selenium.getAttribute(clientTime));
- }
-}