You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2016/09/01 15:02:20 UTC
[1/3] qpid-jms git commit: QPIDJMS-189: update handling of
JMSMessageID and JMSCorrelationID,
facilitate better interop with non-JMS peers when round tripping for
correlation
Repository: qpid-jms
Updated Branches:
refs/heads/master 9e9923359 -> 443a54d6c
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/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 d9648a9..c786ba3 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
@@ -93,199 +93,450 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
}
/**
- * Test that {@link AmqpMessageIdHelper#stripMessageIdPrefix(String)} strips "ID:" from strings that do begin "ID:"
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns null if given null
*/
@Test
- public void testStripMessageIdPrefixWithPrefix() {
- String myIdWithoutPrefix = "something";
- String myId = "ID:" + myIdWithoutPrefix;
- assertEquals("'ID:' prefix should have been stripped", myIdWithoutPrefix, _messageIdHelper.stripMessageIdPrefix(myId));
+ public void testToMessageIdStringWithNull() {
+ assertNull("null string should have been returned", _messageIdHelper.toMessageIdString(null));
}
/**
- * Test that {@link AmqpMessageIdHelper#stripMessageIdPrefix(String)} only strips one "ID:" from strings that
- * begin "ID:ID:...."
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} throws an IAE if given an unexpected object type.
*/
@Test
- public void testStripMessageIdPrefixWithDoublePrefix() {
- String myIdWithSinglePrefix = "ID:something";
- String myIdWithDoublePrefix = "ID:" + myIdWithSinglePrefix;
- assertEquals("'ID:' prefix should only have been stripped once", myIdWithSinglePrefix, _messageIdHelper.stripMessageIdPrefix(myIdWithDoublePrefix));
+ public void testToMessageIdStringThrowsIAEWithUnexpectedType() {
+ try {
+ _messageIdHelper.toMessageIdString(new Object());
+ fail("expected exception not thrown");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+ }
+
+ private void doToMessageIdTestImpl(Object idObject, String expected) {
+ String idString = _messageIdHelper.toMessageIdString(idObject);
+ assertNotNull("null string should not have been returned", idString);
+ assertEquals("expected id string was not returned", expected, idString);
}
/**
- * Test that {@link AmqpMessageIdHelper#stripMessageIdPrefix(String)} does not alter strings that begins "ID" without a colon.
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns the given
+ * basic "ID:content" string unchanged.
*/
@Test
- public void testStripMessageIdPrefixWithIDButNoColonPrefix() {
- String myIdNoColon = "IDsomething";
- assertEquals("string without 'ID:' prefix should have been returned unchanged", myIdNoColon, _messageIdHelper.stripMessageIdPrefix(myIdNoColon));
+ public void testToMessageIdStringWithString() {
+ String stringId = "ID:myIdString";
+
+ doToMessageIdTestImpl(stringId, stringId);
}
/**
- * Test that {@link AmqpMessageIdHelper#stripMessageIdPrefix(String)} returns null if given null;
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns the given
+ * basic string with the 'no prefix' prefix and "ID:" prefix.
*/
@Test
- public void testStripMessageIdPrefixWithNull() {
- String nullString = null;
- assertNull("null string should have been returned", _messageIdHelper.stripMessageIdPrefix(nullString));
+ public void testToMessageIdStringWithStringNoPrefix() {
+ String stringId = "myIdStringNoPrefix";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + stringId;
+
+ doToMessageIdTestImpl(stringId, expected);
}
/**
- * Test that {@link AmqpMessageIdHelper#stripMessageIdPrefix(String)} does not alter string that doesn't begin "ID:"
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating lack of "ID:" prefix, when the given string happens to begin with
+ * the {@link AmqpMessageIdHelper#AMQP_UUID_PREFIX}.
*/
@Test
- public void testStripMessageIdPrefixWithoutIDAnywhere() {
- String myNonId = "something";
- assertEquals("string without 'ID:' anywhere should have been returned unchanged", myNonId, _messageIdHelper.stripMessageIdPrefix(myNonId));
+ public void testToMessageIdStringWithStringBeginningWithEncodingPrefixForUUID() {
+ String uuidStringMessageId = AmqpMessageIdHelper.AMQP_UUID_PREFIX + UUID.randomUUID();
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + uuidStringMessageId;
+
+ doToMessageIdTestImpl(uuidStringMessageId, expected);
}
/**
- * Test that {@link AmqpMessageIdHelper#stripMessageIdPrefix(String)} does not alter string with lowercase "id:"
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating lack of "ID:" prefix, when the given string happens to begin with
+ * the {@link AmqpMessageIdHelper#AMQP_ULONG_PREFIX}.
*/
@Test
- public void testStripMessageIdPrefixWithLowercaseID() {
- String myLowerCaseNonId = "id:something";
- assertEquals("string with lowercase 'id:' prefix should have been returned unchanged", myLowerCaseNonId, _messageIdHelper.stripMessageIdPrefix(myLowerCaseNonId));
+ public void testToMessageIdStringWithStringBeginningWithEncodingPrefixForLong() {
+ String longStringMessageId = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + Long.valueOf(123456789L);
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + longStringMessageId;
+
+ doToMessageIdTestImpl(longStringMessageId, expected);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns null if given null
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating lack of "ID:" prefix, when the given string happens to begin with
+ * the {@link AmqpMessageIdHelper#AMQP_BINARY_PREFIX}.
*/
@Test
- public void testToBaseMessageIdStringWithNull() {
- String nullString = null;
- assertNull("null string should have been returned", _messageIdHelper.toBaseMessageIdString(nullString));
+ public void testToMessageIdStringWithStringBeginningWithEncodingPrefixForBinary() {
+ String binaryStringMessageId = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "0123456789ABCDEF";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + binaryStringMessageId;
+
+ doToMessageIdTestImpl(binaryStringMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating lack of "ID:" prefix, when the given string happens to begin with
+ * the {@link AmqpMessageIdHelper#AMQP_STRING_PREFIX}.
+ */
+ @Test
+ public void testToMessageIdStringWithStringBeginningWithEncodingPrefixForString() {
+ String stringMessageId = AmqpMessageIdHelper.AMQP_STRING_PREFIX + "myStringId";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + stringMessageId;
+
+ doToMessageIdTestImpl(stringMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating lack of "ID:" prefix, effectively twice, when the given string happens to
+ * begin with the {@link AmqpMessageIdHelper#AMQP_NO_PREFIX}.
+ */
+ @Test
+ public void testToMessageIdStringWithStringBeginningWithEncodingPrefixForNoIdPrefix() {
+ String stringMessageId = AmqpMessageIdHelper.AMQP_NO_PREFIX + "myStringId";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + stringMessageId;
+
+ doToMessageIdTestImpl(stringMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an AMQP encoded UUID when given a UUID object.
+ */
+ @Test
+ public void testToMessageIdStringWithUUID() {
+ UUID uuidMessageId = UUID.randomUUID();
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuidMessageId.toString();
+
+ doToMessageIdTestImpl(uuidMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an AMQP encoded ulong when given a UnsignedLong object.
+ */
+ @Test
+ public void testToMessageIdStringWithUnsignedLong() {
+ UnsignedLong uLongMessageId = UnsignedLong.valueOf(123456789L);
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + uLongMessageId.toString();
+
+ doToMessageIdTestImpl(uLongMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an AMQP encoded binary when given a Binary object.
+ */
+ @Test
+ public void testToMessageIdStringWithBinary() {
+ byte[] bytes = new byte[] { (byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF };
+ Binary binary = new Binary(bytes);
+
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF";
+
+ doToMessageIdTestImpl(binary, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_STRING_PREFIX}.
+ */
+ @Test
+ public void testToMessageIdStringWithStringBeginningWithIdAndEncodingPrefixForString() {
+ String unescapedStringPrefixMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + "id-content";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedStringPrefixMessageId;
+
+ doToMessageIdTestImpl(unescapedStringPrefixMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_UUID_PREFIX}.
+ */
+ @Test
+ public void testToMessageIdStringWithStringBeginningWithIdAndEncodingPrefixForUUID() {
+ String unescapedUuidPrefixMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + UUID.randomUUID();
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedUuidPrefixMessageId;
+
+ doToMessageIdTestImpl(unescapedUuidPrefixMessageId, expected);
+ }
+
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_ULONG_PREFIX}.
+ */
+ @Test
+ public void testToMessageIdStringWithStringBeginningWithIdAndEncodingPrefixForUlong() {
+ String unescapedUlongPrefixMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + "42";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedUlongPrefixMessageId;
+
+ doToMessageIdTestImpl(unescapedUlongPrefixMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_BINARY_PREFIX}.
+ */
+ @Test
+ public void testToMessageIdStringWithStringBeginningWithIdAndEncodingPrefixForBinary() {
+ String unescapedBinaryPrefixMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "ABCDEF";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedBinaryPrefixMessageId;
+
+ doToMessageIdTestImpl(unescapedBinaryPrefixMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toMessageIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_NO_PREFIX}.
+ */
+ @Test
+ public void testToMessageIdStringWithStringBeginningWithIdAndEncodingPrefixForNoIDPrefix() {
+ String unescapedBinaryPrefixMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + "id-content";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedBinaryPrefixMessageId;
+
+ doToMessageIdTestImpl(unescapedBinaryPrefixMessageId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns null if given null
+ */
+ @Test
+ public void testToCorrelationIdStringWithNull() {
+ assertNull("null string should have been returned", _messageIdHelper.toCorrelationIdString(null));
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} throws an IAE if given an unexpected object type.
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} throws an IAE if given an unexpected object type.
*/
@Test
- public void testToBaseMessageIdStringThrowsIAEWithUnexpectedType() {
+ public void testToCorrelationIdStringThrowsIAEWithUnexpectedType() {
try {
- _messageIdHelper.toBaseMessageIdString(new Object());
+ _messageIdHelper.toCorrelationIdString(new Object());
fail("expected exception not thrown");
} catch (IllegalArgumentException iae) {
// expected
}
}
+ private void doToCorrelationIDTestImpl(Object idObject, String expected) {
+ String idString = _messageIdHelper.toCorrelationIdString(idObject);
+ assertNotNull("null string should not have been returned", idString);
+ assertEquals("expected id string was not returned", expected, idString);
+ }
+
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns the given
- * basic string unchanged
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns the given
+ * basic string unchanged when it has the "ID:" prefix (but no others).
*/
@Test
- public void testToBaseMessageIdStringWithString() {
- String stringMessageId = "myIdString";
+ public void testToCorrelationIdStringWithString() {
+ String stringId = "ID:myCorrelationIdString";
- String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(stringMessageId);
- assertNotNull("null string should not have been returned", baseMessageIdString);
- assertEquals("expected base id string was not returned", stringMessageId, baseMessageIdString);
+ doToCorrelationIDTestImpl(stringId, stringId);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns a string
- * indicating an AMQP encoded string, when the given string happens to already begin with
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns the given
+ * basic string unchanged when it lacks the "ID:" prefix (and any others)
+ */
+ @Test
+ public void testToCorrelationIdStringWithStringNoPrefix() {
+ String stringNoId = "myCorrelationIdString";
+
+ doToCorrelationIDTestImpl(stringNoId, stringNoId);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * unchanged when it lacks the "ID:" prefix but happens to already begin with
* the {@link AmqpMessageIdHelper#AMQP_UUID_PREFIX}.
*/
@Test
- public void testToBaseMessageIdStringWithStringBeginningWithEncodingPrefixForUUID() {
- String uuidStringMessageId = AmqpMessageIdHelper.AMQP_UUID_PREFIX + UUID.randomUUID();
- String expected = AmqpMessageIdHelper.AMQP_STRING_PREFIX + uuidStringMessageId;
+ public void testToCorrelationIdStringWithStringBeginningWithEncodingPrefixForUUID() {
+ String uuidPrefixStringCorrelationId = AmqpMessageIdHelper.AMQP_UUID_PREFIX + UUID.randomUUID();
- String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(uuidStringMessageId);
- assertNotNull("null string should not have been returned", baseMessageIdString);
- assertEquals("expected base id string was not returned", expected, baseMessageIdString);
+ doToCorrelationIDTestImpl(uuidPrefixStringCorrelationId, uuidPrefixStringCorrelationId);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns a string
- * indicating an AMQP encoded string, when the given string happens to already begin with
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * unchanged when it lacks the "ID:" prefix but happens to already begin with
* the {@link AmqpMessageIdHelper#AMQP_ULONG_PREFIX}.
*/
@Test
- public void testToBaseMessageIdStringWithStringBeginningWithEncodingPrefixForLong() {
- String longStringMessageId = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + Long.valueOf(123456789L);
- String expected = AmqpMessageIdHelper.AMQP_STRING_PREFIX + longStringMessageId;
+ public void testToCorrelationIdStringWithStringBeginningWithEncodingPrefixForLong() {
+ String ulongPrefixStringCorrelationId = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + Long.valueOf(123456789L);
- String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(longStringMessageId);
- assertNotNull("null string should not have been returned", baseMessageIdString);
- assertEquals("expected base id string was not returned", expected, baseMessageIdString);
+ doToCorrelationIDTestImpl(ulongPrefixStringCorrelationId, ulongPrefixStringCorrelationId);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns a string
- * indicating an AMQP encoded string, when the given string happens to already begin with
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * unchanged when it lacks the "ID:" prefix but happens to already begin with
* the {@link AmqpMessageIdHelper#AMQP_BINARY_PREFIX}.
*/
@Test
- public void testToBaseMessageIdStringWithStringBeginningWithEncodingPrefixForBinary() {
- String binaryStringMessageId = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "0123456789ABCDEF";
- String expected = AmqpMessageIdHelper.AMQP_STRING_PREFIX + binaryStringMessageId;
+ public void testToCorrelationIdStringWithStringBeginningWithEncodingPrefixForBinary() {
+ String binaryPrefixStringCorrelationId = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "0123456789ABCDEF";
- String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(binaryStringMessageId);
- assertNotNull("null string should not have been returned", baseMessageIdString);
- assertEquals("expected base id string was not returned", expected, baseMessageIdString);
+ doToCorrelationIDTestImpl(binaryPrefixStringCorrelationId, binaryPrefixStringCorrelationId);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns a string
- * indicating an AMQP encoded string (effectively twice), when the given string happens to already begin with
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * unchanged when it lacks the "ID:" prefix but happens to already begin with
* the {@link AmqpMessageIdHelper#AMQP_STRING_PREFIX}.
*/
@Test
- public void testToBaseMessageIdStringWithStringBeginningWithEncodingPrefixForString() {
- String stringMessageId = AmqpMessageIdHelper.AMQP_STRING_PREFIX + "myStringId";
- String expected = AmqpMessageIdHelper.AMQP_STRING_PREFIX + stringMessageId;
+ public void testToCorrelationIdStringWithStringBeginningWithEncodingPrefixForString() {
+ String stringPrefixCorrelationId = AmqpMessageIdHelper.AMQP_STRING_PREFIX + "myStringId";
+
+ doToCorrelationIDTestImpl(stringPrefixCorrelationId, stringPrefixCorrelationId);
+ }
- String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(stringMessageId);
- assertNotNull("null string should not have been returned", baseMessageIdString);
- assertEquals("expected base id string was not returned", expected, baseMessageIdString);
+ /**
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * unchanged when it lacks the "ID:" prefix but happens to already begin with
+ * the {@link AmqpMessageIdHelper#AMQP_NO_PREFIX}.
+ */
+ @Test
+ public void testToCorrelationIdStringWithStringBeginningWithEncodingPrefixForNoIdPrefix() {
+ String noPrefixStringCorrelationId = AmqpMessageIdHelper.AMQP_NO_PREFIX + "myStringId";
+
+ doToCorrelationIDTestImpl(noPrefixStringCorrelationId, noPrefixStringCorrelationId);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns a string
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
* indicating an AMQP encoded UUID when given a UUID object.
*/
@Test
- public void testToBaseMessageIdStringWithUUID() {
- UUID uuidMessageId = UUID.randomUUID();
- String expected = AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuidMessageId.toString();
+ public void testToCorrelationIdStringWithUUID() {
+ UUID uuidCorrelationId = UUID.randomUUID();
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuidCorrelationId.toString();
- String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(uuidMessageId);
- assertNotNull("null string should not have been returned", baseMessageIdString);
- assertEquals("expected base id string was not returned", expected, baseMessageIdString);
+ doToCorrelationIDTestImpl(uuidCorrelationId, expected);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns a string
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
* indicating an AMQP encoded ulong when given a UnsignedLong object.
*/
@Test
- public void testToBaseMessageIdStringWithUnsignedLong() {
- UnsignedLong uLongMessageId = UnsignedLong.valueOf(123456789L);
- String expected = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + uLongMessageId.toString();
+ public void testToCorrelationIdStringWithUnsignedLong() {
+ UnsignedLong uLongCorrelationId = UnsignedLong.valueOf(123456789L);
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + uLongCorrelationId.toString();
- String baseMessageIdString = _messageIdHelper.toBaseMessageIdString(uLongMessageId);
- assertNotNull("null string should not have been returned", baseMessageIdString);
- assertEquals("expected base id string was not returned", expected, baseMessageIdString);
+ doToCorrelationIDTestImpl(uLongCorrelationId, expected);
}
/**
- * Test that {@link AmqpMessageIdHelper#toBaseMessageIdString(Object)} returns a string
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
* indicating an AMQP encoded binary when given a Binary object.
*/
@Test
- public void testToBaseMessageIdStringWithBinary() {
+ public void testToCorrelationIdStringWithBinary() {
byte[] bytes = new byte[] { (byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF };
Binary binary = new Binary(bytes);
- String expected = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF";
+
+ doToCorrelationIDTestImpl(binary, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_STRING_PREFIX}.
+ */
+ @Test
+ public void testToCorrelationIdStringWithStringBeginningWithIdAndEncodingPrefixForString() {
+ String unescapedStringPrefixCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + "id-content";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedStringPrefixCorrelationId;
+
+ doToCorrelationIDTestImpl(unescapedStringPrefixCorrelationId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_UUID_PREFIX}.
+ */
+ @Test
+ public void testToCorrelationIdStringWithStringBeginningWithIdAndEncodingPrefixForUUID() {
+ String unescapedUuidPrefixCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + UUID.randomUUID();
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedUuidPrefixCorrelationId;
+
+ doToCorrelationIDTestImpl(unescapedUuidPrefixCorrelationId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_ULONG_PREFIX}.
+ */
+ @Test
+ public void testToCorrelationIdStringWithStringBeginningWithIdAndEncodingPrefixForUlong() {
+ String unescapedUlongPrefixCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + "42";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedUlongPrefixCorrelationId;
+
+ doToCorrelationIDTestImpl(unescapedUlongPrefixCorrelationId, expected);
+ }
- 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#toCorrelationIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_BINARY_PREFIX}.
+ */
+ @Test
+ public void testToCorrelationIdStringWithStringBeginningWithIdAndEncodingPrefixForBinary() {
+ String unescapedBinaryPrefixCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "ABCDEF";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedBinaryPrefixCorrelationId;
+
+ doToCorrelationIDTestImpl(unescapedBinaryPrefixCorrelationId, expected);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toCorrelationIdString(Object)} returns a string
+ * indicating an escaped string, when given an input string that already has
+ * the "ID:" prefix, but follows it with an encoding prefix, in this case
+ * the {@link AmqpMessageIdHelper#AMQP_NO_PREFIX}.
+ */
+ @Test
+ public void testToCorrelationIdStringWithStringBeginningWithIdAndEncodingPrefixForNoIDPrefix() {
+ String unescapedBinaryPrefixCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + "id-content";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedBinaryPrefixCorrelationId;
+
+ doToCorrelationIDTestImpl(unescapedBinaryPrefixCorrelationId, expected);
+ }
+
+ private void doToIdObjectTestImpl(String idString, Object expected) throws IdConversionException {
+ Object idObject = _messageIdHelper.toIdObject(idString);
+ assertNotNull("null object should not have been returned", idObject);
+ assertEquals("expected id object was not returned", expected, idObject);
}
/**
@@ -297,11 +548,9 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
@Test
public void testToIdObjectWithEncodedUlong() throws Exception {
UnsignedLong longId = UnsignedLong.valueOf(123456789L);
- String provided = AmqpMessageIdHelper.AMQP_ULONG_PREFIX + "123456789";
+ String provided = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + "123456789";
- Object idObject = _messageIdHelper.toIdObject(provided);
- assertNotNull("null object should not have been returned", idObject);
- assertEquals("expected id object was not returned", longId, idObject);
+ doToIdObjectTestImpl(provided, longId);
}
/**
@@ -315,11 +564,9 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
byte[] bytes = new byte[] { (byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF };
Binary binaryId = new Binary(bytes);
- String provided = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF";
+ String provided = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00AB09FF";
- Object idObject = _messageIdHelper.toIdObject(provided);
- assertNotNull("null object should not have been returned", idObject);
- assertEquals("expected id object was not returned", binaryId, idObject);
+ doToIdObjectTestImpl(provided, binaryId);
}
/**
@@ -344,11 +591,9 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
byte[] bytes = new byte[] { (byte) 0x00, (byte) 0xAB, (byte) 0x09, (byte) 0xFF };
Binary binaryId = new Binary(bytes);
- String provided = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00ab09ff";
+ String provided = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "00ab09ff";
- Object idObject = _messageIdHelper.toIdObject(provided);
- assertNotNull("null object should not have been returned", idObject);
- assertEquals("expected id object was not returned", binaryId, idObject);
+ doToIdObjectTestImpl(provided, binaryId);
}
/**
@@ -360,26 +605,50 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
@Test
public void testToIdObjectWithEncodedUuid() throws Exception {
UUID uuid = UUID.randomUUID();
- String provided = AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuid.toString();
+ String provided = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuid.toString();
- Object idObject = _messageIdHelper.toIdObject(provided);
- assertNotNull("null object should not have been returned", idObject);
- assertEquals("expected id object was not returned", uuid, idObject);
+ doToIdObjectTestImpl(provided, uuid);
}
/**
* Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns a string
- * when given a string without any type encoding prefix.
+ * unchanged when given a string without any prefix.
*
* @throws Exception if an error occurs during the test.
*/
@Test
- public void testToIdObjectWithStringContainingNoEncodingPrefix() throws Exception {
+ public void testToIdObjectWithAppSpecificString() throws Exception {
String stringId = "myStringId";
- Object idObject = _messageIdHelper.toIdObject(stringId);
- assertNotNull("null object should not have been returned", idObject);
- assertEquals("expected id object was not returned", stringId, idObject);
+ doToIdObjectTestImpl(stringId, stringId);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns a string
+ * unchanged when given a string with only the 'ID:' prefix.
+ *
+ * @throws Exception if an error occurs during the test.
+ */
+ @Test
+ public void testToIdObjectWithSimplIdString() throws Exception {
+ String stringId = "ID:myStringId";
+
+ doToIdObjectTestImpl(stringId, stringId);
+ }
+
+ /**
+ * Test that {@link AmqpMessageIdHelper#toIdObject(String)} returns the remainder of the
+ * provided string after removing the 'ID:' and {@link AmqpMessageIdHelper#AMQP_NO_PREFIX}
+ * prefix used to indicate it originally had no 'ID:' prefix [when arriving as a message id].
+ *
+ * @throws Exception if an error occurs during the test.
+ */
+ @Test
+ public void testToIdObjectWithStringContainingEncodingPrefixForNoIdPrefix() throws Exception {
+ String suffix = "myStringSuffix";
+ String stringId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + suffix;
+
+ doToIdObjectTestImpl(stringId, suffix);
}
/**
@@ -389,13 +658,11 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
* @throws Exception if an error occurs during the test.
*/
@Test
- public void testToIdObjectWithStringContainingStringEncodingPrefix() throws Exception {
+ public void testToIdObjectWithStringContainingIdStringEncodingPrefix() throws Exception {
String suffix = "myStringSuffix";
- String stringId = AmqpMessageIdHelper.AMQP_STRING_PREFIX + suffix;
+ String stringId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + suffix;
- Object idObject = _messageIdHelper.toIdObject(stringId);
- assertNotNull("null object should not have been returned", idObject);
- assertEquals("expected id object was not returned", suffix, idObject);
+ doToIdObjectTestImpl(stringId, suffix);
}
/**
@@ -407,13 +674,11 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
* @throws Exception if an error occurs during the test.
*/
@Test
- public void testToIdObjectWithStringContainingStringEncodingPrefixAndThenUuidPrefix() throws Exception {
+ public void testToIdObjectWithStringContainingIdStringEncodingPrefixAndThenUuidPrefix() throws Exception {
String encodedUuidString = AmqpMessageIdHelper.AMQP_UUID_PREFIX + UUID.randomUUID().toString();
- String stringId = AmqpMessageIdHelper.AMQP_STRING_PREFIX + encodedUuidString;
+ String stringId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + encodedUuidString;
- Object idObject = _messageIdHelper.toIdObject(stringId);
- assertNotNull("null object should not have been returned", idObject);
- assertEquals("expected id object was not returned", encodedUuidString, idObject);
+ doToIdObjectTestImpl(stringId, encodedUuidString);
}
/**
@@ -424,7 +689,7 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
*/
@Test
public void testToIdObjectWithStringContainingBinaryHexThrowsICEWithUnevenLengthString() {
- String unevenHead = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "123";
+ String unevenHead = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "123";
try {
_messageIdHelper.toIdObject(unevenHead);
@@ -447,7 +712,7 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
// char before '0'
char nonHexChar = '/';
- String nonHexString = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
+ String nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
try {
_messageIdHelper.toIdObject(nonHexString);
@@ -460,7 +725,7 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
// char after '9', before 'A'
nonHexChar = ':';
- nonHexString = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
+ nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
try {
_messageIdHelper.toIdObject(nonHexString);
@@ -473,7 +738,7 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
// char after 'F', before 'a'
nonHexChar = 'G';
- nonHexString = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
+ nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
try {
_messageIdHelper.toIdObject(nonHexString);
@@ -486,7 +751,7 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
// char after 'f'
nonHexChar = 'g';
- nonHexString = AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
+ nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar;
try {
_messageIdHelper.toIdObject(nonHexString);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/3] qpid-jms git commit: QPIDJMS-189: update handling of
JMSMessageID and JMSCorrelationID,
facilitate better interop with non-JMS peers when round tripping for
correlation
Posted by ro...@apache.org.
QPIDJMS-189: update handling of JMSMessageID and JMSCorrelationID, facilitate better interop with non-JMS peers when round tripping for correlation
- Send the 'ID:' prefix of JMSMessageID values on the wire [Deliberately, as opposed to accidentally as started happening].
- Use the 'ID:' prefix on the wire for string based correlation-id values to distinguish whether they are application-specific or JMSMessageID based values.
- Use AMQP_NO_PREFIX to escape arriving message-id strings that dont have the 'ID:' prefix so they can be correctly round tripped back as correlation-id.
- Account for arriving message-id and correlation-id strings that start with 'ID:' *then* an encoding prefix, ensure they roundtrip correctly to JMSCorrelationID.
- Add PREFIXED_UUID_STRING option for sent message-id, leave existing option sending stringified UUID only.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/7b34f4fc
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/7b34f4fc
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/7b34f4fc
Branch: refs/heads/master
Commit: 7b34f4fc3f62bc04dff36cdf0e110e6436a66dc9
Parents: 9e99233
Author: Robert Gemmell <ro...@apache.org>
Authored: Thu Sep 1 15:56:42 2016 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Thu Sep 1 15:56:42 2016 +0100
----------------------------------------------------------------------
.../qpid/jms/message/JmsMessageIDBuilder.java | 25 +-
.../message/JmsMessagePropertyIntercepter.java | 2 +-
.../jms/message/facade/JmsMessageFacade.java | 3 +-
.../amqp/message/AmqpJmsMessageFacade.java | 60 +--
.../amqp/message/AmqpMessageIdHelper.java | 177 ++++---
.../amqp/message/AmqpMessageSupport.java | 6 -
.../jms/integration/MessageIntegrationTest.java | 180 ++++---
.../integration/ProducerIntegrationTest.java | 78 ++-
.../amqp/message/AmqpJmsMessageFacadeTest.java | 125 +++--
.../amqp/message/AmqpMessageIdHelperTest.java | 523 ++++++++++++++-----
10 files changed, 783 insertions(+), 396 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessageIDBuilder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessageIDBuilder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessageIDBuilder.java
index f9555fe..66d6487 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessageIDBuilder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessageIDBuilder.java
@@ -18,6 +18,8 @@ package org.apache.qpid.jms.message;
import java.util.Locale;
+import org.apache.qpid.jms.provider.amqp.message.AmqpMessageIdHelper;
+
/**
* Interface for creating a custom Message ID builder to populate the
* Message ID field of the outgoing message.
@@ -32,7 +34,11 @@ public interface JmsMessageIDBuilder {
@Override
public Object createMessageID(String producerId, long messageSequence) {
- return producerId + "-" + messageSequence;
+ String messageId = producerId + "-" + messageSequence;
+ if (!AmqpMessageIdHelper.INSTANCE.hasMessageIdPrefix(messageId)) {
+ messageId = AmqpMessageIdHelper.JMS_ID_PREFIX + messageId;
+ }
+ return messageId;
}
@Override
@@ -75,6 +81,23 @@ public interface JmsMessageIDBuilder {
}
};
}
+ },
+ PREFIXED_UUID_STRING {
+ @Override
+ public JmsMessageIDBuilder createBuilder() {
+ return new JmsMessageIDBuilder() {
+
+ @Override
+ public Object createMessageID(String producerId, long messageSequence) {
+ return AmqpMessageIdHelper.JMS_ID_PREFIX + java.util.UUID.randomUUID().toString();
+ }
+
+ @Override
+ public String toString() {
+ return PREFIXED_UUID_STRING.name();
+ }
+ };
+ }
};
public abstract JmsMessageIDBuilder createBuilder();
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessagePropertyIntercepter.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessagePropertyIntercepter.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessagePropertyIntercepter.java
index 64d400d..418d85c 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessagePropertyIntercepter.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/JmsMessagePropertyIntercepter.java
@@ -331,7 +331,7 @@ public class JmsMessagePropertyIntercepter {
}
@Override
- public void clearProperty(JmsMessage message) {
+ public void clearProperty(JmsMessage message) throws JMSException {
message.getFacade().setMessageId(null);
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/facade/JmsMessageFacade.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/facade/JmsMessageFacade.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/facade/JmsMessageFacade.java
index 35be150..1741251 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/facade/JmsMessageFacade.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/message/facade/JmsMessageFacade.java
@@ -195,8 +195,9 @@ public interface JmsMessageFacade {
*
* @param messageId
* The message ID to set on this message, or null to clear.
+ * @throws JMSException if an error occurs while setting the message ID.
*/
- void setMessageId(String messageId);
+ void setMessageId(String messageId) throws JMSException;
/**
* @return true if this message is tagged as being persistent.
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
index ff36db7..f98dccc 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacade.java
@@ -323,16 +323,7 @@ public class AmqpJmsMessageFacade implements JmsMessageFacade {
@Override
public String getMessageId() {
Object underlying = message.getMessageId();
- AmqpMessageIdHelper helper = AmqpMessageIdHelper.INSTANCE;
- String baseStringId = helper.toBaseMessageIdString(underlying);
-
- // Ensure the ID: prefix is present.
- // TODO: should we always do this when non-null? AMQP JMS Mapping says never to send the "ID:" prefix.
- if (baseStringId != null && !helper.hasMessageIdPrefix(baseStringId)) {
- baseStringId = AmqpMessageIdHelper.JMS_ID_PREFIX + baseStringId;
- }
-
- return baseStringId;
+ return AmqpMessageIdHelper.INSTANCE.toMessageIdString(underlying);
}
@Override
@@ -346,14 +337,8 @@ public class AmqpJmsMessageFacade implements JmsMessageFacade {
}
@Override
- public void setMessageId(String messageId) {
- if (messageId == null) {
- message.setMessageId(null);
- } else {
- // Remove the first 'ID:' prefix if present
- String stripped = AmqpMessageIdHelper.INSTANCE.stripMessageIdPrefix(messageId);
- message.setMessageId(stripped);
- }
+ public void setMessageId(String messageId) throws IdConversionException {
+ message.setMessageId(AmqpMessageIdHelper.INSTANCE.toIdObject(messageId));
}
@Override
@@ -381,50 +366,23 @@ public class AmqpJmsMessageFacade implements JmsMessageFacade {
@Override
public String getCorrelationId() {
- AmqpMessageIdHelper messageIdHelper = AmqpMessageIdHelper.INSTANCE;
- String baseIdString = messageIdHelper.toBaseMessageIdString(message.getCorrelationId());
-
- if (baseIdString == null) {
- return null;
- } else {
- Object annotation = getMessageAnnotation(AmqpMessageSupport.JMS_APP_CORRELATION_ID);
- boolean appSpecific = Boolean.TRUE.equals(annotation);
-
- if (appSpecific) {
- return baseIdString;
- } else {
- return AmqpMessageIdHelper.JMS_ID_PREFIX + baseIdString;
- }
- }
+ return AmqpMessageIdHelper.INSTANCE.toCorrelationIdString(message.getCorrelationId());
}
@Override
public void setCorrelationId(String correlationId) throws IdConversionException {
- AmqpMessageIdHelper messageIdHelper = AmqpMessageIdHelper.INSTANCE;
- boolean appSpecific = false;
if (correlationId == null) {
message.setCorrelationId(null);
} else {
- boolean hasMessageIdPrefix = messageIdHelper.hasMessageIdPrefix(correlationId);
- if (!hasMessageIdPrefix) {
- appSpecific = true;
- }
-
- String stripped = messageIdHelper.stripMessageIdPrefix(correlationId);
-
- if (hasMessageIdPrefix) {
- Object idObject = messageIdHelper.toIdObject(stripped);
+ if (AmqpMessageIdHelper.INSTANCE.hasMessageIdPrefix(correlationId)) {
+ // JMSMessageID value, process it for possible type conversion
+ Object idObject = AmqpMessageIdHelper.INSTANCE.toIdObject(correlationId);
message.setCorrelationId(idObject);
} else {
- message.setCorrelationId(stripped);
+ // application-specific value, send as-is
+ message.setCorrelationId(correlationId);
}
}
-
- if (appSpecific) {
- setMessageAnnotation(AmqpMessageSupport.JMS_APP_CORRELATION_ID, true);
- } else {
- removeMessageAnnotation(AmqpMessageSupport.JMS_APP_CORRELATION_ID);
- }
}
@Override
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/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 f6f0b5f..3c8d67a 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
@@ -55,13 +55,16 @@ public class AmqpMessageIdHelper {
public static final String AMQP_UUID_PREFIX = "AMQP_UUID:";
public static final String AMQP_ULONG_PREFIX = "AMQP_ULONG:";
public static final String AMQP_BINARY_PREFIX = "AMQP_BINARY:";
+ public static final String AMQP_NO_PREFIX = "AMQP_NO_PREFIX:";
public static final String JMS_ID_PREFIX = "ID:";
+ private static final String AMQP_PREFIX = "AMQP_";
private static final int JMS_ID_PREFIX_LENGTH = JMS_ID_PREFIX.length();
private static final int AMQP_UUID_PREFIX_LENGTH = AMQP_UUID_PREFIX.length();
private static final int AMQP_ULONG_PREFIX_LENGTH = AMQP_ULONG_PREFIX.length();
private static final int AMQP_STRING_PREFIX_LENGTH = AMQP_STRING_PREFIX.length();
private static final int AMQP_BINARY_PREFIX_LENGTH = AMQP_BINARY_PREFIX.length();
+ private static final int AMQP_NO_PREFIX_LENGTH = AMQP_NO_PREFIX.length();
private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
/**
@@ -78,116 +81,158 @@ public class AmqpMessageIdHelper {
return string.startsWith(JMS_ID_PREFIX);
}
- /**
- * Returns the suffix of the given string after removing the first "ID:" prefix (if present).
- *
- * @param id the string to process
- * @return the suffix, or the original String if the "ID:" prefix is not present
- */
- public String stripMessageIdPrefix(String id) {
- if (hasMessageIdPrefix(id)) {
- return strip(id, JMS_ID_PREFIX_LENGTH);
+ public String toMessageIdString(Object idObject) {
+ if (idObject instanceof String) {
+ final String stringId = (String) idObject;
+
+ boolean hasMessageIdPrefix = hasMessageIdPrefix(stringId);
+ if (!hasMessageIdPrefix) {
+ // For JMSMessageID, has no "ID:" prefix, we need to record
+ // that for later use as a JMSCorrelationID.
+ return JMS_ID_PREFIX + AMQP_NO_PREFIX + stringId;
+ } else if (hasTypeEncodingPrefix(stringId, JMS_ID_PREFIX_LENGTH)) {
+ // We are for a JMSMessageID value, but have 'ID:' followed by
+ // one of the encoding prefixes. Need to escape the entire string
+ // to preserve for later re-use as a JMSCorrelationID.
+ return JMS_ID_PREFIX + AMQP_STRING_PREFIX + stringId;
+ } else {
+ // It has "ID:" prefix and doesn't have encoding prefix, use it as-is.
+ return stringId;
+ }
} else {
- return id;
+ // Not a string, convert it
+ return convertToIdString(idObject);
}
}
- private String strip(String id, int numChars) {
- return id.substring(numChars);
+ public String toCorrelationIdString(Object idObject) {
+
+ if (idObject instanceof String) {
+ final String stringId = (String) idObject;
+
+ boolean hasMessageIdPrefix = hasMessageIdPrefix(stringId);
+ if (!hasMessageIdPrefix) {
+ // For JMSCorrelationID, has no "ID:" prefix, use it as-is.
+ return stringId;
+ } else if (hasTypeEncodingPrefix(stringId, JMS_ID_PREFIX_LENGTH)) {
+ // We are for a JMSCorrelationID value, but have 'ID:' followed by
+ // one of the encoding prefixes. Need to escape the entire string
+ // to preserve for later re-use as a JMSCorrelationID.
+ return JMS_ID_PREFIX + AMQP_STRING_PREFIX + stringId;
+ } else {
+ // It has "ID:" prefix and doesn't have encoding prefix, use it as-is.
+ return stringId;
+ }
+ } else {
+ // Not a string, convert it
+ return convertToIdString(idObject);
+ }
}
/**
- * Takes the provided amqp messageId style object, and convert it to a base string.
- * Encodes type information as a prefix where necessary to convey or escape the type
- * of the provided object.
+ * Takes the provided non-String AMQP message-id/correlation-id object, and
+ * convert it it to a String usable as either a JMSMessageID or JMSCorrelationID
+ * value, encoding the type information as a prefix to convey for later use
+ * in reversing the process if used to set JMSCorrelationID on a message.
*
- * @param messageId the object to process
- * @return the base string to be used in creating the actual JMS id.
+ * @param idObject the object to process
+ * @return string to be used for the actual JMS ID.
*/
- public String toBaseMessageIdString(Object messageId) {
- if (messageId == null) {
+ private String convertToIdString(Object idObject) {
+ if (idObject == null) {
return null;
- } else if (messageId instanceof String) {
- String stringId = (String) messageId;
-
- // If the given string has a type encoding prefix,
- // we need to escape it as an encoded string (even if
- // the existing encoding prefix was also for string)
- if (hasTypeEncodingPrefix(stringId)) {
- return AMQP_STRING_PREFIX + stringId;
- } else {
- return stringId;
- }
- } else if (messageId instanceof UUID) {
- return AMQP_UUID_PREFIX + messageId.toString();
- } else if (messageId instanceof UnsignedLong) {
- return AMQP_ULONG_PREFIX + messageId.toString();
- } else if (messageId instanceof Binary) {
- ByteBuffer dup = ((Binary) messageId).asByteBuffer();
+ }
+
+ if (idObject instanceof UUID) {
+ return JMS_ID_PREFIX + AMQP_UUID_PREFIX + idObject.toString();
+ } else if (idObject instanceof UnsignedLong) {
+ return JMS_ID_PREFIX + AMQP_ULONG_PREFIX + idObject.toString();
+ } else if (idObject instanceof Binary) {
+ ByteBuffer dup = ((Binary) idObject).asByteBuffer();
byte[] bytes = new byte[dup.remaining()];
dup.get(bytes);
String hex = convertBinaryToHexString(bytes);
- return AMQP_BINARY_PREFIX + hex;
+ return JMS_ID_PREFIX + AMQP_BINARY_PREFIX + hex;
} else {
- throw new IllegalArgumentException("Unsupported type provided: " + messageId.getClass());
+ throw new IllegalArgumentException("Unsupported type provided: " + idObject.getClass());
}
}
- private boolean hasTypeEncodingPrefix(String stringId) {
- return hasAmqpBinaryPrefix(stringId) ||
- hasAmqpUuidPrefix(stringId) ||
- hasAmqpUlongPrefix(stringId) ||
- hasAmqpStringPrefix(stringId);
+ private boolean hasTypeEncodingPrefix(String stringId, int offset) {
+ if(!stringId.startsWith(AMQP_PREFIX, offset)){
+ return false;
+ }
+
+ return hasAmqpBinaryPrefix(stringId, offset) ||
+ hasAmqpUuidPrefix(stringId, offset) ||
+ hasAmqpUlongPrefix(stringId, offset) ||
+ hasAmqpStringPrefix(stringId, offset) ||
+ hasAmqpNoPrefix(stringId, offset);
+ }
+
+ private boolean hasAmqpStringPrefix(String stringId, int offset) {
+ return stringId.startsWith(AMQP_STRING_PREFIX, offset);
}
- private boolean hasAmqpStringPrefix(String stringId) {
- return stringId.startsWith(AMQP_STRING_PREFIX);
+ private boolean hasAmqpUlongPrefix(String stringId, int offset) {
+ return stringId.startsWith(AMQP_ULONG_PREFIX, offset);
}
- private boolean hasAmqpUlongPrefix(String stringId) {
- return stringId.startsWith(AMQP_ULONG_PREFIX);
+ private boolean hasAmqpUuidPrefix(String stringId, int offset) {
+ return stringId.startsWith(AMQP_UUID_PREFIX, offset);
}
- private boolean hasAmqpUuidPrefix(String stringId) {
- return stringId.startsWith(AMQP_UUID_PREFIX);
+ private boolean hasAmqpBinaryPrefix(String stringId, int offset) {
+ return stringId.startsWith(AMQP_BINARY_PREFIX, offset);
}
- private boolean hasAmqpBinaryPrefix(String stringId) {
- return stringId.startsWith(AMQP_BINARY_PREFIX);
+ private boolean hasAmqpNoPrefix(String stringId, int offset) {
+ return stringId.startsWith(AMQP_NO_PREFIX, offset);
}
/**
- * Takes the provided base id string and return the appropriate amqp messageId style object.
+ * Takes the provided id string and return the appropriate amqp messageId style object.
* Converts the type based on any relevant encoding information found as a prefix.
*
- * @param baseId the object to be converted
+ * @param origId the object to be converted
* @return the amqp messageId style object
* @throws IdConversionException if the provided baseId String indicates an encoded type but can't be converted to that type.
*/
- public Object toIdObject(String baseId) throws IdConversionException {
- if (baseId == null) {
+ public Object toIdObject(final String origId) throws IdConversionException {
+ if (origId == null) {
return null;
}
+ if(!AmqpMessageIdHelper.INSTANCE.hasMessageIdPrefix(origId)) {
+ // We have a string without any "ID:" prefix, it is an
+ // application-specific String, use it as-is.
+ return origId;
+ }
+
try {
- if (hasAmqpUuidPrefix(baseId)) {
- String uuidString = strip(baseId, AMQP_UUID_PREFIX_LENGTH);
+ if (hasAmqpNoPrefix(origId, JMS_ID_PREFIX_LENGTH)) {
+ // Prefix telling us there was originally no "ID:" prefix,
+ // strip it and return the remainder
+ return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_NO_PREFIX_LENGTH);
+ } else if (hasAmqpUuidPrefix(origId, JMS_ID_PREFIX_LENGTH)) {
+ String uuidString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_UUID_PREFIX_LENGTH);
return UUID.fromString(uuidString);
- } else if (hasAmqpUlongPrefix(baseId)) {
- String longString = strip(baseId, AMQP_ULONG_PREFIX_LENGTH);
- 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);
+ } else if (hasAmqpUlongPrefix(origId, JMS_ID_PREFIX_LENGTH)) {
+ String ulongString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_ULONG_PREFIX_LENGTH);
+ return UnsignedLong.valueOf(ulongString);
+ } else if (hasAmqpStringPrefix(origId, JMS_ID_PREFIX_LENGTH)) {
+ return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_STRING_PREFIX_LENGTH);
+ } else if (hasAmqpBinaryPrefix(origId, JMS_ID_PREFIX_LENGTH)) {
+ String hexString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_BINARY_PREFIX_LENGTH);
byte[] bytes = convertHexStringToBinary(hexString);
return new Binary(bytes);
} else {
- // We have a string without any type prefix, transmit it as-is.
- return baseId;
+ // We have a string without any encoding prefix needing processed,
+ // so transmit it as-is, including the "ID:"
+ return origId;
}
} catch (IllegalArgumentException e) {
throw new IdConversionException("Unable to convert ID value", e);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageSupport.java
index 4d93167..271481b 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageSupport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/message/AmqpMessageSupport.java
@@ -31,12 +31,6 @@ import io.netty.buffer.Unpooled;
public final class AmqpMessageSupport {
/**
- * Attribute used to mark the Application defined correlation Id that has been
- * set for the message.
- */
- public static final String JMS_APP_CORRELATION_ID = "x-opt-app-correlation-id";
-
- /**
* Attribute used to mark the class type of JMS message that a particular message
* instance represents, used internally by the client.
*/
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java
index 101a637..ec84479 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/MessageIntegrationTest.java
@@ -1385,14 +1385,28 @@ public class MessageIntegrationTest extends QpidJmsTestCase
}
/**
- * Tests that receiving a message with a string typed message-id results in returning the
- * expected value for JMSMessageId where the JMS "ID:" prefix has been added.
+ * Tests that receiving a message with a string typed message-id with "ID:" prefix results
+ * in returning the expected value for JMSMessageId .
*
* @throws Exception if an error occurs during the test.
*/
@Test(timeout = 20000)
public void testReceivedMessageWithStringMessageIdReturnsExpectedJMSMessageID() throws Exception {
- receivedMessageWithMessageIdTestImpl("myTestMessageIdString");
+ String messageId = "ID:myTestMessageIdString";
+ receivedMessageWithMessageIdTestImpl(messageId, messageId);
+ }
+
+ /**
+ * Tests that receiving a message with a string typed message-id with no "ID:" prefix results
+ * in returning the expected value for JMSMessageId where the JMS "ID:" prefix has been added.
+ *
+ * @throws Exception if an error occurs during the test.
+ */
+ @Test(timeout = 20000)
+ public void testReceivedMessageWithStringMessageIdNoPrefixReturnsExpectedJMSMessageID() throws Exception {
+ String messageIdNoPrefix = "myTestMessageIdString";
+ String expected = "ID:AMQP_NO_PREFIX:" + messageIdNoPrefix;
+ receivedMessageWithMessageIdTestImpl(messageIdNoPrefix, expected);
}
/**
@@ -1403,7 +1417,9 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithUUIDMessageIdReturnsExpectedJMSMessageID() throws Exception {
- receivedMessageWithMessageIdTestImpl(UUID.randomUUID());
+ UUID uuid = UUID.randomUUID();
+ String expected = "ID:AMQP_UUID:" + uuid.toString();
+ receivedMessageWithMessageIdTestImpl(uuid, expected);
}
/**
@@ -1414,7 +1430,9 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithUnsignedLongMessageIdReturnsExpectedJMSMessageID() throws Exception {
- receivedMessageWithMessageIdTestImpl(UnsignedLong.valueOf(123456789L));
+ UnsignedLong ulong = UnsignedLong.valueOf(123456789L);
+ String expected = "ID:AMQP_ULONG:123456789";
+ receivedMessageWithMessageIdTestImpl(ulong, expected);
}
/**
@@ -1425,10 +1443,12 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithBinaryMessageIdReturnsExpectedJMSMessageID() throws Exception {
- receivedMessageWithMessageIdTestImpl(new Binary(new byte[]{(byte)0x02, (byte)0x20, (byte) 0xAE, (byte) 0x00}));
+ Binary binary = new Binary(new byte[]{(byte)0x02, (byte)0x20, (byte) 0xAE, (byte) 0x00});
+ String expected = "ID:AMQP_BINARY:0220AE00";
+ receivedMessageWithMessageIdTestImpl(binary, expected);
}
- private void receivedMessageWithMessageIdTestImpl(Object underlyingAmqpMessageId) throws Exception {
+ private void receivedMessageWithMessageIdTestImpl(Object underlyingAmqpMessageId, String expected) throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
connection.start();
@@ -1452,33 +1472,37 @@ public class MessageIntegrationTest extends QpidJmsTestCase
assertNotNull(receivedMessage);
- String expectedBaseIdString = new AmqpMessageIdHelper().toBaseMessageIdString(underlyingAmqpMessageId);
-
- assertEquals("ID:" + expectedBaseIdString, receivedMessage.getJMSMessageID());
+ assertEquals(expected, receivedMessage.getJMSMessageID());
+ assertTrue(receivedMessage.getJMSMessageID().startsWith("ID:"));
}
}
/**
- * Tests that receiving a message with a string typed correlation-id results in returning the
- * expected value for JMSCorrelationID where the JMS "ID:" prefix has been added.
+ * Tests that receiving a message with a string typed correlation-id which is indicated
+ * to be a JMSMessageID by presence of "ID:" prefix, results in returning the
+ * expected value for JMSCorrelationID where the JMS "ID:" prefix is retained.
*
* @throws Exception if an error occurs during the test.
*/
@Test(timeout = 20000)
public void testReceivedMessageWithStringCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception {
- receivedMessageWithCorrelationIdTestImpl("myTestCorrelationIdString", false);
+ String underlyingCorrelationId = "ID:myTestCorrelationIdString";
+ String expected = underlyingCorrelationId;
+ receivedMessageWithCorrelationIdTestImpl(underlyingCorrelationId, expected);
}
/**
* Tests that receiving a message with a string typed correlation-id, which is indicated to be an
- * application-specific value, results in returning the expected value for JMSCorrelationID
- * where the JMS "ID:" prefix has NOT been added.
+ * application-specific value, by lacking the "ID:" prefix, results in returning the expected value
+ * for JMSCorrelationID where the JMS "ID:" prefix has NOT been added.
*
* @throws Exception if an error occurs during the test.
*/
@Test(timeout = 20000)
public void testReceivedMessageWithAppSpecificStringCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception {
- receivedMessageWithCorrelationIdTestImpl("myTestCorrelationIdString", true);
+ String underlyingCorrelationId = "myTestCorrelationIdString";
+ String expected = underlyingCorrelationId;
+ receivedMessageWithCorrelationIdTestImpl(underlyingCorrelationId, expected);
}
/**
@@ -1489,7 +1513,9 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithUUIDCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception {
- receivedMessageWithCorrelationIdTestImpl(UUID.randomUUID(), false);
+ UUID underlyingCorrelationId = UUID.randomUUID();
+ String expected = "ID:AMQP_UUID:" + underlyingCorrelationId.toString();
+ receivedMessageWithCorrelationIdTestImpl(underlyingCorrelationId, expected);
}
/**
@@ -1500,10 +1526,12 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithLongCorrelationIdReturnsExpectedJMSCorrelationID() throws Exception {
- receivedMessageWithCorrelationIdTestImpl(UnsignedLong.valueOf(123456789L), false);
+ UnsignedLong underlyingCorrelationId = UnsignedLong.valueOf(123456789L);
+ String expected = "ID:AMQP_ULONG:" + underlyingCorrelationId.toString();
+ receivedMessageWithCorrelationIdTestImpl(underlyingCorrelationId, expected);
}
- private void receivedMessageWithCorrelationIdTestImpl(Object correlationIdForAmqpMessageClass, boolean appSpecific) throws Exception {
+ private void receivedMessageWithCorrelationIdTestImpl(Object underlyingCorrelationId, String expected) throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
connection.start();
@@ -1515,17 +1543,12 @@ public class MessageIntegrationTest extends QpidJmsTestCase
PropertiesDescribedType props = new PropertiesDescribedType();
DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);
- MessageAnnotationsDescribedType ann = null;
props.setMessageId("myMessageIdString");
- props.setCorrelationId(correlationIdForAmqpMessageClass);
- if (appSpecific) {
- ann = new MessageAnnotationsDescribedType();
- ann.setSymbolKeyedAnnotation(AmqpMessageSupport.JMS_APP_CORRELATION_ID, true);
- }
+ props.setCorrelationId(underlyingCorrelationId);
testPeer.expectReceiverAttach();
- testPeer.expectLinkFlowRespondWithTransfer(null, ann, props, null, amqpValueNullContent);
+ testPeer.expectLinkFlowRespondWithTransfer(null, null, props, null, amqpValueNullContent);
testPeer.expectDispositionThatIsAcceptedAndSettled();
MessageConsumer messageConsumer = session.createConsumer(queue);
@@ -1533,11 +1556,6 @@ public class MessageIntegrationTest extends QpidJmsTestCase
testPeer.waitForAllHandlersToComplete(3000);
assertNotNull(receivedMessage);
- String expectedBaseIdString = new AmqpMessageIdHelper().toBaseMessageIdString(correlationIdForAmqpMessageClass);
- String expected = expectedBaseIdString;
- if (!appSpecific) {
- expected = "ID:" + expected;
- }
assertEquals(expected, receivedMessage.getJMSCorrelationID());
}
@@ -1555,14 +1573,13 @@ public class MessageIntegrationTest extends QpidJmsTestCase
public void testSentMessageWithUUIDCorrelationId() throws Exception {
UUID uuid = UUID.randomUUID();
String stringCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + uuid.toString();
- sentMessageWithCorrelationIdTestImpl(stringCorrelationId, uuid, false);
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, uuid);
}
/**
* Tests that sending a message with a binary typed correlation-id value which is a
* message-id results in an AMQP message with the expected encoding of the correlation-id,
- * where the type is binary, the "ID:" prefix of the JMSCorrelationID value is (obviously) not present, and there is
- * no presence of the message annotation to indicate an app-specific correlation-id.
+ * where the type is binary, the "ID:" prefix of the JMSCorrelationID value is (obviously) not present.
*
* @throws Exception if an error occurs during the test.
*/
@@ -1571,14 +1588,13 @@ public class MessageIntegrationTest extends QpidJmsTestCase
{
Binary bin = new Binary(new byte[]{(byte)0x01, (byte)0x23, (byte) 0xAF, (byte) 0x00});
String stringCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + "0123af00";
- sentMessageWithCorrelationIdTestImpl(stringCorrelationId, bin, false);
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, bin);
}
/**
* Tests that sending a message with a ulong typed correlation-id value which is a
* message-id results in an AMQP message with the expected encoding of the correlation-id,
- * where the type is ulong, the "ID:" prefix of the JMSCorrelationID value is (obviously) not present, and there is
- * no presence of the message annotation to indicate an app-specific correlation-id.
+ * where the type is ulong, the "ID:" prefix of the JMSCorrelationID value is (obviously) not present.
*
* @throws Exception if an error occurs during the test.
*/
@@ -1586,38 +1602,50 @@ public class MessageIntegrationTest extends QpidJmsTestCase
public void testSentMessageWithUlongCorrelationId() throws Exception {
UnsignedLong ulong = UnsignedLong.valueOf(Long.MAX_VALUE);
String stringCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + ulong.toString();
- sentMessageWithCorrelationIdTestImpl(stringCorrelationId, ulong, false);
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, ulong);
}
/**
* Tests that sending a message with a string typed correlation-id value which is a
* message-id results in an AMQP message with the expected encoding of the correlation-id,
- * where the "ID:" prefix of the JMSCorrelationID value is not present, and there is
- * no presence of the message annotation to indicate an app-specific correlation-id.
+ * where the "ID:" prefix of the JMSCorrelationID value is still present
*
* @throws Exception if an error occurs during the test.
*/
@Test(timeout = 20000)
public void testSentMessageWithStringCorrelationId() throws Exception {
String stringCorrelationId = "ID:myTestMessageIdString";
- String underlyingCorrelationId = "myTestMessageIdString";
- sentMessageWithCorrelationIdTestImpl(stringCorrelationId, underlyingCorrelationId, false);
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, stringCorrelationId);
+ }
+
+ /**
+ * Tests that sending a message with a string typed correlation-id value which is came
+ * from a received message-id that lacked the "ID:" prefix and had it added, results in
+ * an AMQP message with the expected encoding of the correlation-id, where the
+ * the "ID:" prefix of the JMSCorrelationID value has been removed present
+ *
+ * @throws Exception if an error occurs during the test.
+ */
+ @Test(timeout = 20000)
+ public void testSentMessageWithNoPrefixEncodedStringCorrelationId() throws Exception {
+ String idSuffix = "myNoIdPrefixString";
+ String stringCorrelationId = "ID:" + AmqpMessageIdHelper.AMQP_NO_PREFIX + idSuffix;
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, idSuffix);
}
/**
* Tests that sending a message with a string typed correlation-id value which is a
- * app-specific results in an AMQP message with the expected encoding of the correlation-id,
- * and the presence of the message annotation to indicate an app-specific correlation-id.
+ * app-specific results in an AMQP message with the expected encoding of the correlation-id.
*
* @throws Exception if an error occurs during the test.
*/
@Test(timeout = 20000)
public void testSentMessageWithAppSpecificStringCorrelationId() throws Exception {
String stringCorrelationId = "myTestAppSpecificString";
- sentMessageWithCorrelationIdTestImpl(stringCorrelationId, stringCorrelationId, true);
+ sentMessageWithCorrelationIdTestImpl(stringCorrelationId, stringCorrelationId);
}
- private void sentMessageWithCorrelationIdTestImpl(String stringCorrelationId, Object correlationIdForAmqpMessageClass, boolean appSpecific) throws Exception {
+ private void sentMessageWithCorrelationIdTestImpl(String stringCorrelationId, Object correlationIdForAmqpMessageClass) throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
testPeer.expectBegin();
@@ -1632,12 +1660,8 @@ public class MessageIntegrationTest extends QpidJmsTestCase
MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true);
- //Set matcher to validate the correlation-id, and the annotation
- //presence+value if it is application-specific
+ //Set matcher to validate the correlation-id
propsMatcher.withCorrelationId(equalTo(correlationIdForAmqpMessageClass));
- if (appSpecific) {
- msgAnnotationsMatcher.withEntry(Symbol.valueOf(AmqpMessageSupport.JMS_APP_CORRELATION_ID), equalTo(Boolean.TRUE));
- }
TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
messageMatcher.setHeadersMatcher(headersMatcher);
@@ -1652,24 +1676,34 @@ public class MessageIntegrationTest extends QpidJmsTestCase
producer.send(message);
testPeer.waitForAllHandlersToComplete(3000);
-
- //validate the annotation was not present if the value was a message-id
- if (!appSpecific) {
- assertFalse(msgAnnotationsMatcher.keyExistsInReceivedAnnotations(Symbol.valueOf(AmqpMessageSupport.JMS_APP_CORRELATION_ID)));
- }
}
}
/**
- * Tests that receiving a message with a string typed message-id, and then sending a message which
- * uses the result of calling getJMSMessageID as the value for setJMSCorrelationId results in
- * transmission of the expected AMQP message content.
+ * Tests that receiving a message with a string typed message-id, that has the "ID:" prefix, and then sending
+ * a message which uses the result of calling getJMSMessageID as the value for setJMSCorrelationId
+ * results in transmission of the expected AMQP message content.
*
* @throws Exception if an error occurs during the test.
*/
@Test(timeout = 20000)
public void testReceivedMessageWithStringMessageIdAndSendValueAsCorrelationId() throws Exception {
- recieveMessageIdSendCorrelationIdTestImpl("myStringMessageId");
+ String string = "ID:myStringMessageId";
+ recieveMessageIdSendCorrelationIdTestImpl(string, string);
+ }
+
+ /**
+ * Tests that receiving a message with a string typed message-id, that has no "ID:" prefix, and then sending
+ * a message which uses the result of calling getJMSMessageID as the value for setJMSCorrelationId
+ * results in transmission of the expected AMQP message content.
+ *
+ * @throws Exception if an error occurs during the test.
+ */
+ @Test(timeout = 20000)
+ public void testReceivedMessageWithStringNoPrefixMessageIdAndSendValueAsCorrelationId() throws Exception {
+ String stringNoPrefix = "myStringMessageId";
+ String expected = "ID:AMQP_NO_PREFIX:" + stringNoPrefix;
+ recieveMessageIdSendCorrelationIdTestImpl(stringNoPrefix, expected);
}
/**
@@ -1681,7 +1715,9 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithUUIDMessageIdAndSendValueAsCorrelationId() throws Exception {
- recieveMessageIdSendCorrelationIdTestImpl(UUID.randomUUID());
+ UUID uuid = UUID.randomUUID();
+ String expected = "ID:AMQP_UUID:" + uuid.toString();
+ recieveMessageIdSendCorrelationIdTestImpl(uuid, expected);
}
/**
@@ -1693,7 +1729,9 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithUlongMessageIdAndSendValueAsCorrelationId() throws Exception {
- recieveMessageIdSendCorrelationIdTestImpl(UnsignedLong.valueOf(123456789L));
+ UnsignedLong ulong = UnsignedLong.valueOf(123456789L);
+ String expected = "ID:AMQP_ULONG:123456789";
+ recieveMessageIdSendCorrelationIdTestImpl(ulong, expected);
}
/**
@@ -1705,10 +1743,12 @@ public class MessageIntegrationTest extends QpidJmsTestCase
*/
@Test(timeout = 20000)
public void testReceivedMessageWithBinaryMessageIdAndSendValueAsCorrelationId() throws Exception {
- recieveMessageIdSendCorrelationIdTestImpl(new Binary(new byte[]{(byte)0x00, (byte)0xCD, (byte) 0xEF, (byte) 0x01}));
+ Binary binary = new Binary(new byte[]{(byte)0x00, (byte)0xCD, (byte) 0xEF, (byte) 0x01});
+ String expected = "ID:AMQP_BINARY:00CDEF01";
+ recieveMessageIdSendCorrelationIdTestImpl(binary, expected);
}
- private void recieveMessageIdSendCorrelationIdTestImpl(Object idForAmqpMessageClass) throws Exception {
+ private void recieveMessageIdSendCorrelationIdTestImpl(Object amqpIdObject, String expectedMessageId) throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
connection.start();
@@ -1719,7 +1759,7 @@ public class MessageIntegrationTest extends QpidJmsTestCase
Queue queue = session.createQueue("myQueue");
PropertiesDescribedType props = new PropertiesDescribedType();
- props.setMessageId(idForAmqpMessageClass);
+ props.setMessageId(amqpIdObject);
DescribedType amqpValueNullContent = new AmqpValueDescribedType(null);
testPeer.expectReceiverAttach();
@@ -1732,13 +1772,11 @@ public class MessageIntegrationTest extends QpidJmsTestCase
assertNotNull(receivedMessage);
- String expectedBaseIdString = new AmqpMessageIdHelper().toBaseMessageIdString(idForAmqpMessageClass);
-
String jmsMessageID = receivedMessage.getJMSMessageID();
- assertEquals("ID:" + expectedBaseIdString, jmsMessageID);
+ assertEquals("Unexpected value for JMSMessageID", expectedMessageId, jmsMessageID);
//Now take the received JMSMessageID, and send a message with it set
- //as the JMSCorrelationID and verify we get the same AMQP id as we started with.
+ //as the JMSCorrelationID and verify we send the same AMQP id as we started with.
testPeer.expectSenderAttach();
MessageProducer producer = session.createProducer(queue);
@@ -1747,8 +1785,8 @@ public class MessageIntegrationTest extends QpidJmsTestCase
MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true);
- //Set matcher to validate the correlation-id matches the previous message-id
- propsMatcher.withCorrelationId(equalTo(idForAmqpMessageClass));
+ //Set matcher to validate the correlation-id on the wire matches the previous message-id
+ propsMatcher.withCorrelationId(equalTo(amqpIdObject));
TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
messageMatcher.setHeadersMatcher(headersMatcher);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
index d16c713..9c2d2bf 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ProducerIntegrationTest.java
@@ -61,6 +61,7 @@ import org.apache.qpid.jms.JmsDefaultConnectionListener;
import org.apache.qpid.jms.JmsOperationTimedOutException;
import org.apache.qpid.jms.JmsSendTimedOutException;
import org.apache.qpid.jms.message.foreign.ForeignJmsMessage;
+import org.apache.qpid.jms.provider.amqp.message.AmqpMessageIdHelper;
import org.apache.qpid.jms.provider.amqp.message.AmqpMessageSupport;
import org.apache.qpid.jms.test.QpidJmsTestCase;
import org.apache.qpid.jms.test.Wait;
@@ -618,7 +619,7 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
Object receivedMessageId = propsMatcher.getReceivedMessageId();
assertTrue("Expected string message id to be sent", receivedMessageId instanceof String);
- assertTrue("Expected JMSMessageId value to be present in AMQP message", jmsMessageID.endsWith((String)receivedMessageId));
+ assertTrue("Expected JMSMessageId value to be present in AMQP message", jmsMessageID.equals(receivedMessageId));
}
}
@@ -677,7 +678,7 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
}
@Test(timeout=20000)
- public void testSendingMessageWithUUIDStringMessageFormat() throws Exception {
+ public void testSendingMessageWithUUIDStringMessageIdFormat() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
// DONT create a test fixture, we will drive everything directly.
String uri = "amqp://127.0.0.1:" + testPeer.getServerPort() + "?jms.messageIDPolicy.messageIDType=UUID_STRING";
@@ -716,16 +717,21 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
String jmsMessageID = message.getJMSMessageID();
assertNotNull("JMSMessageID should be set", jmsMessageID);
assertTrue("JMS 'ID:' prefix not found", jmsMessageID.startsWith("ID:"));
+ String noIdPrefix = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX;
+ assertTrue("The 'No ID prefix' encoding hint was not found", jmsMessageID.startsWith(noIdPrefix));
connection.close();
-
- // Get the value that was actually transmitted/received, verify it is a String, compare to what we have locally
testPeer.waitForAllHandlersToComplete(1000);
+ // Get the value that was actually transmitted/received, verify it is a String,
+ // verify it is only the UUID toString and has no "ID", check the encoded
+ // JMSMessageID value that we have locally.
Object receivedMessageId = propsMatcher.getReceivedMessageId();
- assertTrue("Expected UUID message id to be sent", receivedMessageId instanceof String);
- assertTrue("Expected JMSMessageId value to be present in AMQP message", jmsMessageID.endsWith(receivedMessageId.toString()));
+ String expected = jmsMessageID.substring(noIdPrefix.length());
+ UUID.fromString(expected);
+ assertTrue("Expected String message id to be sent", receivedMessageId instanceof String);
+ assertEquals("Expected UUID toString value to be present in AMQP message", expected, receivedMessageId);
}
}
@@ -784,7 +790,7 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
}
@Test(timeout=20000)
- public void testSendingMessageWithUUIDMessageFormat() throws Exception {
+ public void testSendingMessageWithUUIDMessageIdFormat() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
// DONT create a test fixture, we will drive everything directly.
String uri = "amqp://127.0.0.1:" + testPeer.getServerPort() + "?jms.messageIDPolicy.messageIDType=UUID";
@@ -823,6 +829,8 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
String jmsMessageID = message.getJMSMessageID();
assertNotNull("JMSMessageID should be set", jmsMessageID);
assertTrue("JMS 'ID:' prefix not found", jmsMessageID.startsWith("ID:"));
+ String uuidEncodingPrefix = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX;
+ assertTrue("The 'UUID prefix' encoding hint was not found", jmsMessageID.startsWith(uuidEncodingPrefix));
connection.close();
@@ -836,6 +844,62 @@ public class ProducerIntegrationTest extends QpidJmsTestCase {
}
}
+ @Test(timeout=20000)
+ public void testSendingMessageWithPrefixedUUIDStringMessageIdFormat() throws Exception {
+ try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+ // DONT create a test fixture, we will drive everything directly.
+ String uri = "amqp://127.0.0.1:" + testPeer.getServerPort() + "?jms.messageIDPolicy.messageIDType=PREFIXED_UUID_STRING";
+ JmsConnectionFactory factory = new JmsConnectionFactory(uri);
+
+ Connection connection = factory.createConnection();
+ testPeer.expectSaslAnonymousConnect();
+ testPeer.expectBegin();
+
+ testPeer.expectBegin();
+ testPeer.expectSenderAttach();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ String queueName = "myQueue";
+ Queue queue = session.createQueue(queueName);
+ MessageProducer producer = session.createProducer(queue);
+
+ String text = "myMessage";
+ MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true));
+ MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
+ MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true).withMessageId(isA(String.class));
+ TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
+ messageMatcher.setHeadersMatcher(headersMatcher);
+ messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
+ messageMatcher.setPropertiesMatcher(propsMatcher);
+ messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(text));
+ testPeer.expectTransfer(messageMatcher);
+ testPeer.expectClose();
+
+ Message message = session.createTextMessage(text);
+
+ assertNull("JMSMessageID should not yet be set", message.getJMSMessageID());
+
+ producer.send(message);
+
+ String jmsMessageID = message.getJMSMessageID();
+ assertNotNull("JMSMessageID should be set", jmsMessageID);
+ assertTrue("JMS 'ID:' prefix not found", jmsMessageID.startsWith("ID:"));
+
+ connection.close();
+ testPeer.waitForAllHandlersToComplete(1000);
+
+ // Get the value that was actually transmitted/received, verify it is a String,
+ // verify it is the "ID:" prefix followed by the UUID toString, check the
+ // JMSMessageID value that we have locally matches exactly.
+ Object receivedMessageId = propsMatcher.getReceivedMessageId();
+
+ String uuidToString = jmsMessageID.substring("ID:".length());
+ UUID.fromString(uuidToString);
+ assertTrue("Expected String message id to be sent", receivedMessageId instanceof String);
+ assertEquals("Expected UUID toString value to be present in AMQP message", jmsMessageID, receivedMessageId);
+ }
+ }
+
/**
* Test that after sending a message with the disableMessageID hint set, the message
* object has a null JMSMessageID value, and no message-id field value was set.
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7b34f4fc/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
index 597d01f..e7956e8 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
@@ -861,8 +861,7 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
/**
* Test that setting then getting an application-specific String as the CorrelationId returns
- * the expected value and sets the expected value on the underlying AMQP message, additionally
- * setting the annotation to indicate an application-specific correlation-id
+ * the expected value and sets the expected value on the underlying AMQP message.
* @throws Exception if unexpected error
*/
@Test
@@ -873,35 +872,26 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
amqpMessageFacade.setCorrelationId(testCorrelationId);
Message amqpMessage = amqpMessageFacade.getAmqpMessage();
- assertEquals("Unexpected correlationId value on underlying AMQP message", testCorrelationId, amqpMessage.getCorrelationId());
+ assertEquals("correlationId value on underlying AMQP message not as expected", testCorrelationId, amqpMessage.getCorrelationId());
assertEquals("Expected correlationId not returned", testCorrelationId, amqpMessageFacade.getCorrelationId());
- MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
- assertNotNull("Message Annotations not present", messageAnnotations);
- Object annotation = messageAnnotations.getValue().get(Symbol.valueOf(AmqpMessageSupport.JMS_APP_CORRELATION_ID));
- assertTrue("Message annotation " + AmqpMessageSupport.JMS_APP_CORRELATION_ID + " not set as expected", Boolean.TRUE.equals(annotation));
}
/**
* Test that setting then getting an JMSMessageID String as the CorrelationId returns
- * the expected value and sets the expected value on the underlying AMQP message, additionally
- * checking it does not set the annotation to indicate an application-specific correlation-id
+ * the expected value and sets the expected value on the underlying AMQP message
* @throws Exception if unexpected error
*/
@Test
public void testSetGetCorrelationIdOnNewMessageWithStringJMSMessageID() throws Exception {
String testCorrelationId = "ID:myJMSMessageIDStringCorrelationId";
- //The underlying AMQP message should not contain the ID: prefix
- String stripped = AmqpMessageIdHelper.INSTANCE.stripMessageIdPrefix(testCorrelationId);
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
amqpMessageFacade.setCorrelationId(testCorrelationId);
Message amqpMessage = amqpMessageFacade.getAmqpMessage();
- assertEquals("Unexpected correlationId value on underlying AMQP message", stripped, amqpMessage.getCorrelationId());
+ assertEquals("correlationId value on underlying AMQP message not as expected", testCorrelationId, amqpMessage.getCorrelationId());
assertEquals("Expected correlationId not returned from facade", testCorrelationId, amqpMessageFacade.getCorrelationId());
-
- assertNull("Message annotation " + AmqpMessageSupport.JMS_APP_CORRELATION_ID + " not null as expected", amqpMessageFacade.getMessageAnnotation(AmqpMessageSupport.JMS_APP_CORRELATION_ID));
}
/**
@@ -926,17 +916,19 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
*/
@Test
public void testGetCorrelationIdOnReceivedMessageWithStringAppSpecific() {
- correlationIdOnReceivedMessageTestImpl("myCorrelationIdString", true);
+ String testCorrelationId = "myCorrelationIdString";
+ correlationIdOnReceivedMessageTestImpl(testCorrelationId, testCorrelationId, true);
}
/**
* Test that getting the correlationId when using an underlying received message with
- * a String correlation id representing a JMSMessageID (i.e there is no annotation to
- * indicate it is an application-specific correlation-id) returns the expected value.
+ * a String correlation id representing a JMSMessageID (i.e there is an ID: prefix)
+ * returns the expected value.
*/
@Test
public void testGetCorrelationIdOnReceivedMessageWithStringJMSMessageId() {
- correlationIdOnReceivedMessageTestImpl("myCorrelationIdString", false);
+ String testCorrelationId = "ID:JMSMessageIDasCorrelationIdString";
+ correlationIdOnReceivedMessageTestImpl(testCorrelationId, testCorrelationId, false);
}
/**
@@ -962,7 +954,9 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
*/
@Test
public void testGetCorrelationIdOnReceivedMessageWithUUID() {
- correlationIdOnReceivedMessageTestImpl(UUID.randomUUID(), true);
+ UUID testCorrelationId = UUID.randomUUID();
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + testCorrelationId.toString();
+ correlationIdOnReceivedMessageTestImpl(testCorrelationId, expected, false);
}
/**
@@ -988,7 +982,9 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
*/
@Test
public void testGetCorrelationIdOnReceivedMessageWithUnsignedLong() {
- correlationIdOnReceivedMessageTestImpl(UnsignedLong.valueOf(123456789L), true);
+ UnsignedLong testCorrelationId = UnsignedLong.valueOf(123456789L);
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + testCorrelationId.toString();
+ correlationIdOnReceivedMessageTestImpl(testCorrelationId, expected, false);
}
/**
@@ -1075,43 +1071,31 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
/**
* Test that getting the correlationId when using an underlying received message with a
- * Binary message id returns the expected ByteBuffer value.
+ * Binary message id returns the expected value.
*/
@Test
public void testGetCorrelationIdOnReceivedMessageWithBinary() {
Binary testCorrelationId = createBinaryId();
-
- correlationIdOnReceivedMessageTestImpl(testCorrelationId, true);
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX +
+ AmqpMessageIdHelper.INSTANCE.convertBinaryToHexString(testCorrelationId.getArray());
+ correlationIdOnReceivedMessageTestImpl(testCorrelationId, expected, false);
}
- private void correlationIdOnReceivedMessageTestImpl(final Object testCorrelationId, boolean appSpecificCorrelationId) {
+ private void correlationIdOnReceivedMessageTestImpl(final Object testCorrelationId, final String expected, boolean appSpecificCorrelationId) {
Message message = Proton.message();
Properties props = new Properties();
props.setCorrelationId(testCorrelationId);
message.setProperties(props);
- if(appSpecificCorrelationId)
- {
- //Add the annotation instructing the client the correlation-id is not a JMS MessageID value.
- Map<Symbol, Object> annMap = new HashMap<Symbol, Object>();
- annMap.put(Symbol.valueOf(AmqpMessageSupport.JMS_APP_CORRELATION_ID), true);
- MessageAnnotations messageAnnotations = new MessageAnnotations(annMap);
- message.setMessageAnnotations(messageAnnotations);
- }
-
- AmqpMessageIdHelper helper = AmqpMessageIdHelper.INSTANCE;
- String expected = helper.toBaseMessageIdString(testCorrelationId);
- if(!appSpecificCorrelationId && !helper.hasMessageIdPrefix(expected))
- {
- expected = AmqpMessageIdHelper.JMS_ID_PREFIX + expected;
- }
-
AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);
- assertNotNull("Expected a correlationId on received message", amqpMessageFacade.getCorrelationId());
-
- assertEquals("Incorrect correlationId value received", expected, amqpMessageFacade.getCorrelationId());
+ String result = amqpMessageFacade.getCorrelationId();
+ assertNotNull("Expected a correlationId on received message", result);
+ assertEquals("Incorrect correlationId value received", expected, result);
+ if(!appSpecificCorrelationId) {
+ assertTrue("Should have have 'ID:' prefix", result.startsWith(AmqpMessageIdHelper.JMS_ID_PREFIX));
+ }
}
@Test
@@ -1125,7 +1109,7 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
* Test that setting then getting a String value as the messageId returns the expected value
*/
@Test
- public void testSetGetMessageIdOnNewMessageWithString() {
+ public void testSetGetMessageIdOnNewMessageWithString() throws Exception {
String testMessageId = "ID:myStringMessageId";
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
@@ -1138,18 +1122,17 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
/**
* Test that setting an ID: prefixed JMSMessageId results in the underlying AMQP
- * message holding the value withint the ID: prefix.
+ * message holding the value with the ID: prefix retained.
*/
@Test
- public void testSetMessageIdRemovesIdPrefixFromUnderlyingMessage() {
- String suffix = "myStringMessageIdSuffix";
- String testMessageId = "ID:" + suffix;
+ public void testSetMessageIdRemovesIdPrefixFromUnderlyingMessage() throws Exception {
+ String testMessageId = "ID:myStringMessageId";
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
amqpMessageFacade.setMessageId(testMessageId);
- assertEquals("Expected underlying messageId value not returned", suffix, amqpMessageFacade.getAmqpMessage().getMessageId());
+ assertEquals("underlying messageId value not as expected", testMessageId, amqpMessageFacade.getAmqpMessage().getMessageId());
}
/**
@@ -1157,7 +1140,7 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
* underlying amqp message-id field
*/
@Test
- public void testSetMessageIdNullClearsExistingValue() {
+ public void testSetMessageIdNullClearsExistingValue() throws Exception {
String testMessageId = "ID:myStringMessageId";
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
@@ -1178,7 +1161,20 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
*/
@Test
public void testGetMessageIdOnReceivedMessageWithString() {
- messageIdOnReceivedMessageTestImpl("myMessageIdString");
+ String testMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + "myMessageIdString";
+ messageIdOnReceivedMessageTestImpl(testMessageId, testMessageId);
+ }
+
+ /**
+ * Test that getting the messageId when using an underlying received message with a
+ * String message id without "ID:" prefix returns the expected value.
+ */
+ @Test
+ public void testGetMessageIdOnReceivedMessageWithStringNoIdPrefix() {
+ //Deliberately omit the "ID:", as if it was sent from a non-JMS client
+ Object testMessageId = "myMessageIdString";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + testMessageId;
+ messageIdOnReceivedMessageTestImpl(testMessageId, expected);
}
/**
@@ -1187,7 +1183,9 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
*/
@Test
public void testGetMessageIdOnReceivedMessageWithUUID() {
- messageIdOnReceivedMessageTestImpl(UUID.randomUUID());
+ Object testMessageId = UUID.randomUUID();
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_UUID_PREFIX + testMessageId;
+ messageIdOnReceivedMessageTestImpl(testMessageId, expected);
}
/**
@@ -1196,39 +1194,40 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
*/
@Test
public void testGetMessageIdOnReceivedMessageWithUnsignedLong() {
- messageIdOnReceivedMessageTestImpl(UnsignedLong.valueOf(123456789L));
+ UnsignedLong testMessageId = UnsignedLong.valueOf(123456789L);
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_ULONG_PREFIX + testMessageId;
+ messageIdOnReceivedMessageTestImpl(testMessageId, expected);
}
/**
* Test that getting the messageId when using an underlying received message with a
- * Binary message id returns the expected ByteBuffer value.
+ * Binary message id returns the expected value.
*/
@Test
public void testGetMessageIdOnReceivedMessageWithBinary() {
Binary testMessageId = createBinaryId();
-
- messageIdOnReceivedMessageTestImpl(testMessageId);
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX +
+ AmqpMessageIdHelper.INSTANCE.convertBinaryToHexString(testMessageId.getArray());
+ messageIdOnReceivedMessageTestImpl(testMessageId, expected);
}
- private void messageIdOnReceivedMessageTestImpl(Object testMessageId) {
- Object underlyingIdObject = testMessageId;
- if (!(testMessageId == null || testMessageId instanceof Binary || testMessageId instanceof UnsignedLong || testMessageId instanceof String || testMessageId instanceof UUID)) {
+ private void messageIdOnReceivedMessageTestImpl(Object underlyingMessageId, String expected) {
+ if (!(underlyingMessageId == null || underlyingMessageId instanceof Binary
+ || underlyingMessageId instanceof UnsignedLong || underlyingMessageId instanceof String || underlyingMessageId instanceof UUID)) {
throw new IllegalArgumentException("invalid id type");
}
Message message = Proton.message();
Properties props = new Properties();
- props.setMessageId(underlyingIdObject);
+ props.setMessageId(underlyingMessageId);
message.setProperties(props);
AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);
assertNotNull("Expected a messageId on received message", amqpMessageFacade.getMessageId());
- String expectedString = appendIdAndTypePrefix(testMessageId);
-
- assertEquals("Incorrect messageId value received", expectedString, amqpMessageFacade.getMessageId());
+ assertEquals("Incorrect messageId value received", expected, amqpMessageFacade.getMessageId());
}
private String appendIdAndTypePrefix(Object testMessageId) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[3/3] qpid-jms git commit: QPIDJMS-189: some test cleanup
Posted by ro...@apache.org.
QPIDJMS-189: some test cleanup
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/443a54d6
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/443a54d6
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/443a54d6
Branch: refs/heads/master
Commit: 443a54d6c9fa919253316f01bbeed83bb27e7aef
Parents: 7b34f4f
Author: Robert Gemmell <ro...@apache.org>
Authored: Thu Sep 1 15:57:01 2016 +0100
Committer: Robert Gemmell <ro...@apache.org>
Committed: Thu Sep 1 15:57:01 2016 +0100
----------------------------------------------------------------------
.../amqp/message/AmqpJmsMessageFacadeTest.java | 33 +++++---------------
.../amqp/message/AmqpMessageIdHelperTest.java | 12 +++----
2 files changed, 14 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/443a54d6/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
index e7956e8..8bbbb4b 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/message/AmqpJmsMessageFacadeTest.java
@@ -939,7 +939,7 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
@Test
public void testSetGetCorrelationIdOnNewMessageWithUUID() throws Exception {
UUID testCorrelationId = UUID.randomUUID();
- String converted = appendIdAndTypePrefix(testCorrelationId);
+ String converted = "ID:AMQP_UUID:" + testCorrelationId;
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
amqpMessageFacade.setCorrelationId(converted);
@@ -967,7 +967,7 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
@Test
public void testSetGetCorrelationIdOnNewMessageWithUnsignedLong() throws Exception {
Object testCorrelationId = UnsignedLong.valueOf(123456789L);
- String converted = appendIdAndTypePrefix(testCorrelationId);
+ String converted = "ID:AMQP_ULONG:" + testCorrelationId;
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
amqpMessageFacade.setCorrelationId(converted);
@@ -995,7 +995,11 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
@Test
public void testSetGetCorrelationIdOnNewMessageWithBinary() throws Exception {
Binary testCorrelationId = createBinaryId();
- String converted = appendIdAndTypePrefix(testCorrelationId);
+ ByteBuffer buf = testCorrelationId.asByteBuffer();
+ byte[] bytes = new byte[buf.remaining()];
+ buf.get(bytes);
+
+ String converted = "ID:AMQP_BINARY:" + new AmqpMessageIdHelper().convertBinaryToHexString(bytes);
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
amqpMessageFacade.setCorrelationId(converted);
@@ -1125,7 +1129,7 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
* message holding the value with the ID: prefix retained.
*/
@Test
- public void testSetMessageIdRemovesIdPrefixFromUnderlyingMessage() throws Exception {
+ public void testSetMessageIdRetainsIdPrefixInUnderlyingMessage() throws Exception {
String testMessageId = "ID:myStringMessageId";
AmqpJmsMessageFacade amqpMessageFacade = createNewMessageFacade();
@@ -1230,27 +1234,6 @@ public class AmqpJmsMessageFacadeTest extends AmqpJmsMessageTypesTestCase {
assertEquals("Incorrect messageId value received", expected, amqpMessageFacade.getMessageId());
}
- private String appendIdAndTypePrefix(Object testMessageId) {
- if (testMessageId instanceof Binary) {
- ByteBuffer buf = ((Binary) testMessageId).asByteBuffer();
-
- byte[] bytes = new byte[buf.remaining()];
- buf.get(bytes);
-
- return "ID:AMQP_BINARY:" + new AmqpMessageIdHelper().convertBinaryToHexString(bytes);
- } else if (testMessageId instanceof UnsignedLong) {
- return ("ID:AMQP_ULONG:" + testMessageId);
- } else if (testMessageId instanceof UUID) {
- return ("ID:AMQP_UUID:" + testMessageId);
- } else if (testMessageId instanceof String) {
- return "ID:" + testMessageId;
- } else if (testMessageId == null) {
- return null;
- }
-
- throw new IllegalArgumentException();
- }
-
private Binary createBinaryId() {
byte length = 10;
byte[] idBytes = new byte[length];
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/443a54d6/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 c786ba3..ac246e3 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
@@ -310,10 +310,10 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
*/
@Test
public void testToMessageIdStringWithStringBeginningWithIdAndEncodingPrefixForNoIDPrefix() {
- String unescapedBinaryPrefixMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + "id-content";
- String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedBinaryPrefixMessageId;
+ String unescapedNoPrefixPrefixedMessageId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + "id-content";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedNoPrefixPrefixedMessageId;
- doToMessageIdTestImpl(unescapedBinaryPrefixMessageId, expected);
+ doToMessageIdTestImpl(unescapedNoPrefixPrefixedMessageId, expected);
}
/**
@@ -527,10 +527,10 @@ public class AmqpMessageIdHelperTest extends QpidJmsTestCase {
*/
@Test
public void testToCorrelationIdStringWithStringBeginningWithIdAndEncodingPrefixForNoIDPrefix() {
- String unescapedBinaryPrefixCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + "id-content";
- String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedBinaryPrefixCorrelationId;
+ String unescapedNoPrefixCorrelationId = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX + "id-content";
+ String expected = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_STRING_PREFIX + unescapedNoPrefixCorrelationId;
- doToCorrelationIDTestImpl(unescapedBinaryPrefixCorrelationId, expected);
+ doToCorrelationIDTestImpl(unescapedNoPrefixCorrelationId, expected);
}
private void doToIdObjectTestImpl(String idString, Object expected) throws IdConversionException {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org