[jboss-svn-commits] JBL Code SVN: r22772 - in labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus: jms and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Sep 15 06:36:00 EDT 2008
Author: tfennelly
Date: 2008-09-15 06:35:59 -0400 (Mon, 15 Sep 2008)
New Revision: 22772
Added:
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/JMSBusTest.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/jmsbus.properties
Log:
JMSBus Test
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/JMSBusTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/JMSBusTest.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/JMSBusTest.java 2008-09-15 10:35:59 UTC (rev 22772)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.federate.bus.jms;
+
+import junit.framework.TestCase;
+import org.jboss.esb.deploy.DeploymentException;
+import org.jboss.esb.federate.bus.BusMessage;
+import org.jboss.esb.federate.bus.BusMessageListener;
+import org.jboss.esb.federate.notify.NotificationListener;
+import org.jboss.esb.federate.notify.AbstractDeploymentNotification;
+import org.jboss.esb.federate.notify.DeploymentHeartbeatNotification;
+import org.jboss.esb.jms.JMSTestRunner;
+import org.jboss.esb.properties.ApplicationProperties;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JMSBusTest extends TestCase
+{
+ public void test_send_message() throws Exception
+ {
+ new JMSTestRunner()
+ {
+ public void test() throws Exception
+ {
+ JMSBus interface1 = createBusInterfaceInstance("deployment1");
+ TestBusMessageListener interface1Listener = new TestBusMessageListener();
+ interface1.setBusMessageListener(interface1Listener);
+ try
+ {
+ JMSBus interface2 = createBusInterfaceInstance("deployment2");
+ TestBusMessageListener interface2Listener = new TestBusMessageListener();
+ interface2.setBusMessageListener(interface2Listener);
+ try
+ {
+ JMSBus interface3 = createBusInterfaceInstance("deployment3");
+ TestBusMessageListener interface3Listener = new TestBusMessageListener();
+ interface3.setBusMessageListener(interface3Listener);
+ try
+ {
+ BusMessage message = new BusMessage();
+
+ // Send a message from deployment1 to deployment2
+ assertEquals(0, interface1Listener.messagesReceived.size());
+ assertEquals(0, interface2Listener.messagesReceived.size());
+ assertEquals(0, interface3Listener.messagesReceived.size());
+ interface1.send(message, "deployment2");
+ Thread.sleep(100);
+ assertEquals(0, interface1Listener.messagesReceived.size());
+ assertEquals(1, interface2Listener.messagesReceived.size());
+ assertEquals(0, interface3Listener.messagesReceived.size());
+ interface2Listener.messagesReceived.clear();
+
+ // Send a message from deployment2 to deployment3
+ assertEquals(0, interface1Listener.messagesReceived.size());
+ assertEquals(0, interface2Listener.messagesReceived.size());
+ assertEquals(0, interface3Listener.messagesReceived.size());
+ interface2.send(message, "deployment3");
+ Thread.sleep(100);
+ assertEquals(0, interface1Listener.messagesReceived.size());
+ assertEquals(0, interface2Listener.messagesReceived.size());
+ assertEquals(1, interface3Listener.messagesReceived.size());
+ interface3Listener.messagesReceived.clear();
+
+ // Send a message from deployment3 to deployment1
+ assertEquals(0, interface1Listener.messagesReceived.size());
+ assertEquals(0, interface2Listener.messagesReceived.size());
+ assertEquals(0, interface3Listener.messagesReceived.size());
+ interface3.send(message, "deployment1");
+ Thread.sleep(100);
+ assertEquals(1, interface1Listener.messagesReceived.size());
+ assertEquals(0, interface2Listener.messagesReceived.size());
+ assertEquals(0, interface3Listener.messagesReceived.size());
+ interface1Listener.messagesReceived.clear();
+ }
+ finally
+ {
+ interface3.close();
+ }
+ }
+ finally
+ {
+ interface2.close();
+ }
+ }
+ finally
+ {
+ interface1.close();
+ }
+ }
+ }.run();
+ }
+
+ public void test_send_notification() throws Exception
+ {
+ new JMSTestRunner()
+ {
+ public void test() throws Exception
+ {
+ JMSBus interface1 = createBusInterfaceInstance("deployment1");
+ TestNotificationListener interface1Listener = new TestNotificationListener();
+ interface1.setNotificationListener(interface1Listener);
+ try
+ {
+ JMSBus interface2 = createBusInterfaceInstance("deployment2");
+ TestNotificationListener interface2Listener = new TestNotificationListener();
+ interface2.setNotificationListener(interface2Listener);
+ try
+ {
+ JMSBus interface3 = createBusInterfaceInstance("deployment3");
+ TestNotificationListener interface3Listener = new TestNotificationListener();
+ interface3.setNotificationListener(interface3Listener);
+ try
+ {
+ DeploymentHeartbeatNotification notification = new DeploymentHeartbeatNotification();
+
+ // deployment1 send a notification...
+ assertEquals(0, interface1Listener.notificationsReceived.size());
+ assertEquals(0, interface2Listener.notificationsReceived.size());
+ assertEquals(0, interface3Listener.notificationsReceived.size());
+ interface1.sendNotification(notification);
+ Thread.sleep(100);
+ assertEquals(0, interface1Listener.notificationsReceived.size());
+ assertEquals(1, interface2Listener.notificationsReceived.size());
+ assertEquals(1, interface3Listener.notificationsReceived.size());
+ interface2Listener.notificationsReceived.clear();
+ interface3Listener.notificationsReceived.clear();
+
+ // deployment2 send a notification...
+ assertEquals(0, interface1Listener.notificationsReceived.size());
+ assertEquals(0, interface2Listener.notificationsReceived.size());
+ assertEquals(0, interface3Listener.notificationsReceived.size());
+ interface2.sendNotification(notification);
+ Thread.sleep(100);
+ assertEquals(1, interface1Listener.notificationsReceived.size());
+ assertEquals(0, interface2Listener.notificationsReceived.size());
+ assertEquals(1, interface3Listener.notificationsReceived.size());
+ interface1Listener.notificationsReceived.clear();
+ interface3Listener.notificationsReceived.clear();
+
+ // deployment3 send a notification...
+ assertEquals(0, interface1Listener.notificationsReceived.size());
+ assertEquals(0, interface2Listener.notificationsReceived.size());
+ assertEquals(0, interface3Listener.notificationsReceived.size());
+ interface3.sendNotification(notification);
+ Thread.sleep(100);
+ assertEquals(1, interface1Listener.notificationsReceived.size());
+ assertEquals(1, interface2Listener.notificationsReceived.size());
+ assertEquals(0, interface3Listener.notificationsReceived.size());
+ interface1Listener.notificationsReceived.clear();
+ interface3Listener.notificationsReceived.clear();
+ }
+ finally
+ {
+ interface3.close();
+ }
+ }
+ finally
+ {
+ interface2.close();
+ }
+ }
+ finally
+ {
+ interface1.close();
+ }
+ }
+ }.run();
+ }
+
+ private JMSBus createBusInterfaceInstance(String name) throws IOException, DeploymentException, InterruptedException
+ {
+ JMSBus busInterface1 = new JMSBus();
+ ApplicationProperties properties = ApplicationProperties.loadProperties(getClass().getResourceAsStream("jmsbus.properties"));
+
+ busInterface1.setDeploymentName(name);
+ busInterface1.setDeploymentId(name); // using the name as the ID for testing
+ busInterface1.setProperties(properties);
+ busInterface1.connect();
+
+ Thread.sleep(500);
+
+ return busInterface1;
+ }
+
+ private class TestBusMessageListener implements BusMessageListener
+ {
+ private List<BusMessage> messagesReceived = new ArrayList<BusMessage>();
+ public void onMessage(BusMessage busMessage)
+ {
+ messagesReceived.add(busMessage);
+ }
+ }
+
+ private class TestNotificationListener implements NotificationListener
+ {
+ private List<AbstractDeploymentNotification> notificationsReceived = new ArrayList<AbstractDeploymentNotification>();
+
+ public void onNotification(AbstractDeploymentNotification notification)
+ {
+ notificationsReceived.add(notification);
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/JMSBusTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/jmsbus.properties (from rev 22770, labs/jbossesb/workspace/skeagh/runtime/src/test/resources/META-INF/jbossesb/busconfig/jms/default.properties)
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/jmsbus.properties (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/jmsbus.properties 2008-09-15 10:35:59 UTC (rev 22772)
@@ -0,0 +1,18 @@
+###########################################################################################
+# Using ActiveMQ because it's so easy to embed. Apparently JBM v2.0 will also be
+# easy to embed. We might be able to switch to that then!!
+##########################################################################################
+
+# JNDI Settings...
+# NOTE: The JNDI settings in this config file must be the same as those
+# set in the JMSTestRunner class!!
+java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
+java.naming.provider.url=tcp://localhost:61717
+
+# Bus Queues and Topics...
+deployment.coordintation.topic=jbossesb.deployment.coordintation.topic
+deployment.bus.queue=jbossesb.jms.bus
+
+# ActiveMQ Queue and Topic deployments...
+topic.jbossesb.deployment.coordintation.topic=jbossesb.deployment.coordintation.topic
+queue.jbossesb.jms.bus=jbossesb.jms.bus
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/federate/bus/jms/jmsbus.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list