Author: ritchiem
Date: Thu Jul 22 14:21:47 2010
New Revision: 966680

URL: http://svn.apache.org/viewvc?rev=966680&view=rev
Log:
QPID-2744 : Add tests for correct exception when null object is set via 
setObjectProperty in Field Table and via JMS Properties

Modified:
    
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java
    
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
    
qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
    
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java

Modified: 
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java?rev=966680&r1=966679&r2=966680&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java
 (original)
+++ 
qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/JMSHeaderAdapter.java
 Thu Jul 22 14:21:47 2010
@@ -400,7 +400,7 @@ public final class JMSHeaderAdapter
         }
         catch (AMQPInvalidClassException aice)
         {
-            MessageFormatException mfe = new MessageFormatException("Only 
primatives are allowed object is:" + object.getClass());
+            MessageFormatException mfe = new MessageFormatException("Only 
Primitives objects allowed Object is:" + (object == null ? "null" : 
object.getClass()));
             mfe.setLinkedException(aice);
             mfe.initCause(aice);
             throw mfe;

Modified: 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java?rev=966680&r1=966679&r2=966680&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
 (original)
+++ 
qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java
 Thu Jul 22 14:21:47 2010
@@ -675,7 +675,7 @@ public class FieldTable
             return setBytes(string, (byte[]) object);
         }
 
-        throw new AMQPInvalidClassException("Only Primatives objects allowed 
Object is:" + object.getClass());
+        throw new AMQPInvalidClassException("Only Primitives objects allowed 
Object is:" + (object == null ? "null" : object.getClass()));
     }
 
     public boolean isNullStringValue(String name)

Modified: 
qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java?rev=966680&r1=966679&r2=966680&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
 (original)
+++ 
qpid/trunk/qpid/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java
 Thu Jul 22 14:21:47 2010
@@ -25,6 +25,7 @@ import junit.framework.TestCase;
 
 import org.apache.mina.common.ByteBuffer;
 
+import org.apache.qpid.AMQInvalidArgumentException;
 import org.apache.qpid.AMQPInvalidClassException;
 
 import org.slf4j.Logger;
@@ -520,6 +521,18 @@ public class PropertyFieldTableTest exte
         table.setObject("object-short", Short.MAX_VALUE);
         table.setObject("object-string", "Hello");
 
+        try
+        {
+            table.setObject("Null-object", null);
+            fail("null values are not allowed");
+        }
+        catch (AMQPInvalidClassException aice)
+        {
+            assertEquals("Null values are not allowed to be set",
+                         "Only Primitives objects allowed Object is:null", 
aice.getMessage());
+        }
+
+
         Assert.assertEquals((Boolean) true, table.getBoolean("bool"));
         Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte"));
         assertBytesEqual(bytes, table.getBytes("bytes"));

Modified: 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java?rev=966680&r1=966679&r2=966680&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
 (original)
+++ 
qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/JMSPropertiesTest.java
 Thu Jul 22 14:21:47 2010
@@ -20,6 +20,7 @@
  */
 package org.apache.qpid.test.unit.message;
 
+import org.apache.qpid.AMQPInvalidClassException;
 import org.apache.qpid.client.AMQConnection;
 import org.apache.qpid.client.AMQQueue;
 import org.apache.qpid.client.AMQSession;
@@ -33,6 +34,7 @@ import org.slf4j.LoggerFactory;
 import javax.jms.Destination;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
+import javax.jms.MessageFormatException;
 import javax.jms.MessageProducer;
 import javax.jms.ObjectMessage;
 import javax.jms.Queue;
@@ -52,6 +54,7 @@ public class JMSPropertiesTest extends Q
     public static final String JMS_CORR_ID = "QPIDID_01";
     public static final int JMS_DELIV_MODE = 1;
     public static final String JMS_TYPE = "test.jms.type";
+    protected static final String NULL_OBJECT_PROPERTY = "NullObject";
 
     protected void setUp() throws Exception
     {
@@ -89,6 +92,28 @@ public class JMSPropertiesTest extends Q
         int JMSXGroupSeq_VALUE = 1;
         sentMsg.setIntProperty("JMSXGroupSeq", JMSXGroupSeq_VALUE);
 
+        try
+        {
+            sentMsg.setObjectProperty(NULL_OBJECT_PROPERTY, null);
+            fail("Null Object Property value set");
+        }
+        catch (MessageFormatException mfe)
+        {
+            // Check the cause
+            Throwable cause = mfe.getCause();
+            assertNotNull(cause);
+            assertEquals("Incorrect cause ", AMQPInvalidClassException.class, 
cause.getClass());
+            assertEquals("Null values are not allowed to be set",
+                         "Only Primitives objects allowed Object is:null", 
cause.getMessage());
+
+            // Also check the linked exception
+            cause = mfe.getLinkedException();
+            assertNotNull(cause);
+            assertEquals("Incorrect cause ", AMQPInvalidClassException.class, 
cause.getClass());
+            assertEquals("Null values are not allowed to be set",
+                         "Only Primitives objects allowed Object is:null", 
cause.getMessage());
+        }
+
         // send it
         producer.send(sentMsg);
 
@@ -131,6 +156,9 @@ public class JMSPropertiesTest extends Q
         assertTrue("JMSXGroupID not available.",JMSXGroupID_Available);
         assertTrue("JMSXGroupSeq not available.",JMSXGroupSeq_Available);
 
+        // Check that the NULL_OBJECT_PROPERTY was not set or transmitted.
+        assertFalse(NULL_OBJECT_PROPERTY + " was not set.", 
rm.propertyExists(NULL_OBJECT_PROPERTY));
+
         con.close();
     }
 



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to