[jboss-svn-commits] JBL Code SVN: r22813 - in labs/jbossesb/workspace/skeagh/routing/jms/src: test/java/org/jboss/esb/jms and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 16 09:46:06 EDT 2008


Author: beve
Date: 2008-09-16 09:46:06 -0400 (Tue, 16 Sep 2008)
New Revision: 22813

Added:
   labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/MyTestService.java
Modified:
   labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
   labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java
   labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml
Log:
Updated test


Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java	2008-09-16 13:30:06 UTC (rev 22812)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/main/java/org/jboss/esb/jms/JmsInboundRouter.java	2008-09-16 13:46:06 UTC (rev 22813)
@@ -33,15 +33,37 @@
 import org.jboss.esb.annotations.Property;
 import org.jboss.esb.annotations.Uninitialize;
 import org.jboss.esb.annotations.Property.Use;
+import org.jboss.esb.context.DeploymentContext;
 import org.jboss.esb.context.InvocationContext;
 import org.jboss.esb.message.Message;
 import org.jboss.esb.routing.InboundRouter;
 import org.jboss.esb.routing.MessageDispatcher;
 import org.jboss.esb.routing.RoutingException;
+import org.jboss.esb.service.ServiceName;
 
 /**
  * Inbound router for JMS.
+ * <br><br>
+ * Sample usage:
+ * <br>
+ * <pre>{@code
+ * <inRouter name="inrouter1" class="org.jboss.esb.jms.JmsInboundRouter">
+ *     <property name="jmsDestination">jbossesb.TestQueue</property>
+ * </inRouter>
  *
+ * Optional properties (default shown):
+ *     <property name="extractProperties">true</property>
+ *     <property name="java.naming.provider.url">jnp://localhost:1099</property>
+ *     <property name="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</property>
+ *     <property name="java.naming.factory.url.pkgs">org.jboss.naming,org.jnp.interfaces</property>
+ *     <property name="org.jboss.esb.jms.connectionFactory">ConnectionFactory</property>
+ * }</pre>
+ * <br>
+ * Properties decription:
+ * <lu>
+ * <li>extractProperties true is JMS Headers and properties should be extracted and added to the invocation context</li>
+ * </lu>
+ *
  * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
  */
 public class JmsInboundRouter implements InboundRouter
@@ -57,6 +79,24 @@
     private MessageDispatcher dispatcher;
 
     /**
+     * Deployment context
+     */
+    @SuppressWarnings("unused")
+    private DeploymentContext deploymentContext;
+
+    /**
+     * The name of this object ('name' attribute from config).
+     */
+    @SuppressWarnings("unused")
+    private String objectName;
+
+    /**
+     * The service name of this service.
+     */
+    @SuppressWarnings("unused")
+    private ServiceName serviceName;
+
+    /**
      * JMS destination name.
      */
     @Property(use = Use.REQUIRED, name = "jmsDestination")
@@ -91,7 +131,7 @@
     @Initialize
     public final void initialize() throws JMSException
     {
-        log.info("JMSProperties : " + jmsProperties + "," + destination);
+        log.debug("JMSProperties : " + jmsProperties + "," + destination);
 
         // add this class as a JMS message listener...
         Destination jmsDestination = AbstractMessageHandler.lookupDestination(destination, jmsProperties);
@@ -102,12 +142,12 @@
             messageListener = new JmsMessageListener(destination, jmsSession, jmsProperties, dispatcher);
             messageListener.connect();
         }
-        catch (JMSException e)
+        catch (final JMSException e)
         {
             jmsSession.close();
             throw e;
         }
-        catch (Throwable t)
+        catch (final Throwable t)
         {
             jmsSession.close();
             throw (JMSException) (new JMSException("Unexpected exception while connecting JmsMesssageListener.").initCause(t));
@@ -159,7 +199,7 @@
     @Override
     public final String toString()
     {
-        return "[dispatcher=" + dispatcher + ", jmsProperties=" + jmsProperties + "]";
+        return "[dispatcher=" + dispatcher + ", extractProperties=" + extractProperties + ", jmsProperties=" + jmsProperties + "]";
     }
 
     /**
@@ -224,7 +264,6 @@
          */
         public void onMessage(final javax.jms.Message jmsMessage)
         {
-            log.info("jmsMessage recieved.....");
             try
             {
                 Message esbMessage = JmsInformationExtractor.extractPayload(jmsMessage);
@@ -234,13 +273,13 @@
                 {
                     Properties properties = JmsInformationExtractor.extractJmsProperties(jmsMessage);
                     context.set(JmsConstants.PROPERTIES, properties);
+                    log.debug(context.get(JmsConstants.PROPERTIES));
                 }
-                log.info(context.get(JmsConstants.PROPERTIES));
-
                 dispatcher.dispatch(esbMessage, context);
             }
             catch (RoutingException e)
             {
+                //TODO: Should errors be reported back to a caller. DLQ?
                 log.error("RoutingException in onMessage", e);
             }
             catch (JMSException e)

Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java	2008-09-16 13:30:06 UTC (rev 22812)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/JmsInboundRouterTest.java	2008-09-16 13:46:06 UTC (rev 22813)
@@ -20,15 +20,19 @@
  */
 package org.jboss.esb.jms;
 
-import org.jboss.esb.deploy.DeploymentRuntime;
-import org.jboss.esb.deploy.config.digest.DigestUtil;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
+import java.util.Properties;
+
 import javax.jms.Queue;
 import javax.jms.Session;
 import javax.jms.TextMessage;
-import java.util.Properties;
 
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.deploy.config.digest.DigestUtil;
+import org.junit.Test;
+
 /**
  * Test for {@link JmsInboundRouter}.
  *
@@ -37,53 +41,66 @@
 public class JmsInboundRouterTest
 {
     private static final String DESTINATION_NAME = "jbossesb.TestQueue";
+    private String messageContent = "Some text as payload";
 
     @Test
-    public final void initializeConfOverride() throws Exception
+    public final void recieveAndDispatch() throws Exception
     {
-        new JMSTestRunner()
+        new JmsInBoundRouterTestRunner("jms-inbound-router_01.xml").run();
+
+        assertNotNull(MyTestService.getMessage());
+        assertEquals(messageContent, MyTestService.getMessage().getPayload());
+    }
+
+    private class JmsInBoundRouterTestRunner extends JMSTestRunner
+    {
+        private String config;
+
+        public JmsInBoundRouterTestRunner(final String config)
         {
-            @Override
-            public void test() throws Exception
+            this.config = config;
+        }
+
+        @Override
+        public void test() throws Exception
+        {
+            DeploymentRuntime runtime = DigestUtil.digestConfig(getClass().getResourceAsStream(config));
+
+            runtime.deploy();
+            try
             {
-                DeploymentRuntime runtime = DigestUtil.digestConfig(getClass().getResourceAsStream("jms-inbound-router_01.xml"));
+                Thread.sleep(3000);
 
-                runtime.deploy();
+                Properties jndiProperties = getJndiProperties();
+                jndiProperties.setProperty("queue." + DESTINATION_NAME, DESTINATION_NAME);
+                JMSSession jmsSession = new JMSSession(Queue.class, jndiProperties);
+
+                jmsSession.connect();
                 try
                 {
-                    Thread.sleep(3000);
-
-                    Properties jndiProperties = getJndiProperties();
-                    jndiProperties.setProperty("queue." + DESTINATION_NAME, DESTINATION_NAME);
-                    JMSSession jmsSession = new JMSSession(Queue.class, jndiProperties);
-
-                    jmsSession.connect();
+                    MessageSender sender = new MessageSender(DESTINATION_NAME, jmsSession);
                     try
                     {
-                        MessageSender sender = new MessageSender(DESTINATION_NAME, jmsSession);
-                        try
-                        {
-                            sender.connect();
-                            Session session = sender.getSession();
-                            TextMessage textMessage = session.createTextMessage("test");
-                            sender.send(textMessage);
-                            Thread.sleep(3000);
-                        }
-                        finally
-                        {
-                            sender.close();
-                        }
+                        sender.connect();
+                        Session session = sender.getSession();
+                        TextMessage textMessage = session.createTextMessage(messageContent);
+                        sender.send(textMessage);
+                        Thread.sleep(3000);
                     }
                     finally
                     {
-                        jmsSession.close();
+                        sender.close();
                     }
                 }
                 finally
                 {
-                    runtime.undeploy();
+                    jmsSession.close();
                 }
             }
-        }.run();
+            finally
+            {
+                runtime.undeploy();
+            }
+        }
     }
 }

Added: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/MyTestService.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/MyTestService.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/MyTestService.java	2008-09-16 13:46:06 UTC (rev 22813)
@@ -0,0 +1,48 @@
+/*
+ * 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.jms;
+
+import org.jboss.esb.message.Message;
+import org.jboss.esb.service.Service;
+import org.jboss.esb.service.ServiceException;
+
+/**
+ * Simple Test service
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ */
+public class MyTestService implements Service
+{
+    private static Message message;
+
+    public Message process(Message message) throws ServiceException
+    {
+        MyTestService.message = message;
+        return message;
+    }
+
+    public static Message getMessage()
+    {
+        return message;
+    }
+
+
+
+}

Modified: labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml	2008-09-16 13:30:06 UTC (rev 22812)
+++ labs/jbossesb/workspace/skeagh/routing/jms/src/test/java/org/jboss/esb/jms/jms-inbound-router_01.xml	2008-09-16 13:46:06 UTC (rev 22813)
@@ -1,17 +1,19 @@
 <jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd">
 
+    <services>
+        <service serviceCategory="service-cat" serviceName="service-a" serviceDescription="TestService" class="org.jboss.esb.jms.MyTestService"/>
+    </services> 
+
     <routing>
         <inRouters serviceCategory="service-cat" serviceName="service-a">
-        
             <inRouter name="inrouter1" class="org.jboss.esb.jms.JmsInboundRouter">
                 <property name="java.naming.provider.url">tcp://localhost:61717</property>
                 <property name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</property>
                 <property name="jmsDestination">jbossesb.TestQueue</property>
-                <property name="extractProperties">true</property>
                 <property name="queue.jbossesb.TestQueue">jbossesb.TestQueue</property>
             </inRouter>
-            
         </inRouters>
     </routing>
+    
 
 </jbossesb>
\ No newline at end of file




More information about the jboss-svn-commits mailing list