You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2014/10/03 18:20:13 UTC

[2/3] git commit: add builder tests for messages arriving without a body section or the message type annotation

add builder tests for messages arriving without a body section or the message type annotation


Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/0136f1d2
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/0136f1d2
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/0136f1d2

Branch: refs/heads/master
Commit: 0136f1d2f54acdf0348276803343afca084d608f
Parents: 5da7f7c
Author: Robert Gemmell <ro...@apache.org>
Authored: Fri Oct 3 16:24:30 2014 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Fri Oct 3 17:11:06 2014 +0100

----------------------------------------------------------------------
 .../amqp/message/AmqpJmsMessageBuilderTest.java | 99 ++++++++++++++++++++
 1 file changed, 99 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/0136f1d2/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
index 2e02608..02951b5 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilderTest.java
@@ -22,6 +22,7 @@ package org.apache.qpid.jms.provider.amqp.message;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -222,4 +223,102 @@ public class AmqpJmsMessageBuilderTest extends QpidJmsTestCase {
         assertNotNull("Facade should not be null", facade);
         assertEquals("Unexpected facade class type", AmqpJmsStreamMessageFacade.class, facade.getClass());
     }
+
+    // =============== Without The Message Type Annotation =========
+    // =============================================================
+
+    // --------- No Body Section ---------
+
+    /**
+     * Test that a message with no body section, but with the content type set to
+     * {@value AmqpMessageSupport#OCTET_STREAM_CONTENT_TYPE} results in a BytesMessage
+     * when not otherwise annotated to indicate the type of JMS message it is.
+     */
+    @Test
+    public void testCreateBytesMessageFromNoBodySectionAndContentType() throws Exception {
+        Message message = Proton.message();
+        message.setContentType(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE);
+
+        JmsMessage jmsMessage = AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+        assertNotNull("Message should not be null", jmsMessage);
+        assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass());
+
+        JmsMessageFacade facade = jmsMessage.getFacade();
+        assertNotNull("Facade should not be null", facade);
+        assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass());
+    }
+
+    /**
+     * Test that a message with no body section, and no content-type results in a BytesMessage
+     * when not otherwise annotated to indicate the type of JMS message it is.
+     */
+    @Test
+    public void testCreateBytesMessageFromNoBodySectionAndNoContentType() throws Exception {
+        Message message = Proton.message();
+
+        assertNull(message.getContentType());
+
+        JmsMessage jmsMessage = AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+        assertNotNull("Message should not be null", jmsMessage);
+        assertEquals("Unexpected message class type", JmsBytesMessage.class, jmsMessage.getClass());
+
+        JmsMessageFacade facade = jmsMessage.getFacade();
+        assertNotNull("Facade should not be null", facade);
+        assertEquals("Unexpected facade class type", AmqpJmsBytesMessageFacade.class, facade.getClass());
+    }
+
+    /**
+    * Test that a message with no body section, but with the content type set to
+    * {@value AmqpMessageSupport#SERIALIZED_JAVA_OBJECT_CONTENT_TYPE} results in an ObjectMessage
+    * when not otherwise annotated to indicate the type of JMS message it is.
+    */
+    @Test
+    public void testCreateObjectMessageFromNoBodySectionAndContentType() throws Exception {
+        Message message = Proton.message();
+        message.setContentType(AmqpMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE);
+
+        JmsMessage jmsMessage = AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+        assertNotNull("Message should not be null", jmsMessage);
+        assertEquals("Unexpected message class type", JmsObjectMessage.class, jmsMessage.getClass());
+
+        JmsMessageFacade facade = jmsMessage.getFacade();
+        assertNotNull("Facade should not be null", facade);
+        assertEquals("Unexpected facade class type", AmqpJmsObjectMessageFacade.class, facade.getClass());
+
+        AmqpObjectTypeDelegate delegate = ((AmqpJmsObjectMessageFacade) facade).getDelegate();
+        assertTrue("Unexpected delegate type: " + delegate, delegate instanceof AmqpSerializedObjectDelegate);
+    }
+
+    /**
+     * Test that a message with no body section, but with the content type set to
+     * {@value AmqpMessageSupport#TEXT_PLAIN_CONTENT_TYPE} results in a TextMessage
+     * when not otherwise annotated to indicate the type of JMS message it is.
+     */
+    @Test
+    public void testCreateTextMessageFromNoBodySectionAndContentType() throws Exception {
+        Message message = Proton.message();
+        message.setContentType(AmqpMessageSupport.TEXT_PLAIN_CONTENT_TYPE);
+
+        JmsMessage jmsMessage = AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+        assertNotNull("Message should not be null", jmsMessage);
+        assertEquals("Unexpected message class type", JmsTextMessage.class, jmsMessage.getClass());
+
+        JmsMessageFacade facade = jmsMessage.getFacade();
+        assertNotNull("Facade should not be null", facade);
+        assertEquals("Unexpected facade class type", AmqpJmsTextMessageFacade.class, facade.getClass());
+    }
+
+    /**
+     * Test that a message with no body section, and with the content type set to
+     * an unknown value results in an exception when not otherwise annotated to
+     * indicate the type of JMS message it is.
+     */
+    @Test(expected = IOException.class)
+    public void testNoBodySectionAndUnknownContentTypeThrowsException() throws Exception {
+        //TODO: decide if this should instead just be a plain Message
+        Message message = Proton.message();
+        message.setContentType("unknown-content-type");
+
+        AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org