qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1544604 - in /qpid/jms/trunk/src: main/java/org/apache/qpid/jms/engine/ main/java/org/apache/qpid/jms/impl/ test/java/org/apache/qpid/jms/ test/java/org/apache/qpid/jms/engine/ test/java/org/apache/qpid/jms/impl/
Date Fri, 22 Nov 2013 16:50:01 GMT
Author: robbie
Date: Fri Nov 22 16:50:00 2013
New Revision: 1544604

URL: http://svn.apache.org/r1544604
Log:
QPIDJMS-9: implement the remaining get/setFooProperty methods from
Message, expand message tests accordingly.

Modified:
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java
    qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java
    qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java?rev=1544604&r1=1544603&r2=1544604&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/engine/AmqpMessage.java Fri Nov 22 16:50:00
2013
@@ -229,8 +229,16 @@ public abstract class AmqpMessage
         }
     }
 
-    public void setApplicationProperty(String key, Object value)
+    /**
+     * @throws IllegalArgumentException if the provided key is null
+     */
+    public void setApplicationProperty(String key, Object value) throws IllegalArgumentException
     {
+        if(key == null)
+        {
+            throw new IllegalArgumentException("Property key must not be null");
+        }
+
         if(_applicationPropertiesMap == null)
         {
             createApplicationProperties();

Modified: qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java?rev=1544604&r1=1544603&r2=1544604&view=diff
==============================================================================
--- qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java (original)
+++ qpid/jms/trunk/src/main/java/org/apache/qpid/jms/impl/MessageImpl.java Fri Nov 22 16:50:00
2013
@@ -79,8 +79,26 @@ public abstract class MessageImpl<T exte
         return true;
     }
 
+    private void setApplicationProperty(String name, Object value) throws MessageFormatException
+    {
+        checkPropertyNameIsValid(name);
+        checkObjectPropertyValueIsValid(value);
+
+        _amqpMessage.setApplicationProperty(name, value);
+    }
+
+    private Object getApplicationProperty(String name)
+    {
+        checkPropertyNameIsValid(name);
+
+        //TODO: handle non-JMS types?
+        return _amqpMessage.getApplicationProperty(name);
+    }
+
+
     //======= JMS Methods =======
 
+
     @Override
     public String getJMSMessageID() throws JMSException
     {
@@ -251,67 +269,192 @@ public abstract class MessageImpl<T exte
     @Override
     public boolean getBooleanProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if (value instanceof Boolean)
+        {
+            return ((Boolean) value).booleanValue();
+        }
+        else if ((value instanceof String) || (value == null))
+        {
+            return Boolean.valueOf((String) value);
+        }
+        else
+        {
+            throw new MessageFormatException("Property " + name + " of type " + value.getClass().getName()
+                + " cannot be converted to boolean.");
+        }
     }
 
     @Override
     public byte getByteProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if (value instanceof Byte)
+        {
+            return ((Byte) value).byteValue();
+        }
+        else if ((value instanceof String) || (value == null))
+        {
+            return Byte.valueOf((String) value).byteValue();
+        }
+        else
+        {
+            throw new MessageFormatException("Property " + name + " of type " + value.getClass().getName()
+                + " cannot be converted to byte.");
+        }
     }
 
     @Override
     public short getShortProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if (value instanceof Short)
+        {
+            return ((Short) value).shortValue();
+        }
+        else if (value instanceof Byte)
+        {
+            return ((Byte) value).shortValue();
+        }
+        else if ((value instanceof String) || (value == null))
+        {
+            return Short.valueOf((String) value).shortValue();
+        }
+        else
+        {
+            throw new MessageFormatException("Property " + name + " of type " + value.getClass().getName()
+                + " cannot be converted to short.");
+        }
     }
 
     @Override
     public int getIntProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if (value instanceof Integer)
+        {
+            return ((Integer) value).intValue();
+        }
+        else if (value instanceof Short)
+        {
+            return ((Short) value).intValue();
+        }
+        else if (value instanceof Byte)
+        {
+            return ((Byte) value).intValue();
+        }
+        else if ((value instanceof String) || (value == null))
+        {
+            return Integer.valueOf((String) value).intValue();
+        }
+        else
+        {
+            throw new MessageFormatException("Property " + name + " of type " + value.getClass().getName()
+                + " cannot be converted to int.");
+        }
     }
 
     @Override
     public long getLongProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if (value instanceof Long)
+        {
+            return ((Long) value).longValue();
+        }
+        else if (value instanceof Integer)
+        {
+            return ((Integer) value).longValue();
+        }
+        else if (value instanceof Short)
+        {
+            return ((Short) value).longValue();
+        }
+        else if (value instanceof Byte)
+        {
+            return ((Byte) value).longValue();
+        }
+        else if ((value instanceof String) || (value == null))
+        {
+            return Long.valueOf((String) value).longValue();
+        }
+        else
+        {
+            throw new MessageFormatException("Property " + name + " of type " + value.getClass().getName()
+                + " cannot be converted to long.");
+        }
     }
 
     @Override
     public float getFloatProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if (value instanceof Float)
+        {
+            return ((Float) value).floatValue();
+        }
+        else if ((value instanceof String) || (value == null))
+        {
+            return Float.valueOf((String) value).floatValue();
+        }
+        else
+        {
+            throw new MessageFormatException("Property " + name + " of type " + value.getClass().getName()
+                + " cannot be converted to float.");
+        }
     }
 
     @Override
     public double getDoubleProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if (value instanceof Double)
+        {
+            return ((Double) value).doubleValue();
+        }
+        else if (value instanceof Float)
+        {
+            return ((Float) value).doubleValue();
+        }
+        else if ((value instanceof String) || (value == null))
+        {
+            return Double.valueOf((String) value).doubleValue();
+        }
+        else
+        {
+            throw new MessageFormatException("Property " + name + " of type " + value.getClass().getName()
+                + " cannot be converted to double.");
+        }
     }
 
     @Override
     public String getStringProperty(String name) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        Object value = getApplicationProperty(name);
+
+        if ((value instanceof String) || (value == null))
+        {
+            return (String) value;
+        }
+        else
+        {
+            //TODO: verify it is a JMS type?
+            return value.toString();
+        }
     }
 
     @Override
     public Object getObjectProperty(String name) throws JMSException
     {
-        checkPropertyNameIsValid(name);
-
-        //TODO: type conversion if any?
-        //TODO: handle non-JMS types?
-        return _amqpMessage.getApplicationProperty(name);
+        //TODO: verify it is a JMS type?
+        return getApplicationProperty(name);
     }
 
     @Override
@@ -323,66 +466,55 @@ public abstract class MessageImpl<T exte
     @Override
     public void setBooleanProperty(String name, boolean value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setByteProperty(String name, byte value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setShortProperty(String name, short value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setIntProperty(String name, int value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setLongProperty(String name, long value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setFloatProperty(String name, float value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setDoubleProperty(String name, double value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setStringProperty(String name, String value) throws JMSException
     {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException("Not Implemented");
+        setApplicationProperty(name, value);
     }
 
     @Override
     public void setObjectProperty(String name, Object value) throws JMSException
     {
-        checkPropertyNameIsValid(name);
-        checkObjectPropertyValueIsValid(value);
-
-        _amqpMessage.setApplicationProperty(name, value);
+        setApplicationProperty(name, value);
     }
 
     @Override

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java?rev=1544604&r1=1544603&r2=1544604&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/MessageIntegrationTest.java Fri Nov 22
16:50:00 2013
@@ -19,6 +19,8 @@
 package org.apache.qpid.jms;
 
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -42,6 +44,25 @@ import org.junit.Test;
 
 public class MessageIntegrationTest extends QpidJmsTestCase
 {
+    private static final String NULL_STRING_PROP = "nullStringProperty";
+    private static final String NULL_STRING_PROP_VALUE = null;
+    private static final String STRING_PROP = "stringProperty";
+    private static final String STRING_PROP_VALUE = "string";
+    private static final String BOOLEAN_PROP = "booleanProperty";
+    private static final boolean BOOLEAN_PROP_VALUE = true;
+    private static final String BYTE_PROP = "byteProperty";
+    private static final byte   BYTE_PROP_VALUE = (byte)1;
+    private static final String SHORT_PROP = "shortProperty";
+    private static final short  SHORT_PROP_VALUE = (short)1;
+    private static final String INT_PROP = "intProperty";
+    private static final int    INT_PROP_VALUE = Integer.MAX_VALUE;
+    private static final String LONG_PROP = "longProperty";
+    private static final long   LONG_PROP_VALUE = Long.MAX_VALUE;
+    private static final String FLOAT_PROP = "floatProperty";
+    private static final float  FLOAT_PROP_VALUE = Float.MAX_VALUE;
+    private static final String DOUBLE_PROP = "doubleProperty";
+    private static final double DOUBLE_PROP_VALUE = Double.MAX_VALUE;
+
     private final IntegrationTestFixture _testFixture = new IntegrationTestFixture();
 
     @Test
@@ -57,18 +78,32 @@ public class MessageIntegrationTest exte
             Queue queue = session.createQueue("myQueue");
             MessageProducer producer = session.createProducer(queue);
 
-            String propertyName = "prop";
-            boolean propertyValue = true;
+            ApplicationPropertiesSectionMatcher appPropsMatcher = new ApplicationPropertiesSectionMatcher(true);
+            appPropsMatcher.withEntry(NULL_STRING_PROP, nullValue());
+            appPropsMatcher.withEntry(STRING_PROP, equalTo(STRING_PROP_VALUE));
+            appPropsMatcher.withEntry(BOOLEAN_PROP, equalTo(BOOLEAN_PROP_VALUE));
+            appPropsMatcher.withEntry(BYTE_PROP, equalTo(BYTE_PROP_VALUE));
+            appPropsMatcher.withEntry(SHORT_PROP, equalTo(SHORT_PROP_VALUE));
+            appPropsMatcher.withEntry(INT_PROP, equalTo(INT_PROP_VALUE));
+            appPropsMatcher.withEntry(LONG_PROP, equalTo(LONG_PROP_VALUE));
+            appPropsMatcher.withEntry(FLOAT_PROP, equalTo(FLOAT_PROP_VALUE));
+            appPropsMatcher.withEntry(DOUBLE_PROP, equalTo(DOUBLE_PROP_VALUE));
 
             TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
-            ApplicationPropertiesSectionMatcher appPropsMatcher = new ApplicationPropertiesSectionMatcher(true);
-            appPropsMatcher.withEntry(propertyName, equalTo(propertyValue));
             messageMatcher.setApplicationPropertiesMatcher(appPropsMatcher);
             messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(null));
             testPeer.expectTransfer(messageMatcher);
 
             Message message = session.createTextMessage();
-            message.setObjectProperty(propertyName, propertyValue);
+            message.setStringProperty(NULL_STRING_PROP, NULL_STRING_PROP_VALUE);
+            message.setStringProperty(STRING_PROP, STRING_PROP_VALUE);
+            message.setBooleanProperty(BOOLEAN_PROP, BOOLEAN_PROP_VALUE);
+            message.setByteProperty(BYTE_PROP, BYTE_PROP_VALUE);
+            message.setShortProperty(SHORT_PROP, SHORT_PROP_VALUE);
+            message.setIntProperty(INT_PROP, INT_PROP_VALUE);
+            message.setLongProperty(LONG_PROP, LONG_PROP_VALUE);
+            message.setFloatProperty(FLOAT_PROP, FLOAT_PROP_VALUE);
+            message.setDoubleProperty(DOUBLE_PROP, DOUBLE_PROP_VALUE);
 
             producer.send(message);
         }
@@ -87,10 +122,17 @@ public class MessageIntegrationTest exte
             Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
             Queue queue = session.createQueue("myQueue");
 
-            String propertyName = "name";
-            String propertyValue = "value";
             ApplicationPropertiesDescribedType appProperties = new ApplicationPropertiesDescribedType();
-            appProperties.setApplicationProperty(propertyName, propertyValue);
+            appProperties.setApplicationProperty(STRING_PROP, STRING_PROP_VALUE);
+            appProperties.setApplicationProperty(NULL_STRING_PROP, NULL_STRING_PROP_VALUE);
+            appProperties.setApplicationProperty(BOOLEAN_PROP, BOOLEAN_PROP_VALUE);
+            appProperties.setApplicationProperty(BYTE_PROP, BYTE_PROP_VALUE);
+            appProperties.setApplicationProperty(SHORT_PROP, SHORT_PROP_VALUE);
+            appProperties.setApplicationProperty(INT_PROP, INT_PROP_VALUE);
+            appProperties.setApplicationProperty(LONG_PROP, LONG_PROP_VALUE);
+            appProperties.setApplicationProperty(FLOAT_PROP, FLOAT_PROP_VALUE);
+            appProperties.setApplicationProperty(DOUBLE_PROP, DOUBLE_PROP_VALUE);
+
             DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);
 
             testPeer.expectReceiverAttach();
@@ -105,8 +147,25 @@ public class MessageIntegrationTest exte
             assertTrue(receivedMessage instanceof TextMessage);
             assertNull(((TextMessage)receivedMessage).getText());
 
-            assertTrue(receivedMessage.propertyExists(propertyName));
-            assertTrue(propertyValue.equals(receivedMessage.getObjectProperty(propertyName)));
+            assertTrue(receivedMessage.propertyExists(STRING_PROP));
+            assertTrue(receivedMessage.propertyExists(NULL_STRING_PROP));
+            assertTrue(receivedMessage.propertyExists(BYTE_PROP));
+            assertTrue(receivedMessage.propertyExists(BOOLEAN_PROP));
+            assertTrue(receivedMessage.propertyExists(SHORT_PROP));
+            assertTrue(receivedMessage.propertyExists(INT_PROP));
+            assertTrue(receivedMessage.propertyExists(LONG_PROP));
+            assertTrue(receivedMessage.propertyExists(FLOAT_PROP));
+            assertTrue(receivedMessage.propertyExists(DOUBLE_PROP));
+            assertNull(receivedMessage.getStringProperty(NULL_STRING_PROP));
+            assertEquals(STRING_PROP_VALUE, receivedMessage.getStringProperty(STRING_PROP));
+            assertEquals(STRING_PROP_VALUE, receivedMessage.getStringProperty(STRING_PROP));
+            assertEquals(BOOLEAN_PROP_VALUE, receivedMessage.getBooleanProperty(BOOLEAN_PROP));
+            assertEquals(BYTE_PROP_VALUE, receivedMessage.getByteProperty(BYTE_PROP));
+            assertEquals(SHORT_PROP_VALUE, receivedMessage.getShortProperty(SHORT_PROP));
+            assertEquals(INT_PROP_VALUE, receivedMessage.getIntProperty(INT_PROP));
+            assertEquals(LONG_PROP_VALUE, receivedMessage.getLongProperty(LONG_PROP));
+            assertEquals(FLOAT_PROP_VALUE, receivedMessage.getFloatProperty(FLOAT_PROP),
0.0);
+            assertEquals(DOUBLE_PROP_VALUE, receivedMessage.getDoubleProperty(DOUBLE_PROP),
0.0);
         }
     }
 }

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java?rev=1544604&r1=1544603&r2=1544604&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/engine/AmqpMessageTest.java Fri Nov 22
16:50:00 2013
@@ -139,4 +139,22 @@ public class AmqpMessageTest
         testAmqpMessage.setApplicationProperty(TEST_PROP_A, TEST_VALUE_STRING_A);
         assertEquals(TEST_VALUE_STRING_A, testAmqpMessage.getApplicationProperty(TEST_PROP_A));
     }
+
+    @Test
+    public void testSetApplicationPropertyUsingNullKeyCausesIAE()
+    {
+        Message message = Proton.message();
+        TestAmqpMessage testAmqpMessage = new TestAmqpMessage(message, _mockDelivery, _mockAmqpConnection);
+
+        try
+        {
+            testAmqpMessage.setApplicationProperty(null, "value");
+            fail("expected exception not thrown");
+        }
+        catch(IllegalArgumentException iae)
+        {
+            //expected
+        }
+    }
+
 }

Modified: qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java
URL: http://svn.apache.org/viewvc/qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java?rev=1544604&r1=1544603&r2=1544604&view=diff
==============================================================================
--- qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java (original)
+++ qpid/jms/trunk/src/test/java/org/apache/qpid/jms/impl/MessageImplTest.java Fri Nov 22
16:50:00 2013
@@ -24,6 +24,7 @@ import static org.junit.Assert.*;
 
 import java.util.Enumeration;
 
+import javax.jms.JMSException;
 import javax.jms.MessageFormatException;
 
 import org.apache.qpid.jms.engine.TestAmqpMessage;
@@ -46,7 +47,7 @@ public class MessageImplTest
     }
 
     @Test
-    public void testSetPropertyWithNullOrEmptyNameThrowsIAE() throws Exception
+    public void testSetObjectPropertyWithNullOrEmptyNameThrowsIAE() throws Exception
     {
         try
         {
@@ -84,7 +85,7 @@ public class MessageImplTest
     }
 
     @Test
-    public void testSetObjectProperty() throws Exception
+    public void testSetGetObjectProperty() throws Exception
     {
         String propertyName = "myProperty";
 
@@ -149,4 +150,347 @@ public class MessageImplTest
         assertTrue(propertyName.equals(name1));
         assertFalse(names.hasMoreElements());
     }
+
+    // ======= String Properties =========
+
+    @Test
+    public void testSetGetStringProperty() throws Exception
+    {
+        //null property value
+        String propertyName = "myNullProperty";
+        String propertyValue = null;
+
+        assertFalse(_testMessage.propertyExists(propertyName));
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertTrue(_testMessage.propertyExists(propertyName));
+        assertEquals(propertyValue, _testMessage.getStringProperty(propertyName));
+
+        //non-null property value
+        propertyName = "myProperty";
+        propertyValue = "myPropertyValue";
+
+        assertFalse(_testMessage.propertyExists(propertyName));
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertTrue(_testMessage.propertyExists(propertyName));
+        assertEquals(propertyValue, _testMessage.getStringProperty(propertyName));
+    }
+
+    @Test
+    public void testSetStringGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        String propertyValue;
+
+        //boolean
+        propertyValue =  "true";
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertGetPropertyEquals(_testMessage, propertyName, Boolean.valueOf(propertyValue),
Boolean.class);
+
+        //byte
+        propertyValue =  String.valueOf(Byte.MAX_VALUE);
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertGetPropertyEquals(_testMessage, propertyName, Byte.valueOf(propertyValue),
Byte.class);
+
+        //short
+        propertyValue =  String.valueOf(Short.MAX_VALUE);
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertGetPropertyEquals(_testMessage, propertyName, Short.valueOf(propertyValue),
Short.class);
+
+        //int
+        propertyValue =  String.valueOf(Integer.MAX_VALUE);
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertGetPropertyEquals(_testMessage, propertyName, Integer.valueOf(propertyValue),
Integer.class);
+
+        //long
+        propertyValue =  String.valueOf(Long.MAX_VALUE);
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertGetPropertyEquals(_testMessage, propertyName, Long.valueOf(propertyValue),
Long.class);
+
+        //float
+        propertyValue =  String.valueOf(Float.MAX_VALUE);
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertGetPropertyEquals(_testMessage, propertyName, Float.valueOf(propertyValue),
Float.class);
+
+        //double
+        propertyValue =  String.valueOf(Double.MAX_VALUE);
+        _testMessage.setStringProperty(propertyName, propertyValue);
+        assertGetPropertyEquals(_testMessage, propertyName, Double.valueOf(propertyValue),
Double.class);
+    }
+
+    // ======= boolean Properties =========
+
+    @Test
+    public void testSetBooleanGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        boolean propertyValue = true;
+
+        _testMessage.setBooleanProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getBooleanProperty(propertyName));
+
+        assertGetPropertyEquals(_testMessage, propertyName, String.valueOf(propertyValue),
String.class);
+    }
+
+    @Test
+    public void testSetBooleanGetIllegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        boolean propertyValue = true;
+
+        _testMessage.setBooleanProperty(propertyName, propertyValue);
+
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Byte.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Short.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Integer.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Long.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Float.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Double.class);
+    }
+
+    // ======= byte Properties =========
+
+    @Test
+    public void testSetByteGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        byte propertyValue = (byte)1;
+
+        _testMessage.setByteProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getByteProperty(propertyName));
+
+        assertGetPropertyEquals(_testMessage, propertyName, String.valueOf(propertyValue),
String.class);
+        assertGetPropertyEquals(_testMessage, propertyName, Short.valueOf(propertyValue),
Short.class);
+        assertGetPropertyEquals(_testMessage, propertyName, Integer.valueOf(propertyValue),
Integer.class);
+        assertGetPropertyEquals(_testMessage, propertyName, Long.valueOf(propertyValue),
Long.class);
+    }
+
+    @Test
+    public void testSetByteGetIllegalPropertyThrowsMFE() throws Exception
+    {
+        String propertyName = "myProperty";
+        byte propertyValue = (byte)1;
+
+        _testMessage.setByteProperty(propertyName, propertyValue);
+
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Boolean.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Float.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Double.class);
+    }
+
+    // ======= short Properties =========
+
+    @Test
+    public void testSetShortGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        short propertyValue = (short)1;
+
+        _testMessage.setShortProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getShortProperty(propertyName));
+
+        assertGetPropertyEquals(_testMessage, propertyName, String.valueOf(propertyValue),
String.class);
+        assertGetPropertyEquals(_testMessage, propertyName, Integer.valueOf(propertyValue),
Integer.class);
+        assertGetPropertyEquals(_testMessage, propertyName, Long.valueOf(propertyValue),
Long.class);
+    }
+
+    @Test
+    public void testSetShortGetIllegalPropertyThrowsMFE() throws Exception
+    {
+        String propertyName = "myProperty";
+        short propertyValue = (short)1;
+
+        _testMessage.setShortProperty(propertyName, propertyValue);
+
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Boolean.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Byte.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Float.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Double.class);
+    }
+
+    // ======= int Properties =========
+
+    @Test
+    public void testSetIntGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        int propertyValue = (int)1;
+
+        _testMessage.setIntProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getIntProperty(propertyName));
+
+        assertGetPropertyEquals(_testMessage, propertyName, String.valueOf(propertyValue),
String.class);
+        assertGetPropertyEquals(_testMessage, propertyName, Long.valueOf(propertyValue),
Long.class);
+    }
+
+    @Test
+    public void testSetIntGetIllegalPropertyThrowsMFE() throws Exception
+    {
+        String propertyName = "myProperty";
+        int propertyValue = (int)1;
+
+        _testMessage.setIntProperty(propertyName, propertyValue);
+
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Boolean.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Byte.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Short.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Float.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Double.class);
+    }
+
+    // ======= long Properties =========
+
+    @Test
+    public void testSetLongGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        long propertyValue = Long.MAX_VALUE;
+
+        _testMessage.setLongProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getLongProperty(propertyName));
+
+        assertGetPropertyEquals(_testMessage, propertyName, String.valueOf(propertyValue),
String.class);
+    }
+
+    @Test
+    public void testSetLongGetIllegalPropertyThrowsMFE() throws Exception
+    {
+        String propertyName = "myProperty";
+        long propertyValue = Long.MAX_VALUE;
+
+        _testMessage.setLongProperty(propertyName, propertyValue);
+
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Boolean.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Byte.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Short.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Integer.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Float.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Double.class);
+    }
+
+    // ======= float Properties =========
+
+    @Test
+    public void testSetFloatGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        float propertyValue = Float.MAX_VALUE;
+
+        _testMessage.setFloatProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getFloatProperty(propertyName), 0.0);
+
+        assertGetPropertyEquals(_testMessage, propertyName, String.valueOf(propertyValue),
String.class);
+        assertGetPropertyEquals(_testMessage, propertyName, Double.valueOf(propertyValue),
Double.class);
+    }
+
+    @Test
+    public void testSetFloatGetIllegalPropertyThrowsMFE() throws Exception
+    {
+        String propertyName = "myProperty";
+        float propertyValue = Float.MAX_VALUE;
+
+        _testMessage.setFloatProperty(propertyName, propertyValue);
+
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Boolean.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Byte.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Short.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Integer.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Long.class);
+    }
+
+    // ======= double Properties =========
+
+    @Test
+    public void testSetDoubleGetLegalProperty() throws Exception
+    {
+        String propertyName = "myProperty";
+        double propertyValue = Double.MAX_VALUE;
+
+        _testMessage.setDoubleProperty(propertyName, propertyValue);
+        assertEquals(propertyValue, _testMessage.getDoubleProperty(propertyName), 0.0);
+
+        assertGetPropertyEquals(_testMessage, propertyName, String.valueOf(propertyValue),
String.class);
+    }
+
+    @Test
+    public void testSetDoubleGetIllegalPropertyThrowsMFE() throws Exception
+    {
+        String propertyName = "myProperty";
+        double propertyValue = Double.MAX_VALUE;
+
+        _testMessage.setDoubleProperty(propertyName, propertyValue);
+
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Boolean.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Byte.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Short.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Integer.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Long.class);
+        assertGetPropertyThrowsMessageFormatException(_testMessage, propertyName, Float.class);
+    }
+
+    // ====== utility methods =======
+
+    private void assertGetPropertyThrowsMessageFormatException(TestMessageImpl testMessage,
+                                                               String propertyName,
+                                                               Class<?> clazz) throws
JMSException
+    {
+        try
+        {
+            getMessagePropertyUsingTypeMethod(testMessage, propertyName, clazz);
+
+            fail("expected exception to be thrown");
+        }
+        catch(MessageFormatException jmsMFE)
+        {
+            //expected
+        }
+    }
+
+    private Object getMessagePropertyUsingTypeMethod(TestMessageImpl testMessage, String
propertyName, Class<?> clazz) throws JMSException
+    {
+        if(clazz == Boolean.class)
+        {
+            return testMessage.getBooleanProperty(propertyName);
+        }
+        else if(clazz == Byte.class)
+        {
+            return testMessage.getByteProperty(propertyName);
+        }
+        else if(clazz == Short.class)
+        {
+            return testMessage.getShortProperty(propertyName);
+        }
+        else if(clazz == Integer.class)
+        {
+            return testMessage.getIntProperty(propertyName);
+        }
+        else if(clazz == Long.class)
+        {
+            return testMessage.getLongProperty(propertyName);
+        }
+        else if(clazz == Float.class)
+        {
+            return testMessage.getFloatProperty(propertyName);
+        }
+        else if(clazz == Double.class)
+        {
+            return testMessage.getDoubleProperty(propertyName);
+        }
+        else if(clazz == String.class)
+        {
+            return testMessage.getStringProperty(propertyName);
+        }
+        else
+        {
+          throw new RuntimeException("Unexpected property type class");
+        }
+    }
+
+    private void assertGetPropertyEquals(TestMessageImpl testMessage,
+                                         String propertyName,
+                                         Object expectedValue,
+                                         Class<?> clazz) throws JMSException
+    {
+        Object actualValue = getMessagePropertyUsingTypeMethod(testMessage, propertyName,
clazz);
+        assertEquals(expectedValue, actualValue);
+    }
 }



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


Mime
View raw message