You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2014/10/01 23:41:44 UTC

git commit: Initial implementation and test for creating a destination from string using connection destination prefix values.

Repository: qpid-jms
Updated Branches:
  refs/heads/master 1e0d838f3 -> eec45adec


Initial implementation and test for creating a destination from string
using connection destination prefix values.

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/eec45ade
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/eec45ade
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/eec45ade

Branch: refs/heads/master
Commit: eec45adec3b052a8feef6a7481eaba83caaccb18
Parents: 1e0d838
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Oct 1 17:41:36 2014 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Oct 1 17:41:36 2014 -0400

----------------------------------------------------------------------
 .../amqp/message/AmqpDestinationHelper.java     | 32 +++++++
 .../amqp/message/AmqpJmsMessageFacade.java      |  5 +-
 .../amqp/message/AmqpDestinationHelperTest.java | 88 ++++++++++++++++++++
 3 files changed, 122 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/eec45ade/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelper.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelper.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelper.java
index fdc9a75..d1ebd8a 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelper.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelper.java
@@ -24,6 +24,7 @@ import org.apache.qpid.jms.JmsQueue;
 import org.apache.qpid.jms.JmsTemporaryQueue;
 import org.apache.qpid.jms.JmsTemporaryTopic;
 import org.apache.qpid.jms.JmsTopic;
+import org.apache.qpid.jms.provider.amqp.AmqpConnection;
 
 /**
  * A set of static utility method useful when mapping JmsDestination types to / from the AMQP
@@ -58,6 +59,37 @@ public class AmqpDestinationHelper {
      */
 
     /**
+     * Given a destination name string, create a JmsDestination object based on the
+     * configured destination prefix values.  If no prefix values are configured or the
+     * name has no matching prefix we create a Queue instance by default.
+     *
+     * @param destinationName
+     *        the name to use to construct the new JmsDestination instance.
+     * @param connection
+     *        the connection where this destination will be handled.
+     *
+     * @throws NullPointerException if destinationName or connection is null.
+     */
+    public JmsDestination createDestination(String destinationName, AmqpConnection connection) {
+
+        JmsDestination result = null;
+
+        if (connection.getQueuePrefix() != null && destinationName.startsWith(connection.getQueuePrefix())) {
+            result = new JmsQueue(destinationName.substring(connection.getQueuePrefix().length()));
+        } else if (connection.getTopicPrefix() != null && destinationName.startsWith(connection.getTopicPrefix())) {
+            result = new JmsTopic(destinationName.substring(connection.getTopicPrefix().length()));
+        } else if (connection.getTempQueuePrefix() != null && destinationName.startsWith(connection.getTempQueuePrefix())) {
+            result = new JmsTemporaryQueue(destinationName.substring(connection.getTempQueuePrefix().length()));
+        } else if (connection.getTempTopicPrefix() != null && destinationName.startsWith(connection.getTempTopicPrefix())) {
+            result = new JmsTemporaryTopic(destinationName.substring(connection.getTempTopicPrefix().length()));
+        } else {
+            result = new JmsQueue(destinationName);
+        }
+
+        return result;
+    }
+
+    /**
      * Decode the provided To address, type description, and consumer destination
      * information such that an appropriate Destination object can be returned.
      *

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/eec45ade/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
index f48bd24..1859a47 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
@@ -34,7 +34,6 @@ import javax.jms.JMSException;
 import javax.jms.MessageFormatException;
 
 import org.apache.qpid.jms.JmsDestination;
-import org.apache.qpid.jms.JmsQueue;
 import org.apache.qpid.jms.exceptions.IdConversionException;
 import org.apache.qpid.jms.message.facade.JmsMessageFacade;
 import org.apache.qpid.jms.provider.amqp.AmqpConnection;
@@ -632,7 +631,7 @@ public class AmqpJmsMessageFacade implements JmsMessageFacade {
 
     @Override
     public void setDestinationFromString(String destination) {
-        setDestination(new JmsQueue(destination));
+        setDestination(AmqpDestinationHelper.INSTANCE.createDestination(destination, connection));
     }
 
     @Override
@@ -653,7 +652,7 @@ public class AmqpJmsMessageFacade implements JmsMessageFacade {
 
     @Override
     public void setReplyToFromString(String destination) {
-        setReplyTo(new JmsQueue(destination));
+        setReplyTo(AmqpDestinationHelper.INSTANCE.createDestination(destination, connection));
     }
 
     public void setReplyToGroupId(String replyToGroupId) {

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/eec45ade/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelperTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelperTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelperTest.java
index 49fc17d..b7cfbcc 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelperTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpDestinationHelperTest.java
@@ -37,6 +37,7 @@ import org.apache.qpid.jms.JmsQueue;
 import org.apache.qpid.jms.JmsTemporaryQueue;
 import org.apache.qpid.jms.JmsTemporaryTopic;
 import org.apache.qpid.jms.JmsTopic;
+import org.apache.qpid.jms.provider.amqp.AmqpConnection;
 import org.junit.Test;
 import org.mockito.Mockito;
 
@@ -44,6 +45,93 @@ public class AmqpDestinationHelperTest {
 
     private final AmqpDestinationHelper helper = AmqpDestinationHelper.INSTANCE;
 
+    private static final String QUEUE_PREFIX = "queue://";
+    private static final String TOPIC_PREFIX = "topic://";
+    private static final String TEMP_QUEUE_PREFIX = "temp-queue://";
+    private static final String TEMP_TOPIC_PREFIX = "temp-topic://";
+
+    private AmqpConnection createConnectionWithDestinationPrefixValues() {
+        AmqpConnection connection = Mockito.mock(AmqpConnection.class);
+        Mockito.when(connection.getQueuePrefix()).thenReturn(QUEUE_PREFIX);
+        Mockito.when(connection.getTopicPrefix()).thenReturn(TOPIC_PREFIX);
+        Mockito.when(connection.getTempQueuePrefix()).thenReturn(TEMP_QUEUE_PREFIX);
+        Mockito.when(connection.getTempTopicPrefix()).thenReturn(TEMP_TOPIC_PREFIX);
+
+        return connection;
+    }
+
+    //--------------- Test createDestination method --------------------------//
+
+    @Test(expected=NullPointerException.class)
+    public void testCreateDestinationFromStringWithNullConnection() {
+        helper.createDestination("testName", null);
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testCreateDestinationFromNullStringWithConnection() {
+        helper.createDestination(null, createConnectionWithDestinationPrefixValues());
+    }
+
+    @Test(expected=NullPointerException.class)
+    public void testCreateDestinationFromNullStringAndConnection() {
+        helper.createDestination(null, null);
+    }
+
+    @Test
+    public void testCreateDestinationFromStringNoPrefixReturnsQueue() {
+        String destinationName = "testDestinationName";
+        AmqpConnection connection = createConnectionWithDestinationPrefixValues();
+        JmsDestination result = helper.createDestination(destinationName, connection);
+        assertNotNull(result);
+        assertTrue(result.isQueue());
+        assertFalse(result.isTemporary());
+        assertEquals(destinationName, result.getName());
+    }
+
+    @Test
+    public void testCreateDestinationFromQeueuePrefixedString() {
+        String destinationName = "testDestinationName";
+        AmqpConnection connection = createConnectionWithDestinationPrefixValues();
+        JmsDestination result = helper.createDestination(QUEUE_PREFIX + destinationName, connection);
+        assertNotNull(result);
+        assertTrue(result.isQueue());
+        assertFalse(result.isTemporary());
+        assertEquals(destinationName, result.getName());
+    }
+
+    @Test
+    public void testCreateDestinationFromTopicPrefixedString() {
+        String destinationName = "testDestinationName";
+        AmqpConnection connection = createConnectionWithDestinationPrefixValues();
+        JmsDestination result = helper.createDestination(TOPIC_PREFIX + destinationName, connection);
+        assertNotNull(result);
+        assertTrue(result.isTopic());
+        assertFalse(result.isTemporary());
+        assertEquals(destinationName, result.getName());
+    }
+
+    @Test
+    public void testCreateDestinationFromTempQueuePrefixedString() {
+        String destinationName = "testDestinationName";
+        AmqpConnection connection = createConnectionWithDestinationPrefixValues();
+        JmsDestination result = helper.createDestination(TEMP_QUEUE_PREFIX + destinationName, connection);
+        assertNotNull(result);
+        assertTrue(result.isQueue());
+        assertTrue(result.isTemporary());
+        assertEquals(destinationName, result.getName());
+    }
+
+    @Test
+    public void testCreateDestinationFromTempTopicPrefixedString() {
+        String destinationName = "testDestinationName";
+        AmqpConnection connection = createConnectionWithDestinationPrefixValues();
+        JmsDestination result = helper.createDestination(TEMP_TOPIC_PREFIX + destinationName, connection);
+        assertNotNull(result);
+        assertTrue(result.isTopic());
+        assertTrue(result.isTemporary());
+        assertEquals(destinationName, result.getName());
+    }
+
     //--------------- Test getJmsDestination method --------------------------//
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org