qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject [2/2] git commit: update the ID helper to use the proton types directory rather than converting them
Date Wed, 24 Sep 2014 18:12:06 GMT
update the ID helper to use the proton types directory rather than converting them


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

Branch: refs/heads/master
Commit: 06d8ed14ff5595dce7750dcdafb4b6b9b1f5154e
Parents: 59a5ae3
Author: Robert Gemmell <robbie@apache.org>
Authored: Wed Sep 24 12:36:07 2014 +0100
Committer: Robert Gemmell <robbie@apache.org>
Committed: Wed Sep 24 19:06:18 2014 +0100

----------------------------------------------------------------------
 .../amqp/message/AmqpMessageIdHelper.java       | 15 +++---
 .../amqp/message/AmqpMessageIdHelperTest.java   | 57 +++++++-------------
 2 files changed, 29 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/06d8ed14/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelper.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelper.java
b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelper.java
index 0bda795..18c0b91 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelper.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelper.java
@@ -20,11 +20,12 @@
  */
 package org.apache.qpid.jms.provider.amqp.message;
 
-import java.math.BigInteger;
 import java.nio.ByteBuffer;
 import java.util.UUID;
 
 import org.apache.qpid.jms.exceptions.IdConversionException;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.UnsignedLong;
 
 /**
  * Helper class for identifying and converting message-id and correlation-id values between
@@ -48,6 +49,8 @@ import org.apache.qpid.jms.exceptions.IdConversionException;
  *
  */
 public class AmqpMessageIdHelper {
+    public static final AmqpMessageIdHelper INSTANCE = new AmqpMessageIdHelper();
+
     public static final String AMQP_STRING_PREFIX = "AMQP_STRING:";
     public static final String AMQP_UUID_PREFIX = "AMQP_UUID:";
     public static final String AMQP_ULONG_PREFIX = "AMQP_ULONG:";
@@ -117,10 +120,10 @@ public class AmqpMessageIdHelper {
             }
         } else if (messageId instanceof UUID) {
             return AMQP_UUID_PREFIX + messageId.toString();
-        } else if (messageId instanceof BigInteger || messageId instanceof Long) {
+        } else if (messageId instanceof UnsignedLong) {
             return AMQP_ULONG_PREFIX + messageId.toString();
-        } else if (messageId instanceof ByteBuffer) {
-            ByteBuffer dup = ((ByteBuffer) messageId).duplicate();
+        } else if (messageId instanceof Binary) {
+            ByteBuffer dup = ((Binary) messageId).asByteBuffer();
 
             byte[] bytes = new byte[dup.remaining()];
             dup.get(bytes);
@@ -175,13 +178,13 @@ public class AmqpMessageIdHelper {
                 return UUID.fromString(uuidString);
             } else if (hasAmqpUlongPrefix(baseId)) {
                 String longString = strip(baseId, AMQP_ULONG_PREFIX_LENGTH);
-                return new BigInteger(longString);
+                return UnsignedLong.valueOf(longString);
             } else if (hasAmqpStringPrefix(baseId)) {
                 return strip(baseId, AMQP_STRING_PREFIX_LENGTH);
             } else if (hasAmqpBinaryPrefix(baseId)) {
                 String hexString = strip(baseId, AMQP_BINARY_PREFIX_LENGTH);
                 byte[] bytes = convertHexStringToBinary(hexString);
-                return ByteBuffer.wrap(bytes);
+                return new Binary(bytes);
             } else {
                 // We have a string without any type prefix, transmit it as-is.
                 return baseId;

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/06d8ed14/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelperTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelperTest.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelperTest.java
index b168ec6..40b711e 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelperTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageIdHelperTest.java
@@ -22,13 +22,13 @@ package org.apache.qpid.jms.provider.amqp.message;
 
 import static org.junit.Assert.*;
 
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
 import java.util.UUID;
 
 import org.apache.qpid.jms.exceptions.IdConversionException;
 import org.apache.qpid.jms.provider.amqp.message.AmqpMessageIdHelper;
 import org.apache.qpid.jms.test.QpidJmsTestCase;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.UnsignedLong;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -255,56 +255,41 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
 
     /**
      * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(String)} returns a string
-     * indicating an AMQP encoded ulong when given a Long object.
+     * indicating an AMQP encoded ulong when given a UnsignedLong object.
      */
     @Test
-    public void testToBaseMessageIdStringWithLong() {
-        Long longMessageId = Long.valueOf(123456789L);
-        String expected = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + longMessageId.toString();
+    public void testToBaseMessageIdStringWithUnsignedLong() {
+        UnsignedLong uLongMessageId = UnsignedLong.valueOf(123456789L);
+        String expected = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + uLongMessageId.toString();
 
-        String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(longMessageId);
+        String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(uLongMessageId);
         assertNotNull("null string should not have been returned", baseMessageIdString);
         assertEquals("expected base id string was not returned", expected, baseMessageIdString);
     }
 
     /**
      * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(String)} returns a string
-     * indicating an AMQP encoded ulong when given a BigInteger object.
+     * indicating an AMQP encoded binary when given a Binary object.
      */
     @Test
-    public void testToBaseMessageIdStringWithBigInteger() {
-        BigInteger bigIntMessageId = BigInteger.valueOf(123456789L);
-        String expected = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + bigIntMessageId.toString();
-
-        String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(bigIntMessageId);
-        assertNotNull("null string should not have been returned", baseMessageIdString);
-        assertEquals("expected base id string was not returned", expected, baseMessageIdString);
-    }
-
-    /**
-     * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(String)} returns a string
-     * indicating an AMQP encoded binary when given a ByteBuffer object.
-     */
-    @Test
-    public void testToBaseMessageIdStringWithByteBufferBinary() {
+    public void testToBaseMessageIdStringWithBinary() {
         byte[] bytes = new byte[] { (byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF };
-        ByteBuffer buf = ByteBuffer.wrap(bytes);
+        Binary binary = new Binary(bytes);
 
         String expected = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF";
 
-        String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(buf);
+        String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(binary);
         assertNotNull("null string should not have been returned", baseMessageIdString);
         assertEquals("expected base id string was not returned", expected, baseMessageIdString);
     }
 
     /**
-     * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns a ulong
-     * (represented as a BigInteger) when given a string indicating an
-     * encoded AMQP ulong id.
+     * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns an
+     * UnsignedLong when given a string indicating an encoded AMQP ulong id.
      */
     @Test
     public void testToIdObjectWithEncodedUlong() throws Exception {
-        BigInteger longId = BigInteger.valueOf(123456789L);
+        UnsignedLong longId = UnsignedLong.valueOf(123456789L);
         String provided = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + "123456789";
 
         Object idObject = _messageIdHelper.toIdObject(provided);
@@ -313,14 +298,13 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
     }
 
     /**
-     * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns binary
-     * (represented as a ByteBuffer) when given a string indicating an
-     * encoded AMQP binary id, using upper case hex characters
+     * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns a Binary
+     * when given a string indicating an encoded AMQP binary id, using upper case hex characters
      */
     @Test
     public void testToIdObjectWithEncodedBinaryUppercaseHexString() throws Exception {
         byte[] bytes = new byte[] { (byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF };
-        ByteBuffer binaryId = ByteBuffer.wrap(bytes);
+        Binary binaryId = new Binary(bytes);
 
         String provided = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF";
 
@@ -339,14 +323,13 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
     }
 
     /**
-     * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns binary
-     * (represented as a ByteBuffer) when given a string indicating an
-     * encoded AMQP binary id, using lower case hex characters.
+     * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns a Binary
+     * when given a string indicating an encoded AMQP binary id, using lower case hex characters.
      */
     @Test
     public void testToIdObjectWithEncodedBinaryLowercaseHexString() throws Exception {
         byte[] bytes = new byte[] { (byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF };
-        ByteBuffer binaryId = ByteBuffer.wrap(bytes);
+        Binary binaryId = new Binary(bytes);
 
         String provided = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00ab09ff";
 


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


Mime
View raw message