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 7c62bb5  PROTON-2393 Add an additional test for codec coverage of type 
decoding
7c62bb5 is described below

commit 7c62bb591c4288a0f50c02822aa904eba47edbd8
Author: Timothy Bish <[email protected]>
AuthorDate: Thu Sep 16 18:20:06 2021 -0400

    PROTON-2393 Add an additional test for codec coverage of type decoding
---
 .../protonj2/test/driver/codec/DataImplTest.java   | 45 ++++++++++++++++++++++
 .../LegacyCodecOpenFramesTestDataGenerator.java    | 21 ++++++++++
 2 files changed, 66 insertions(+)

diff --git 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/codec/DataImplTest.java
 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/codec/DataImplTest.java
index ca04788..637897a 100644
--- 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/codec/DataImplTest.java
+++ 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/codec/DataImplTest.java
@@ -16,15 +16,19 @@
  */
 package org.apache.qpid.protonj2.test.driver.codec;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.qpid.protonj2.test.driver.codec.messaging.Source;
 import org.apache.qpid.protonj2.test.driver.codec.messaging.Target;
 import org.apache.qpid.protonj2.test.driver.codec.primitives.DescribedType;
+import org.apache.qpid.protonj2.test.driver.codec.primitives.Symbol;
 import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedInteger;
 import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedShort;
 import org.apache.qpid.protonj2.test.driver.codec.transport.Attach;
@@ -184,6 +188,47 @@ public class DataImplTest {
         assertEquals(performative.getName(), "test");
     }
 
+    @Test
+    public void testDecodeOfComplexOpenEncoding() throws IOException {
+        // Frame data for: Open
+        //   Open{ containerId='container', hostname='localhost', 
maxFrameSize=16384, channelMax=65535,
+        //         idleTimeOut=36000, outgoingLocales=null, 
incomingLocales=null, offeredCapabilities=[SOMETHING],
+        //         desiredCapabilities=[ANONYMOUS-RELAY, DELAYED-DELIVERY], 
properties={queue-prefix=queue://}}
+        final byte[] completeOpen = new byte[] {0, 83, 16, -64, 116, 10, -95, 
9, 99, 111, 110, 116, 97, 105, 110,
+                                                101, 114, -95, 9, 108, 111, 
99, 97, 108, 104, 111, 115, 116, 112,
+                                                0, 0, 64, 0, 96, -1, -1, 112, 
0, 0, -116, -96, 64, 64, -32, 12, 1,
+                                                -93, 9, 83, 79, 77, 69, 84, 
72, 73, 78, 71, -32, 35, 2, -93, 15,
+                                                65, 78, 79, 78, 89, 77, 79, 
85, 83, 45, 82, 69, 76, 65, 89, 16, 68,
+                                                69, 76, 65, 89, 69, 68, 45, 
68, 69, 76, 73, 86, 69, 82, 89, -63, 25,
+                                                2, -95, 12, 113, 117, 101, 
117, 101, 45, 112, 114, 101, 102, 105,
+                                                120, -95, 8, 113, 117, 101, 
117, 101, 58, 47, 47};
+
+        ByteBuf encoded = Unpooled.wrappedBuffer(completeOpen);
+
+        DescribedType decoded = decodeProtonPerformative(encoded);
+        assertNotNull(decoded);
+        assertTrue(decoded instanceof Open);
+
+        Open performative = (Open) decoded;
+
+        assertEquals("container", performative.getContainerId());
+        assertEquals("localhost", performative.getHostname());
+        assertEquals(UnsignedInteger.valueOf(16384), 
performative.getMaxFrameSize());
+        assertEquals(UnsignedInteger.valueOf(36000), 
performative.getIdleTimeOut());
+        assertEquals(UnsignedShort.valueOf(65535), 
performative.getChannelMax());
+
+        Symbol[] offered = performative.getOfferedCapabilities();
+        Symbol[] desired = performative.getDesiredCapabilities();
+
+        assertArrayEquals(new Symbol[] { Symbol.valueOf("SOMETHING") }, 
offered);
+        assertArrayEquals(new Symbol[] { Symbol.valueOf("ANONYMOUS-RELAY"), 
Symbol.valueOf("DELAYED-DELIVERY") }, desired);
+
+        Map<String, Object> expected = new HashMap<String, Object>();
+        expected.put("queue-prefix", "queue://");
+
+        assertEquals(expected, performative.getProperties());
+    }
+
     private DescribedType decodeProtonPerformative(ByteBuf buffer) throws 
IOException {
         DescribedType performative = null;
 
diff --git 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/legacy/LegacyCodecOpenFramesTestDataGenerator.java
 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/legacy/LegacyCodecOpenFramesTestDataGenerator.java
index d3ec7a8..8d75789 100644
--- 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/legacy/LegacyCodecOpenFramesTestDataGenerator.java
+++ 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/legacy/LegacyCodecOpenFramesTestDataGenerator.java
@@ -16,6 +16,10 @@
  */
 package org.apache.qpid.protonj2.test.driver.legacy;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.proton.amqp.Symbol;
 import org.apache.qpid.proton.amqp.UnsignedInteger;
 import org.apache.qpid.proton.amqp.transport.Open;
 
@@ -40,5 +44,22 @@ public class LegacyCodecOpenFramesTestDataGenerator {
         basicOpen.setIdleTimeOut(UnsignedInteger.valueOf(30000));
         String basicOpenString = 
LegacyFrameDataGenerator.generateUnitTestVariable("basicOpen", basicOpen);
         System.out.println(basicOpenString);
+
+        // 2: Complete Open - No capabilities or locals set
+        Open complete = new Open();
+        complete.setContainerId("container");
+        complete.setHostname("localhost");
+        complete.setMaxFrameSize(UnsignedInteger.valueOf(16384));
+        complete.setIdleTimeOut(UnsignedInteger.valueOf(36000));
+        complete.setDesiredCapabilities(Symbol.valueOf("ANONYMOUS-RELAY"), 
Symbol.valueOf("DELAYED-DELIVERY"));
+        complete.setOfferedCapabilities(Symbol.valueOf("SOMETHING"));
+
+        Map<String, Object> properties = new HashMap<>();
+        properties.put("queue-prefix", "queue://");
+
+        complete.setProperties(properties);
+
+        String completeOpenString = 
LegacyFrameDataGenerator.generateUnitTestVariable("completeOpen", complete);
+        System.out.println(completeOpenString);
     }
 }

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

Reply via email to