activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: ARTEMIS-1341 fixed getBody
Date Tue, 19 Dec 2017 03:39:26 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master d67c65b8a -> d1c9bc0f2


ARTEMIS-1341 fixed getBody


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

Branch: refs/heads/master
Commit: 58cd02090d1db57e642bb62be10910e330a28e51
Parents: d67c65b
Author: Stanislav Knot <sknot@redhat.com>
Authored: Tue Dec 12 14:49:31 2017 +0100
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Mon Dec 18 22:39:19 2017 -0500

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQMessage.java     |  2 ++
 .../integration/jms/jms2client/BodyTest.java    | 27 +++++++++++++-------
 .../tests/message/BodyIsAssignableFromTest.java |  2 +-
 3 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/58cd0209/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
index 9dca137..896a8ed 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
@@ -742,6 +742,8 @@ public class ActiveMQMessage implements javax.jms.Message {
    public <T> T getBody(Class<T> c) throws JMSException {
       if (isBodyAssignableTo(c)) {
          return getBodyInternal(c);
+      } else if (hasNoBody()) {
+         return null;
       }
       // XXX HORNETQ-1209 Do we need translations here?
       throw new MessageFormatException("Body not assignable to " + c);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/58cd0209/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/jms2client/BodyTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/jms2client/BodyTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/jms2client/BodyTest.java
index 826a4c6..3409ee0 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/jms2client/BodyTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/jms2client/BodyTest.java
@@ -20,12 +20,12 @@ import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
-import javax.jms.MessageFormatException;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 
 import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
 import org.apache.activemq.artemis.tests.util.JMSTestBase;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -48,7 +48,6 @@ public class BodyTest extends JMSTestBase {
       try (
          Connection conn = cf.createConnection();
       ) {
-
          Session sess = conn.createSession();
          MessageProducer producer = sess.createProducer(queue);
 
@@ -56,17 +55,27 @@ public class BodyTest extends JMSTestBase {
          conn.start();
 
          BytesMessage bytesMessage = sess.createBytesMessage();
-         producer.send(bytesMessage);
+         BytesMessage bytesMessage2 = sess.createBytesMessage();
+         bytesMessage2.writeInt(42);
+         bytesMessage2.reset();
 
+         producer.send(bytesMessage);
          Message msg = cons.receiveNoWait();
+
+         producer.send(bytesMessage2);
+         Message msg2 = cons.receiveNoWait();
+
          assertNotNull(msg);
+         assertNotNull(msg2);
 
-         try {
-            msg.getBody(String.class);
-            fail("Exception expected");
-         } catch (MessageFormatException e) {
-         }
-      }
+         // message body is empty. getBody parameter may be set to any type
+         Assert.assertNull(msg.getBody(java.lang.Object.class));
+         Assert.assertNull(msg.getBody(byte[].class));
+         Assert.assertNull(msg.getBody(String.class));
 
+         // message body is not empty. getBody parameter must be set to byte[].class (or
java.lang.Object.class)
+         Assert.assertNotNull(msg2.getBody(byte[].class));
+         Assert.assertNotNull(msg2.getBody(java.lang.Object.class));
+      }
    }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/58cd0209/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/BodyIsAssignableFromTest.java
----------------------------------------------------------------------
diff --git a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/BodyIsAssignableFromTest.java
b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/BodyIsAssignableFromTest.java
index 47e43de..b791ce2 100644
--- a/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/BodyIsAssignableFromTest.java
+++ b/tests/jms-tests/src/test/java/org/apache/activemq/artemis/jms/tests/message/BodyIsAssignableFromTest.java
@@ -94,7 +94,7 @@ public class BodyIsAssignableFromTest extends MessageBodyTestCase {
          } else {
             try {
                Object foo = msg.getBody(c);
-               Assert.fail("expected a " + MessageFormatException.class);
+               Assert.assertNull("body should be null", foo);
             } catch (MessageFormatException e) {
                // expected
             }


Mime
View raw message