Repository: qpid-jms Updated Branches: refs/heads/master bec6b5cec -> 7525ab93e
Add some additional tests for handling unresolved foreign destination types. Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/7525ab93 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/7525ab93 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/7525ab93 Branch: refs/heads/master Commit: 7525ab93e2802be8d35120dad1585821dc859533 Parents: bec6b5c Author: Timothy Bish <tabish...@gmail.com> Authored: Thu Oct 16 09:59:51 2014 -0400 Committer: Timothy Bish <tabish...@gmail.com> Committed: Thu Oct 16 09:59:51 2014 -0400 ---------------------------------------------------------------------- ...ultUnresolvedDestinationTransformerTest.java | 178 +++++++++++++++++++ 1 file changed, 178 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7525ab93/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsDefaultUnresolvedDestinationTransformerTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsDefaultUnresolvedDestinationTransformerTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsDefaultUnresolvedDestinationTransformerTest.java new file mode 100644 index 0000000..89d1391 --- /dev/null +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsDefaultUnresolvedDestinationTransformerTest.java @@ -0,0 +1,178 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.qpid.jms.message; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Queue; +import javax.jms.Topic; + +import org.apache.qpid.jms.JmsDestination; +import org.apache.qpid.jms.JmsQueue; +import org.apache.qpid.jms.JmsTopic; +import org.junit.Test; +import org.mockito.Mockito; + +public class JmsDefaultUnresolvedDestinationTransformerTest { + + private final JmsDefaultUnresolvedDestinationTransformer transformer = new JmsDefaultUnresolvedDestinationTransformer(); + + @Test + public void testTransformDestinationDestinationWithNoNameThrowsJMSEx() throws JMSException { + Destination destination = Mockito.mock(Destination.class); + try { + transformer.transform(destination); + fail("Should throw a JMSException here"); + } catch (JMSException ex) { + } + } + + @Test + public void testTransformDestinationDestinationWithoutTypeThrowsJMSEx() throws JMSException { + ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); + destination.setTopic(false); + destination.setQueue(false); + + try { + transformer.transform(destination); + fail("Should throw a JMSException here"); + } catch (JMSException ex) { + } + } + + @Test + public void testTopicTypeIsDetectedFromComposite() throws JMSException { + ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); + destination.setQueue(false); + + JmsDestination result = transformer.transform(destination); + + assertNotNull(result); + assertTrue(result instanceof JmsTopic); + } + + @Test + public void testQueueTypeIsDetectedFromComposite() throws JMSException { + ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); + destination.setTopic(false); + + JmsDestination result = transformer.transform(destination); + + assertNotNull(result); + assertTrue(result instanceof JmsQueue); + } + + @Test + public void testTopicTypeIsDetectedFromCompositeMisMatchedNameAndType() throws JMSException { + ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); + destination.setQueue(false); + destination.setReturnTopicName(false); + + JmsDestination result = transformer.transform(destination); + + assertNotNull(result); + assertTrue(result instanceof JmsTopic); + } + + @Test + public void testQueueTypeIsDetectedFromCompositeMisMatchedNameAndType() throws JMSException { + ForeignTopicAndQueue destination = new ForeignTopicAndQueue("destination"); + destination.setTopic(false); + destination.setReturnQueueName(false); + + JmsDestination result = transformer.transform(destination); + + assertNotNull(result); + assertTrue(result instanceof JmsQueue); + } + + @Test + public void testTransformStringAlwaysAnswersQueue() throws JMSException { + JmsDestination destination = transformer.transform("test"); + assertNotNull(destination); + assertTrue(destination instanceof JmsQueue); + } + + @Test(expected=JMSException.class) + public void testTransformStringWithNullThrowsJMSEx() throws JMSException { + transformer.transform((String) null); + } + + //-------- Custom foreign destination type -------------------------------// + + @SuppressWarnings("unused") + private class ForeignTopicAndQueue implements Queue, Topic { + + private boolean returnTopicName = true; + private boolean returnQueueName = true; + + private boolean topic = true; + private boolean queue = true; + + private final String name; + + public ForeignTopicAndQueue(String name) { + this.name = name; + } + + @Override + public String getTopicName() throws JMSException { + if (returnTopicName) { + return name; + } + + return null; + } + + @Override + public String getQueueName() throws JMSException { + if (returnQueueName) { + return name; + } + + return null; + } + + public boolean isTopic() { + return topic; + } + + public void setTopic(boolean value) { + this.topic = value; + } + + public boolean isQueue() { + return queue; + } + + public void setQueue(boolean value) { + this.queue = value; + } + + public void setReturnTopicName(boolean returnTopicName) { + this.returnTopicName = returnTopicName; + } + + public void setReturnQueueName(boolean returnQueueName) { + this.returnQueueName = returnQueueName; + } + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org