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:12 UTC

[1/3] git commit: update incoming AmqpSequence without the x-opt-jms-msg-type message annotation to be an ObjectMessage

Repository: qpid-jms
Updated Branches:
  refs/heads/master a6b5f1bba -> e3d21a7e6


update incoming AmqpSequence without the x-opt-jms-msg-type message annotation to be an ObjectMessage


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

Branch: refs/heads/master
Commit: 5da7f7cd2f04c9dcacb14d5ec6e845db71d7f308
Parents: a6b5f1b
Author: Robert Gemmell <ro...@apache.org>
Authored: Fri Oct 3 15:47:02 2014 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Fri Oct 3 15:47:02 2014 +0100

----------------------------------------------------------------------
 .../jms/provider/amqp/message/AmqpJmsMessageBuilder.java     | 2 +-
 .../jms/provider/amqp/message/AmqpTypedObjectDelegate.java   | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/5da7f7cd/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
index 0649e6c..b1aade4 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageBuilder.java
@@ -145,7 +145,7 @@ public class AmqpJmsMessageBuilder {
                 return createObjectMessage(consumer, message);
             }
         } else if (body instanceof AmqpSequence) {
-            return createStreamMessage(consumer, message);
+            return createObjectMessage(consumer, message);
         }
 
         return null;

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/5da7f7cd/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpTypedObjectDelegate.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpTypedObjectDelegate.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpTypedObjectDelegate.java
index 9fa88dd..e28dc39 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpTypedObjectDelegate.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpTypedObjectDelegate.java
@@ -56,15 +56,17 @@ public class AmqpTypedObjectDelegate implements AmqpObjectTypeDelegate {
             return null;
         } else if (body instanceof AmqpValue) {
             // TODO: This is assuming the object can be immediately returned, and is
-            //       Serializable. We will actually have to ensure elements are
+            //       deeply Serializable. We will actually have to ensure elements are
             //       Serializable and e.g convert the Uint/Ubyte etc wrappers.
             return (Serializable) ((AmqpValue) body).getValue();
         } else if (body instanceof Data) {
             // TODO: return as byte[]? ByteBuffer?
             throw new UnsupportedOperationException("Data support still to be added");
         } else if (body instanceof AmqpSequence) {
-            // TODO: return as list?
-            throw new UnsupportedOperationException("AmqpSequence support still to be added");
+            // TODO: This is assuming the object can be immediately returned, and is
+            //       deeply Serializable. We will actually have to ensure elements are
+            //       Serializable and e.g convert the Uint/Ubyte etc wrappers.
+            return (Serializable) ((AmqpSequence) body).getValue();
         } else {
             throw new IllegalStateException("Unexpected body type: " + body.getClass().getSimpleName());
         }


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


[3/3] git commit: add builder tests for messages arriving with a data body section but no type annotation

Posted by ro...@apache.org.
add builder tests for messages arriving with a data body section but no 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/e3d21a7e
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e3d21a7e
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e3d21a7e

Branch: refs/heads/master
Commit: e3d21a7e61116feb945a53af17fd90adea98700e
Parents: 0136f1d
Author: Robert Gemmell <ro...@apache.org>
Authored: Fri Oct 3 17:17:56 2014 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Fri Oct 3 17:17:56 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e3d21a7e/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 02951b5..b9177ca 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
@@ -38,7 +38,9 @@ import org.apache.qpid.jms.message.facade.JmsMessageFacade;
 import org.apache.qpid.jms.provider.amqp.AmqpConsumer;
 import org.apache.qpid.jms.test.QpidJmsTestCase;
 import org.apache.qpid.proton.Proton;
+import org.apache.qpid.proton.amqp.Binary;
 import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.messaging.Data;
 import org.apache.qpid.proton.amqp.messaging.MessageAnnotations;
 import org.apache.qpid.proton.message.Message;
 import org.junit.Before;
@@ -321,4 +323,110 @@ public class AmqpJmsMessageBuilderTest extends QpidJmsTestCase {
 
         AmqpJmsMessageBuilder.createJmsMessage(mockConsumer, message);
     }
+
+    // --------- Data Body Section ---------
+
+    /**
+     * Test that a data body containing nothing, 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 testCreateBytesMessageFromDataWithEmptyBinaryAndContentType() throws Exception {
+        Message message = Proton.message();
+        Binary binary = new Binary(new byte[0]);
+        message.setBody(new Data(binary));
+        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 receiving a data body containing nothing and no content type being set
+     * results in a BytesMessage when not otherwise annotated to indicate the type of
+     * JMS message it is.
+     */
+    @Test
+    public void testCreateBytesMessageFromDataWithEmptyBinaryAndNoContentType() throws Exception {
+        Message message = Proton.message();
+        Binary binary = new Binary(new byte[0]);
+        message.setBody(new Data(binary));
+
+        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 receiving a data body containing nothing, 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 testCreateObjectMessageFromDataWithContentTypeAndEmptyBinary() throws Exception {
+        Message message = Proton.message();
+        Binary binary = new Binary(new byte[0]);
+        message.setBody(new Data(binary));
+        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 receiving a data body containing nothing, 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 testCreateTextMessageFromDataWithContentTypeAndEmptyBinary() throws Exception {
+        Message message = Proton.message();
+        Binary binary = new Binary(new byte[0]);
+        message.setBody(new Data(binary));
+        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 a data 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 testCreateGenericMessageFromDataWithUnknownContentTypeAndEmptyBinary() throws Exception {
+        //TODO: decide if this should instead just be a plain Message or BytesMessage instead?
+        Message message = Proton.message();
+        Binary binary = new Binary(new byte[0]);
+        message.setBody(new Data(binary));
+        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


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

Posted by ro...@apache.org.
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