[jboss-cvs] JBoss Messaging SVN: r5273 - in trunk: tests/src/org/jboss/messaging/tests/unit/core and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 5 05:00:49 EST 2008
Author: jmesnil
Date: 2008-11-05 05:00:49 -0500 (Wed, 05 Nov 2008)
New Revision: 5273
Added:
trunk/tests/src/org/jboss/messaging/tests/unit/core/messagecounter/
trunk/tests/src/org/jboss/messaging/tests/unit/core/messagecounter/impl/
trunk/tests/src/org/jboss/messaging/tests/unit/core/messagecounter/impl/MessageCounterHelperTest.java
Modified:
trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java
Log:
JBMESSAGING-732: Improve message counter functionality
updated the HTML String returned by the MessageCounterHelper so that it is well-formed and can be fed to a XML parser
Modified: trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java 2008-11-05 09:23:06 UTC (rev 5272)
+++ trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java 2008-11-05 10:00:49 UTC (rev 5273)
@@ -18,7 +18,7 @@
* 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.jboss.messaging.core.messagecounter.impl;
@@ -49,17 +49,18 @@
if (counters == null)
return null;
- String ret = "<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">"
- + "<tr>"
- + "<th>Type</th>"
- + "<th>Name</th>"
- + "<th>Subscription</th>"
- + "<th>Durable</th>"
- + "<th>Count</th>"
- + "<th>CountDelta</th>"
- + "<th>Depth</th>"
- + "<th>DepthDelta</th>"
- + "<th>Last Add</th>" + "</tr>";
+ String ret = "<table class=\"jbm-message-counter\">\n"
+ + "<tr>"
+ + "<th>Type</th>"
+ + "<th>Name</th>"
+ + "<th>Subscription</th>"
+ + "<th>Durable</th>"
+ + "<th>Count</th>"
+ + "<th>CountDelta</th>"
+ + "<th>Depth</th>"
+ + "<th>DepthDelta</th>"
+ + "<th>Last Add</th>"
+ + "</tr>\n";
for (int i = 0; i < counters.length; i++)
{
@@ -67,8 +68,7 @@
StringTokenizer token = new StringTokenizer(data, ",");
String value;
- ret += "<tr bgcolor=\"#" + ((i % 2) == 0 ? "FFFFFF" : "F0F0F0")
- + "\">";
+ ret += "<tr bgcolor=\"#" + ((i % 2) == 0 ? "FFFFFF" : "F0F0F0") + "\">";
ret += "<td>" + token.nextToken() + "</td>"; // type
ret += "<td>" + token.nextToken() + "</td>"; // name
@@ -95,10 +95,10 @@
ret += "<td>" + token.nextToken() + "</td>"; // date last add
- ret += "</tr>";
+ ret += "</tr>\n";
}
- ret += "</table>";
+ ret += "</table>\n";
return ret;
}
@@ -108,30 +108,37 @@
if (counters == null)
return null;
- String ret = "";
+ String ret = "<ul>\n";
for (int i = 0; i < counters.length; i++)
{
+ ret += "<li>\n";
+ ret += " <ul>\n";
+
+ ret += " <li>";
// destination name
- ret += (counters[i].getDestinationTopic() ? "Topic '" : "Queue '");
- ret += counters[i].getDestinationName() + "'";
+ ret += (counters[i].getDestinationTopic() ? "Topic '" : "Queue '") + counters[i].getDestinationName() + "'";
+ ret += "</li>\n";
if (counters[i].getDestinationSubscription() != null)
- ret += "Subscription '" + counters[i].getDestinationSubscription()
- + "'";
+ {
+ ret += " <li>";
+ ret += "Subscription '" + counters[i].getDestinationSubscription() + "'";
+ ret += "</li>\n";
+ }
+ ret += " <li>";
// table header
- ret += "<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">"
- + "<tr>" + "<th>Date</th>";
+ ret += "<table class=\"jbm-message-counter-history\">\n";
+ ret += "<tr><th>Date</th>";
for (int j = 0; j < 24; j++)
- ret += "<th width=\"4%\">" + j + "</th>";
+ ret += "<th>" + j + "</th>";
- ret += "<th>Total</th></tr>";
+ ret += "<th>Total</th></tr>\n";
// get history data as CSV string
- StringTokenizer tokens = new StringTokenizer(counters[i]
- .getHistoryAsString(), ",\n");
+ StringTokenizer tokens = new StringTokenizer(counters[i].getHistoryAsString(), ",\n");
// get history day count
int days = Integer.parseInt(tokens.nextToken());
@@ -139,8 +146,7 @@
for (int j = 0; j < days; j++)
{
// next day counter row
- ret += "<tr bgcolor=\"#" + ((j % 2) == 0 ? "FFFFFF" : "F0F0F0")
- + "\">";
+ ret += "<tr bgcolor=\"#" + ((j % 2) == 0 ? "FFFFFF" : "F0F0F0") + "\">";
// date
ret += "<td>" + tokens.nextToken() + "</td>";
@@ -155,7 +161,8 @@
if (value == -1)
{
ret += "<td></td>";
- } else
+ }
+ else
{
ret += "<td>" + value + "</td>";
@@ -163,15 +170,19 @@
}
}
- ret += "<td>" + total + "</td></tr>";
+ ret += "<td>" + total + "</td></tr>\n";
}
- ret += "</table><br><br>";
+ ret += "</table></li>\n";
+ ret += " </ul>\n";
+ ret += "</li>\n";
}
+ ret += "</ul>\n";
+
return ret;
}
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/messagecounter/impl/MessageCounterHelperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/messagecounter/impl/MessageCounterHelperTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/messagecounter/impl/MessageCounterHelperTest.java 2008-11-05 10:00:49 UTC (rev 5273)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, 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.jboss.messaging.tests.unit.core.messagecounter.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.jboss.messaging.tests.util.RandomUtil.randomBoolean;
+import static org.jboss.messaging.tests.util.RandomUtil.randomPositiveInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.messagecounter.MessageCounter;
+import org.jboss.messaging.core.messagecounter.impl.MessageCounterHelper;
+import org.jboss.messaging.core.server.Queue;
+import org.xml.sax.InputSource;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * A MessageCounterHelperTest
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ */
+public class MessageCounterHelperTest extends TestCase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testMessageCounterHistoryAsHTMLIsWellFormedIsWellFormed() throws Exception
+ {
+ Queue queue = createMock(Queue.class);
+ MessageCounter counter1 = new MessageCounter(randomString(),
+ randomString(),
+ queue,
+ randomBoolean(),
+ randomBoolean(),
+ 7);
+ MessageCounter counter2 = new MessageCounter(randomString(),
+ randomString(),
+ queue,
+ randomBoolean(),
+ randomBoolean(),
+ 7);
+ MessageCounter[] counters = new MessageCounter[] { counter1, counter2 };
+
+ replay(queue);
+
+ String historyHTML = MessageCounterHelper.listMessageCounterHistoryAsHTML(counters);
+ assertWellFormedXML(historyHTML);
+
+ verify(queue);
+ }
+
+ public void testMessageCounterAsHTMLIsWellFormed() throws Exception
+ {
+ Queue queue1 = createMock(Queue.class);
+ expect(queue1.getMessageCount()).andStubReturn(randomPositiveInt());
+ MessageCounter counter1 = new MessageCounter(randomString(),
+ randomString(),
+ queue1,
+ randomBoolean(),
+ randomBoolean(),
+ 7);
+ Queue queue2 = createMock(Queue.class);
+ expect(queue2.getMessageCount()).andStubReturn(randomPositiveInt());
+ MessageCounter counter2 = new MessageCounter(randomString(),
+ randomString(),
+ queue2,
+ randomBoolean(),
+ randomBoolean(),
+ 7);
+ MessageCounter[] counters = new MessageCounter[] { counter1, counter2 };
+
+ replay(queue1, queue2);
+
+ String countersHTML = MessageCounterHelper.listMessageCounterAsHTML(counters);
+ assertWellFormedXML(countersHTML);
+
+ verify(queue1, queue2);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private static void assertWellFormedXML(String xmlASstring) throws Exception
+ {
+ SAXParserFactory spfactory = SAXParserFactory.newInstance();
+ SAXParser saxParser = spfactory.newSAXParser();
+
+ StringReader reader = new StringReader(xmlASstring);
+ // if the xml is not well-formed, an exception is thrown
+ saxParser.parse(new InputSource(reader), new DefaultHandler());
+ }
+
+ // Inner classes -------------------------------------------------
+
+}
More information about the jboss-cvs-commits
mailing list