This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new c0cd511  PROTON-2504 Fix Proton Properties type validation for 
correlation ID
c0cd511 is described below

commit c0cd5112c09ed2a2e64dba1f049748a7e7cb5056
Author: Timothy Bish <[email protected]>
AuthorDate: Wed Mar 9 15:44:57 2022 -0500

    PROTON-2504 Fix Proton Properties type validation for correlation ID
---
 .../qpid/protonj2/client/impl/StreamReceiverTest.java   |  5 +++--
 .../qpid/protonj2/types/messaging/Properties.java       |  2 +-
 .../protonj2/types/messaging/PropertiesTypeTest.java    | 17 +++++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git 
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
 
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
index 8070784..5fa3a71 100644
--- 
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
+++ 
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamReceiverTest.java
@@ -68,6 +68,7 @@ import org.apache.qpid.protonj2.codec.EncodingCodes;
 import org.apache.qpid.protonj2.test.driver.ProtonTestServer;
 import org.apache.qpid.protonj2.test.driver.codec.messaging.Accepted;
 import 
org.apache.qpid.protonj2.test.driver.codec.messaging.DeliveryAnnotations;
+import org.apache.qpid.protonj2.types.Binary;
 import org.apache.qpid.protonj2.types.Symbol;
 import org.apache.qpid.protonj2.types.UnsignedInteger;
 import org.apache.qpid.protonj2.types.messaging.AmqpSequence;
@@ -3091,7 +3092,7 @@ class StreamReceiverTest extends ImperativeClientTestCase 
{
         properties.setAbsoluteExpiryTime(Integer.MAX_VALUE);
         properties.setContentEncoding("utf8");
         properties.setContentType("text/plain");
-        properties.setCorrelationId(new byte[] { 1, 2, 3 });
+        properties.setCorrelationId(new Binary(new byte[] { 1, 2, 3 }));
         properties.setCreationTime(Short.MAX_VALUE);
         properties.setGroupId("Group");
         properties.setGroupSequence(UnsignedInteger.MAX_VALUE.longValue());
@@ -3148,7 +3149,7 @@ class StreamReceiverTest extends ImperativeClientTestCase 
{
             assertEquals(Integer.MAX_VALUE, message.absoluteExpiryTime());
             assertEquals("utf8", message.contentEncoding());
             assertEquals("text/plain", message.contentType());
-            assertArrayEquals(new byte[] { 1, 2, 3 }, (byte[]) 
message.correlationId());
+            assertEquals(new Binary(new byte[] { 1, 2, 3 }), 
message.correlationId());
             assertEquals("utf8", message.contentEncoding());
             assertEquals("utf8", message.contentEncoding());
             assertEquals("utf8", message.contentEncoding());
diff --git 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Properties.java
 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Properties.java
index 3e92743..02b8739 100644
--- 
a/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Properties.java
+++ 
b/protonj2/src/main/java/org/apache/qpid/protonj2/types/messaging/Properties.java
@@ -259,7 +259,7 @@ public final class Properties implements 
Section<Properties> {
     }
 
     public Properties setCorrelationId(Object correlationId) {
-        validateIsMessageIdType(messageId);
+        validateIsMessageIdType(correlationId);
 
         if (correlationId == null) {
             modified &= ~CORRELATION_ID;
diff --git 
a/protonj2/src/test/java/org/apache/qpid/protonj2/types/messaging/PropertiesTypeTest.java
 
b/protonj2/src/test/java/org/apache/qpid/protonj2/types/messaging/PropertiesTypeTest.java
index b5f0a26..6dad19e 100644
--- 
a/protonj2/src/test/java/org/apache/qpid/protonj2/types/messaging/PropertiesTypeTest.java
+++ 
b/protonj2/src/test/java/org/apache/qpid/protonj2/types/messaging/PropertiesTypeTest.java
@@ -342,9 +342,26 @@ public class PropertiesTypeTest {
         assertTrue(properties.hasCorrelationId());
         assertNotNull(properties.getCorrelationId());
 
+        properties.setCorrelationId(UUID.randomUUID());
+        assertTrue(properties.hasCorrelationId());
+        assertNotNull(properties.getCorrelationId());
+
+        properties.setCorrelationId(new Binary(new byte[] { 1 }));
+        assertTrue(properties.hasCorrelationId());
+        assertNotNull(properties.getCorrelationId());
+
+        properties.setCorrelationId(UnsignedLong.ZERO);
+        assertTrue(properties.hasCorrelationId());
+        assertNotNull(properties.getCorrelationId());
+
         properties.setCorrelationId(null);
         assertFalse(properties.hasCorrelationId());
         assertNull(properties.getCorrelationId());
+
+        try {
+            properties.setCorrelationId(new HashMap<String, String>());
+            fail("Not a valid CorrelationId type.");
+        } catch (IllegalArgumentException iae) {}
     }
 
     @Test

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

Reply via email to