Repository: qpid-jms Updated Branches: refs/heads/master 756f120b9 -> 0d74de27b
Add some additional tests to validate some edge case behaviors. Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/0d74de27 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/0d74de27 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/0d74de27 Branch: refs/heads/master Commit: 0d74de27bb56afa10c819ef9f476f62e938ec011 Parents: 756f120 Author: Timothy Bish <tabish...@gmail.com> Authored: Wed Oct 8 12:49:29 2014 -0400 Committer: Timothy Bish <tabish...@gmail.com> Committed: Wed Oct 8 12:49:29 2014 -0400 ---------------------------------------------------------------------- .../amqp/message/AmqpDestinationHelperTest.java | 139 ++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0d74de27/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 2caf770..dbf9279 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 @@ -89,6 +89,17 @@ public class AmqpDestinationHelperTest { } @Test + public void testCreateDestinationFromStringNoConnectionSetPrefixReturnsQueue() { + String destinationName = "testDestinationName"; + AmqpConnection connection = Mockito.mock(AmqpConnection.class); + 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(); @@ -150,12 +161,62 @@ public class AmqpDestinationHelperTest { Mockito.when(message.getToAddress()).thenReturn(null); Mockito.when(message.getMessageAnnotation( TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME)).thenReturn(QUEUE_ATTRIBUTES_STRING); - JmsQueue consumerDestination = new JmsQueue("ConsumerDestination"); + JmsDestination consumerDestination = new JmsQueue("ConsumerDestination"); + assertSame(consumerDestination, helper.getJmsDestination(message, consumerDestination)); + + consumerDestination = new JmsTopic("ConsumerDestination"); assertSame(consumerDestination, helper.getJmsDestination(message, consumerDestination)); } @Test + public void testGetJmsDestinationWithEmptyTypeAnnotationWithQueueConsumerDest() throws Exception { + String testAddress = "testAddress"; + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getToAddress()).thenReturn(testAddress); + Mockito.when(message.getMessageAnnotation(TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME)).thenReturn(""); + JmsQueue consumerDestination = new JmsQueue("ConsumerDestination"); + + JmsDestination destination = helper.getJmsDestination(message, consumerDestination); + assertNotNull(destination); + assertTrue(destination.isQueue()); + assertFalse(destination.isTemporary()); + assertEquals(testAddress, destination.getName()); + } + + @Test + public void testGetJmsDestinationWithUnknownTypeAnnotationWithQueueConsumerDest() throws Exception { + String testAddress = "testAddress"; + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getToAddress()).thenReturn(testAddress); + Mockito.when(message.getMessageAnnotation(TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME)).thenReturn("jms.queue"); + JmsQueue consumerDestination = new JmsQueue("ConsumerDestination"); + + JmsDestination destination = helper.getJmsDestination(message, consumerDestination); + assertNotNull(destination); + assertTrue(destination.isQueue()); + assertFalse(destination.isTemporary()); + assertEquals(testAddress, destination.getName()); + } + + @Test + public void testGetJmsDestinationWithoutTypeAnnotationWithAnonymousConsumerDest() { + String testAddress = "testAddress"; + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getToAddress()).thenReturn(testAddress); + Mockito.when(message.getMessageAnnotation(TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME)).thenReturn(null); + + JmsDestination consumerDestination = Mockito.mock(JmsDestination.class); + Mockito.when(consumerDestination.getName()).thenReturn("ConsumerDestination"); + + JmsDestination destination = helper.getJmsDestination(message, consumerDestination); + assertNotNull(destination); + assertTrue(destination.isQueue()); + assertFalse(destination.isTemporary()); + assertEquals(testAddress, destination.getName()); + } + + @Test public void testGetJmsDestinationWithoutTypeAnnotationWithQueueConsumerDest() throws Exception { String testAddress = "testAddress"; AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); @@ -310,6 +371,53 @@ public class AmqpDestinationHelperTest { } @Test + public void testGetJmsReplyToWithoutTypeAnnotationWithAnonymousConsumerDest() { + String testAddress = "testAddress"; + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getReplyToAddress()).thenReturn(testAddress); + Mockito.when(message.getMessageAnnotation(REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME)).thenReturn(null); + + JmsDestination consumerDestination = Mockito.mock(JmsDestination.class); + Mockito.when(consumerDestination.getName()).thenReturn("ConsumerDestination"); + + JmsDestination destination = helper.getJmsReplyTo(message, consumerDestination); + assertNotNull(destination); + assertTrue(destination.isQueue()); + assertFalse(destination.isTemporary()); + assertEquals(testAddress, destination.getName()); + } + + @Test + public void testGetJmsReplyToWithEmptyTypeAnnotationWithQueueConsumerDest() throws Exception { + String testAddress = "testAddress"; + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getReplyToAddress()).thenReturn(testAddress); + Mockito.when(message.getMessageAnnotation(REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME)).thenReturn(""); + JmsQueue consumerDestination = new JmsQueue("ConsumerDestination"); + + JmsDestination destination = helper.getJmsReplyTo(message, consumerDestination); + assertNotNull(destination); + assertTrue(destination.isQueue()); + assertFalse(destination.isTemporary()); + assertEquals(testAddress, destination.getName()); + } + + @Test + public void testGetJmsReplyToWithUnknownTypeAnnotationWithQueueConsumerDest() throws Exception { + String testAddress = "testAddress"; + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getReplyToAddress()).thenReturn(testAddress); + Mockito.when(message.getMessageAnnotation(REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME)).thenReturn("jms.queue"); + JmsQueue consumerDestination = new JmsQueue("ConsumerDestination"); + + JmsDestination destination = helper.getJmsReplyTo(message, consumerDestination); + assertNotNull(destination); + assertTrue(destination.isQueue()); + assertFalse(destination.isTemporary()); + assertEquals(testAddress, destination.getName()); + } + + @Test public void testGetJmsReplyToWithoutTypeAnnotationWithTopicConsumerDest() throws Exception { String testAddress = "testAddress"; AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); @@ -479,6 +587,19 @@ public class AmqpDestinationHelperTest { Mockito.verify(message).setMessageAnnotation(TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME, TEMP_TOPIC_ATTRIBUTES_STRING); } + @Test + public void testSetToAddressFromDestinationWithAnonymousDestination() { + String testAddress = "testAddress"; + JmsDestination destination = Mockito.mock(JmsDestination.class); + Mockito.when(destination.getName()).thenReturn(testAddress); + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + + helper.setToAddressFromDestination(message, destination); + + Mockito.verify(message).setToAddress(testAddress); + Mockito.verify(message).removeMessageAnnotation(TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME); + } + //--------------- Test setReplyToAddressFromDestination method -----------// @Test @@ -548,6 +669,19 @@ public class AmqpDestinationHelperTest { Mockito.verify(message).setMessageAnnotation(REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME, TEMP_TOPIC_ATTRIBUTES_STRING); } + @Test + public void testSetReplyToAddressFromDestinationWithAnonymousDestination() { + String testAddress = "testAddress"; + JmsDestination destination = Mockito.mock(JmsDestination.class); + Mockito.when(destination.getName()).thenReturn(testAddress); + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + + helper.setReplyToAddressFromDestination(message, destination); + + Mockito.verify(message).setReplyToAddress(testAddress); + Mockito.verify(message).removeMessageAnnotation(REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL_NAME); + } + //--------------- Test Support Methods -----------------------------------// @Test @@ -557,6 +691,9 @@ public class AmqpDestinationHelperTest { set.add(AmqpDestinationHelper.QUEUE_ATTRIBUTE); set.add(AmqpDestinationHelper.TEMPORARY_ATTRIBUTE); + // test for no NPE errors. + assertNull(helper.splitAttributes(null)); + // test a single comma separator produces expected set assertEquals(set, helper.splitAttributes(AmqpDestinationHelper.QUEUE_ATTRIBUTES_STRING + "," + AmqpDestinationHelper.TEMPORARY_ATTRIBUTE)); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org