activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject [09/17] activemq git commit: https://issues.apache.org/jira/browse/AMQ-5323
Date Thu, 18 Dec 2014 02:41:39 GMT
https://issues.apache.org/jira/browse/AMQ-5323


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/3f67862a
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/3f67862a
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/3f67862a

Branch: refs/heads/activemq-5.10.x
Commit: 3f67862ac882c333b0e46e8386f27097c02c468a
Parents: 4275157
Author: Timothy Bish <tabish121@gmail.com>
Authored: Fri Aug 15 14:23:14 2014 -0400
Committer: Hadrian Zbarcea <hadrian@apache.org>
Committed: Wed Dec 17 19:39:00 2014 -0500

----------------------------------------------------------------------
 .../activemq/command/ActiveMQMessage.java       | 18 ++++++++--
 .../activemq/command/ActiveMQMessageTest.java   | 36 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/3f67862a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
index eef6c11..7995993 100755
--- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
+++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
@@ -396,13 +396,25 @@ public class ActiveMQMessage extends Message implements org.apache.activemq.Mess
         JMS_PROPERTY_SETERS.put("JMSDeliveryMode", new PropertySetter() {
             @Override
             public void set(Message message, Object value) throws MessageFormatException
{
-                Integer rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
+                Integer rc = null;
+                try {
+                    rc = (Integer) TypeConversionSupport.convert(value, Integer.class);
+                } catch (NumberFormatException nfe) {
+                    if (value instanceof String) {
+                        if (((String) value).equalsIgnoreCase("PERSISTENT")) {
+                            rc = DeliveryMode.PERSISTENT;
+                        } else if (((String) value).equalsIgnoreCase("NON_PERSISTENT")) {
+                            rc = DeliveryMode.NON_PERSISTENT;
+                        } else {
+                            throw nfe;
+                        }
+                    }
+                }
                 if (rc == null) {
                     Boolean bool = (Boolean) TypeConversionSupport.convert(value, Boolean.class);
                     if (bool == null) {
                         throw new MessageFormatException("Property JMSDeliveryMode cannot
be set from a " + value.getClass().getName() + ".");
-                    }
-                    else {
+                    } else {
                         rc = bool.booleanValue() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/3f67862a/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java
index 0287f4b..e1079a1 100755
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/command/ActiveMQMessageTest.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.Enumeration;
 import java.util.Map;
 
+import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageFormatException;
@@ -353,6 +354,41 @@ public class ActiveMQMessageTest extends TestCase {
         assertTrue(((Float) msg.getObjectProperty(name)).floatValue() == 1.3f);
     }
 
+    public void testSetJMSDeliveryModeProperty() throws JMSException {
+        ActiveMQMessage message = new ActiveMQMessage();
+        String propertyName = "JMSDeliveryMode";
+
+        // Set as Boolean
+        message.setObjectProperty(propertyName, Boolean.TRUE);
+        assertTrue(message.isPersistent());
+        message.setObjectProperty(propertyName, Boolean.FALSE);
+        assertFalse(message.isPersistent());
+        message.setBooleanProperty(propertyName, true);
+        assertTrue(message.isPersistent());
+        message.setBooleanProperty(propertyName, false);
+        assertFalse(message.isPersistent());
+
+        // Set as Integer
+        message.setObjectProperty(propertyName, DeliveryMode.PERSISTENT);
+        assertTrue(message.isPersistent());
+        message.setObjectProperty(propertyName, DeliveryMode.NON_PERSISTENT);
+        assertFalse(message.isPersistent());
+        message.setIntProperty(propertyName, DeliveryMode.PERSISTENT);
+        assertTrue(message.isPersistent());
+        message.setIntProperty(propertyName, DeliveryMode.NON_PERSISTENT);
+        assertFalse(message.isPersistent());
+
+        // Set as String
+        message.setObjectProperty(propertyName, "PERSISTENT");
+        assertTrue(message.isPersistent());
+        message.setObjectProperty(propertyName, "NON_PERSISTENT");
+        assertFalse(message.isPersistent());
+        message.setStringProperty(propertyName, "PERSISTENT");
+        assertTrue(message.isPersistent());
+        message.setStringProperty(propertyName, "NON_PERSISTENT");
+        assertFalse(message.isPersistent());
+    }
+
     @SuppressWarnings("rawtypes")
     public void testGetPropertyNames() throws JMSException {
         ActiveMQMessage msg = new ActiveMQMessage();


Mime
View raw message