resolve https://issues.apache.org/activemq/browse/AMQ-2630 - added test and restricted imlementation

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@918381 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2010-03-03 10:15:10 +00:00
parent f782fc0b4a
commit f33e2190d0
2 changed files with 57 additions and 0 deletions

View File

@ -117,6 +117,17 @@ public abstract class ActiveMQDestination extends JNDIBaseStorable implements Da
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());
}

View File

@ -24,6 +24,12 @@ import java.util.Map;
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 @@ public class ActiveMQDestinationTest extends DataStructureTestSupport {
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);
}