qpid-jms git commit: QPIDJMS-313 Add some additional tests to show the issue is not valid

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

qpid-jms git commit: QPIDJMS-313 Add some additional tests to show the issue is not valid

tabish
Repository: qpid-jms
Updated Branches:
  refs/heads/master d4d318d55 -> ab5f46336


QPIDJMS-313 Add some additional tests to show the issue is not valid

Add a few more tests that check in different contexts that the getBody
method does throw when expected.

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

Branch: refs/heads/master
Commit: ab5f463366acf2547725b0043003d8b8168f46bf
Parents: d4d318d
Author: Timothy Bish <[hidden email]>
Authored: Wed Aug 9 11:30:06 2017 -0400
Committer: Timothy Bish <[hidden email]>
Committed: Wed Aug 9 11:30:06 2017 -0400

----------------------------------------------------------------------
 .../BytesMessageIntegrationTest.java            | 64 ++++++++++++++++++++
 .../integration/JMSConsumerIntegrationTest.java | 57 +++++++++++++++++
 .../qpid/jms/message/JmsBytesMessageTest.java   | 42 +++++++++++++
 3 files changed, 163 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/ab5f4633/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/BytesMessageIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/BytesMessageIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/BytesMessageIntegrationTest.java
index 940cb9e..81c1b60 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/BytesMessageIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/BytesMessageIntegrationTest.java
@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Map;
 
 import javax.jms.BytesMessage;
 import javax.jms.CompletionListener;
@@ -36,6 +37,7 @@ import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
+import javax.jms.MessageFormatException;
 import javax.jms.MessageNotWriteableException;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
@@ -279,6 +281,68 @@ public class BytesMessageIntegrationTest extends QpidJmsTestCase {
         }
     }
 
+    @Test(timeout = 20000)
+    public void testGetBodyBytesMessageFailsWhenWrongTypeRequested() throws Exception {
+        try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+            Connection connection = testFixture.establishConnecton(testPeer);
+            connection.start();
+
+            testPeer.expectBegin();
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = session.createQueue("myQueue");
+
+            PropertiesDescribedType properties = new PropertiesDescribedType();
+            properties.setContentType(Symbol.valueOf(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE));
+
+            MessageAnnotationsDescribedType msgAnnotations = null;
+            msgAnnotations = new MessageAnnotationsDescribedType();
+            msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_BYTES_MESSAGE);
+
+            final byte[] expectedContent = "expectedContent".getBytes();
+            DescribedType dataContent = new DataDescribedType(new Binary(expectedContent));
+
+            testPeer.expectReceiverAttach();
+            testPeer.expectLinkFlowRespondWithTransfer(null, msgAnnotations, properties, null, dataContent, 2);
+            testPeer.expectDispositionThatIsAcceptedAndSettled();
+            testPeer.expectDispositionThatIsAcceptedAndSettled();
+
+            MessageConsumer messageConsumer = session.createConsumer(queue);
+
+            Message readMsg1 = messageConsumer.receive(1000);
+            Message readMsg2 = messageConsumer.receive(1000);
+
+            testPeer.waitForAllHandlersToComplete(3000);
+
+            assertNotNull(readMsg1);
+            assertNotNull(readMsg2);
+
+            try {
+                readMsg1.getBody(String.class);
+                fail("Should have thrown MessageFormatException");
+            } catch (MessageFormatException mfe) {
+            }
+
+            try {
+                readMsg2.getBody(Map.class);
+                fail("Should have thrown MessageFormatException");
+            } catch (MessageFormatException mfe) {
+            }
+
+            byte[] received1 = readMsg1.getBody(byte[].class);
+            byte[] received2 = (byte[]) readMsg2.getBody(Object.class);
+
+            assertTrue(Arrays.equals(expectedContent, received1));
+            assertTrue(Arrays.equals(expectedContent, received2));
+
+            testPeer.expectClose();
+
+            connection.close();
+
+            testPeer.waitForAllHandlersToComplete(3000);
+        }
+    }
+
     /**
      * Test that a message received from the test peer with an AmqpValue section containing
      * Binary and no content type is returned as a BytesMessage, verify it gives the

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/ab5f4633/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/JMSConsumerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/JMSConsumerIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/JMSConsumerIntegrationTest.java
index 78374e0..786d4e4 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/JMSConsumerIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/JMSConsumerIntegrationTest.java
@@ -561,4 +561,61 @@ public class JMSConsumerIntegrationTest extends QpidJmsTestCase {
             testPeer.waitForAllHandlersToComplete(3000);
         }
     }
+
+    @Test(timeout = 20000)
+    public void testReceiveBodyBytesMessageFailsWhenWrongTypeRequested() throws Exception {
+        try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+            JMSContext context = testFixture.createJMSContext(testPeer);
+
+            testPeer.expectBegin();
+
+            Queue queue = context.createQueue("myQueue");
+
+            PropertiesDescribedType properties = new PropertiesDescribedType();
+            properties.setContentType(Symbol.valueOf(AmqpMessageSupport.OCTET_STREAM_CONTENT_TYPE));
+
+            MessageAnnotationsDescribedType msgAnnotations = null;
+            msgAnnotations = new MessageAnnotationsDescribedType();
+            msgAnnotations.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_MSG_TYPE, AmqpMessageSupport.JMS_BYTES_MESSAGE);
+
+            final byte[] expectedContent = "expectedContent".getBytes();
+            DescribedType dataContent = new DataDescribedType(new Binary(expectedContent));
+
+            testPeer.expectReceiverAttach();
+            testPeer.expectLinkFlowRespondWithTransfer(null, msgAnnotations, properties, null, dataContent, 2);
+            testPeer.expectDispositionThatIsAcceptedAndSettled();
+            testPeer.expectDispositionThatIsAcceptedAndSettled();
+
+            JMSConsumer messageConsumer = context.createConsumer(queue);
+            try {
+                messageConsumer.receiveBody(String.class, 3000);
+                fail("Should not read as String type");
+            } catch (MessageFormatRuntimeException mfre) {
+            }
+
+            byte[] received1 = messageConsumer.receiveBody(byte[].class, 3000);
+
+            try {
+                messageConsumer.receiveBody(Map.class, 3000);
+                fail("Should not read as Map type");
+            } catch (MessageFormatRuntimeException mfre) {
+            }
+
+            byte[] received2 = (byte[]) messageConsumer.receiveBody(Object.class, 3000);
+
+            testPeer.waitForAllHandlersToComplete(3000);
+
+            assertNotNull(received1);
+            assertNotNull(received2);
+            assertTrue(Arrays.equals(expectedContent, received1));
+            assertTrue(Arrays.equals(expectedContent, received2));
+
+            testPeer.expectEnd();
+            testPeer.expectClose();
+
+            context.close();
+
+            testPeer.waitForAllHandlersToComplete(3000);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/ab5f4633/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsBytesMessageTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsBytesMessageTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsBytesMessageTest.java
index 0eb948a..d56c533 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsBytesMessageTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/message/JmsBytesMessageTest.java
@@ -18,6 +18,7 @@ package org.apache.qpid.jms.message;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -25,7 +26,10 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Array;
 import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
 
 import javax.jms.BytesMessage;
 import javax.jms.JMSException;
@@ -974,6 +978,44 @@ public class JmsBytesMessageTest {
         } catch (Exception e) {
             fail("should have thrown MessageFormatException");
         }
+
+        try {
+            bytesMessage.getBody(String.class);
+            fail("should have thrown MessageFormatException");
+        } catch (MessageFormatException mfe) {
+        } catch (Exception e) {
+            fail("should have thrown MessageFormatException");
+        }
+
+        try {
+            bytesMessage.getBody(Map.class);
+            fail("should have thrown MessageFormatException");
+        } catch (MessageFormatException mfe) {
+        } catch (Exception e) {
+            fail("should have thrown MessageFormatException");
+        }
+
+        try {
+            bytesMessage.getBody(List.class);
+            fail("should have thrown MessageFormatException");
+        } catch (MessageFormatException mfe) {
+        } catch (Exception e) {
+            fail("should have thrown MessageFormatException");
+        }
+
+        try {
+            bytesMessage.getBody(Array.class);
+            fail("should have thrown MessageFormatException");
+        } catch (MessageFormatException mfe) {
+        } catch (Exception e) {
+            fail("should have thrown MessageFormatException");
+        }
+
+        byte[] read1 = bytesMessage.getBody(byte[].class);
+        assertNotNull(read1);
+
+        byte[] read2 = (byte[]) bytesMessage.getBody(Object.class);
+        assertNotNull(read2);
     }
 
     //---------- Test for misc message methods -------------------------------//


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...