Repository: qpid-jms Updated Branches: refs/heads/master 5c46a63c3 -> ba54a036f
Add additional tests for property intercept on AMQP specific JMS properties. Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/ba54a036 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/ba54a036 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/ba54a036 Branch: refs/heads/master Commit: ba54a036f62f305e7f997cdfb36cb2da2342fc0e Parents: 5c46a63 Author: Timothy Bish <tabish...@gmail.com> Authored: Fri Oct 10 09:58:54 2014 -0400 Committer: Timothy Bish <tabish...@gmail.com> Committed: Fri Oct 10 09:58:54 2014 -0400 ---------------------------------------------------------------------- .../AmqpJmsMessagePropertyIntercepterTest.java | 122 +++++++++++++++++++ 1 file changed, 122 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/ba54a036/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessagePropertyIntercepterTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessagePropertyIntercepterTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessagePropertyIntercepterTest.java index d835eb5..96c0c79 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessagePropertyIntercepterTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessagePropertyIntercepterTest.java @@ -24,14 +24,45 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import javax.jms.JMSException; +import javax.jms.MessageFormatException; import org.junit.Test; import org.mockito.Mockito; public class AmqpJmsMessagePropertyIntercepterTest { + //---------- Non-Intercepted -------------------------------------------------// + + @Test + public void testGetPropertyWithNonInterceptedNameCallsIntoFacade() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + assertNull(AmqpJmsMessagePropertyIntercepter.getProperty(message, "SomeRandomPropertyName")); + Mockito.verify(message).getApplicationProperty(Mockito.anyString()); + } + + @Test + public void testSetPropertyWithNonInterceptedNameCallsIntoFacade() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + AmqpJmsMessagePropertyIntercepter.setProperty(message, "SomeRandomPropertyName", "Something"); + Mockito.doThrow(new JMSException("Expected")).when(message).setApplicationProperty(Mockito.anyString(), Mockito.anyString()); + try { + AmqpJmsMessagePropertyIntercepter.setProperty(message, "SomeRandomPropertyName", "Something"); + fail("Should have thrown"); + } catch (JMSException ex) { + assertEquals("Expected", ex.getMessage()); + } + } + + @Test + public void testPropertyExistsWithNonInterceptedNameCallsIntoFacade() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + assertFalse(AmqpJmsMessagePropertyIntercepter.propertyExists(message, "SomeRandomPropertyName")); + Mockito.verify(message).applicationPropertyExists(Mockito.anyString()); + } + //-------- JMS_AMQP_TTL --------------------------------------------------// @Test @@ -77,6 +108,30 @@ public class AmqpJmsMessagePropertyIntercepterTest { assertTrue(AmqpJmsMessagePropertyIntercepter.getPropertyNames(message).contains(JMS_AMQP_TTL)); } + @Test + public void testJmsAmqpTtlIPropertExistsWhenSet() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.hasAmqpTimeToLiveOverride()).thenReturn(true); + Mockito.when(message.getAmqpTimeToLiveOverride()).thenReturn(65536L); + assertTrue(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_TTL)); + } + + @Test + public void testJmsAmqpTtlPropertExistsWhenNotSet() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + assertFalse(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_TTL)); + } + + @Test + public void testSetJmsAmqpTtlConversionChecks() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + try { + AmqpJmsMessagePropertyIntercepter.setProperty(message, JMS_AMQP_TTL, new byte[1]); + fail("Should have thrown an exception for this call"); + } catch (JMSException e) { + } + } + //-------- JMS_AMQP_REPLY_TO_GROUP_ID ------------------------------------// @Test @@ -122,6 +177,33 @@ public class AmqpJmsMessagePropertyIntercepterTest { assertTrue(AmqpJmsMessagePropertyIntercepter.getPropertyNames(message).contains(JMS_AMQP_REPLY_TO_GROUP_ID)); } + @Test + public void testJmsAmqpReplyToGroupIdPropertExistsWhenSet() throws JMSException { + String testValue = "ReplyToGroupId"; + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getReplyToGroupId()).thenReturn(testValue); + assertTrue(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_REPLY_TO_GROUP_ID)); + } + + @Test + public void testJmsAmqpReplyToGroupIdPropertExistsWhenNotSet() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + Mockito.when(message.getReplyToGroupId()).thenReturn(null); + assertFalse(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_REPLY_TO_GROUP_ID)); + Mockito.when(message.getReplyToGroupId()).thenReturn(""); + assertFalse(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_REPLY_TO_GROUP_ID)); + } + + @Test + public void testSetJmsAmqpReplyToGroupIdConversionChecks() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + try { + AmqpJmsMessagePropertyIntercepter.setProperty(message, JMS_AMQP_REPLY_TO_GROUP_ID, new byte[1]); + fail("Should have thrown an exception for this call"); + } catch (JMSException e) { + } + } + //-------- JMS_AMQP_TYPED_ENCODING ---------------------------------------// @Test @@ -137,6 +219,16 @@ public class AmqpJmsMessagePropertyIntercepterTest { } @Test + public void testSetJmsAmqpTypedEncodingOnNonObjectMessage() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + try { + AmqpJmsMessagePropertyIntercepter.setProperty(message, JMS_AMQP_TYPED_ENCODING, true); + fail("Should have thrown an exception"); + } catch (MessageFormatException mfe) { + } + } + + @Test public void testGetJmsAmqpTypedEncodingWithNonObjectMessage() throws JMSException { AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); assertNull(AmqpJmsMessagePropertyIntercepter.getProperty(message, JMS_AMQP_TYPED_ENCODING)); @@ -169,4 +261,34 @@ public class AmqpJmsMessagePropertyIntercepterTest { Mockito.when(message.isAmqpTypedEncoding()).thenReturn(true); assertTrue(AmqpJmsMessagePropertyIntercepter.getPropertyNames(message).contains(JMS_AMQP_TYPED_ENCODING)); } + + @Test + public void testJmsAmqpTypedEncodingPropertExistsWhenSet() throws JMSException { + AmqpJmsObjectMessageFacade message = Mockito.mock(AmqpJmsObjectMessageFacade.class); + Mockito.when(message.isAmqpTypedEncoding()).thenReturn(true); + assertTrue(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_TYPED_ENCODING)); + } + + @Test + public void testJmsAmqpTypedEncodingdPropertExistsWhenNotSet() throws JMSException { + AmqpJmsObjectMessageFacade message = Mockito.mock(AmqpJmsObjectMessageFacade.class); + Mockito.when(message.isAmqpTypedEncoding()).thenReturn(false); + assertFalse(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_TYPED_ENCODING)); + } + + @Test + public void testJmsAmqpTypedEncodingdPropertExistsWhenNotAnObjectMessage() throws JMSException { + AmqpJmsMessageFacade message = Mockito.mock(AmqpJmsMessageFacade.class); + assertFalse(AmqpJmsMessagePropertyIntercepter.propertyExists(message, JMS_AMQP_TYPED_ENCODING)); + } + + @Test + public void testSetJmsAmqpTypedEncodingConversionChecks() throws JMSException { + AmqpJmsObjectMessageFacade message = Mockito.mock(AmqpJmsObjectMessageFacade.class); + try { + AmqpJmsMessagePropertyIntercepter.setProperty(message, JMS_AMQP_TYPED_ENCODING, new byte[1]); + fail("Should have thrown an exception for this call"); + } catch (JMSException e) { + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org