You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by gt...@apache.org on 2010/03/03 11:35:17 UTC

svn commit: r918388 - in /activemq/branches/activemq-5.3/activemq-core/src: main/java/org/apache/activemq/command/ActiveMQDestination.java test/java/org/apache/activemq/command/ActiveMQDestinationTest.java

Author: gtully
Date: Wed Mar  3 10:35:17 2010
New Revision: 918388

URL: http://svn.apache.org/viewvc?rev=918388&view=rev
Log:
merge -c 918381 https://svn.apache.org/repos/asf/activemq/trunk - resolve https://issues.apache.org/activemq/browse/AMQ-2630 - added test and restricted imlementation

Modified:
    activemq/branches/activemq-5.3/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
    activemq/branches/activemq-5.3/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java

Modified: activemq/branches/activemq-5.3/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-5.3/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java?rev=918388&r1=918387&r2=918388&view=diff
==============================================================================
--- activemq/branches/activemq-5.3/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java (original)
+++ activemq/branches/activemq-5.3/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java Wed Mar  3 10:35:17 2010
@@ -117,6 +117,17 @@
         if (dest instanceof ActiveMQDestination) {
             return (ActiveMQDestination)dest;
         }
+        
+        if (dest instanceof Queue && dest instanceof Topic) {
+            String queueName = ((Queue) dest).getQueueName();
+            String topicName = ((Topic) dest).getTopicName();
+            if (queueName != null && topicName == null) {
+                return new ActiveMQQueue(queueName);
+            } else if (queueName == null && topicName != null) {
+                return new ActiveMQTopic(topicName);
+            }
+            throw new JMSException("Could no disambiguate on queue|Topic-name totransform pollymorphic destination into a ActiveMQ destination: " + dest);
+        }
         if (dest instanceof TemporaryQueue) {
             return new ActiveMQTempQueue(((TemporaryQueue)dest).getQueueName());
         }

Modified: activemq/branches/activemq-5.3/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-5.3/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java?rev=918388&r1=918387&r2=918388&view=diff
==============================================================================
--- activemq/branches/activemq-5.3/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java (original)
+++ activemq/branches/activemq-5.3/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java Wed Mar  3 10:35:17 2010
@@ -24,6 +24,12 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.Topic;
+
 import junit.framework.Test;
 
 public class ActiveMQDestinationTest extends DataStructureTestSupport {
@@ -71,6 +77,46 @@
         assertEquals("Sorted order", expected, actual);
     }
 
+    // https://issues.apache.org/activemq/browse/AMQ-2630
+    class CombyDest implements Queue, Topic, TemporaryQueue, TemporaryTopic {
+
+        private final String qName;
+        private final String topicName;
+
+        public CombyDest(String qName, String topicName) {
+            this.qName = qName;
+            this.topicName = topicName;
+        }
+        
+        public void delete() throws JMSException {
+        }
+
+        public String getTopicName() throws JMSException {
+            return topicName;
+        }
+
+        public String getQueueName() throws JMSException {
+            return qName;
+        }    
+    }
+    
+    public void testTransformPollymorphic() throws Exception {
+        ActiveMQQueue queue = new ActiveMQQueue("TEST");
+        assertEquals(ActiveMQDestination.transform(queue), queue);
+        assertTrue("is a q", ActiveMQDestination.transform(new CombyDest(null, "Topic")) instanceof ActiveMQTopic);
+        assertTrue("is a q", ActiveMQDestination.transform(new CombyDest("Q", null)) instanceof ActiveMQQueue);
+        try {
+            ActiveMQDestination.transform(new CombyDest(null, null));
+            fail("expect ex as cannot disambiguate");
+        } catch (JMSException expected) { 
+        } 
+        try {
+            ActiveMQDestination.transform(new CombyDest("Q", "T"));
+            fail("expect ex as cannot disambiguate");
+        } catch (JMSException expected) { 
+        }
+    }
+    
     public static Test suite() {
         return suite(ActiveMQDestinationTest.class);
     }