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

commit fc3713ee6bb35ea32daf920bff180f9f25520272
Author: Timothy Bish <tabish...@gmail.com>
AuthorDate: Fri May 28 10:30:22 2021 -0400

    PROTON-2392 Fix issue with Declare expectation and message format
    
    Fix an issue with the matcher that was created for the expectDeclare
    scripted element which wasn't correclty handling null or zero cases.
    Also improves the API a bit when scripting expectations for delcare and
    discharge.
---
 .../qpid/protonj2/test/driver/ScriptWriter.java    |   9 +-
 .../test/driver/actions/TransferInjectAction.java  |  10 ++
 .../driver/expectations/DeclareExpectation.java    | 172 +++++++++++++++++++++
 .../driver/expectations/DischargeExpectation.java  | 172 +++++++++++++++++++++
 .../test/driver/TransactionHandlingTest.java       |  16 +-
 5 files changed, 371 insertions(+), 8 deletions(-)

diff --git 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java
 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java
index 15e2ab5..951e8b5 100644
--- 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java
+++ 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ScriptWriter.java
@@ -16,11 +16,8 @@
  */
 package org.apache.qpid.protonj2.test.driver;
 
-import static org.hamcrest.CoreMatchers.anyOf;
-import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.isA;
 import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.nio.charset.StandardCharsets;
@@ -51,6 +48,7 @@ import 
org.apache.qpid.protonj2.test.driver.actions.TransferInjectAction;
 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.UnsignedInteger;
 import org.apache.qpid.protonj2.test.driver.codec.security.SaslCode;
 import org.apache.qpid.protonj2.test.driver.codec.transactions.Coordinator;
 import org.apache.qpid.protonj2.test.driver.codec.transport.AMQPHeader;
@@ -73,6 +71,7 @@ import 
org.apache.qpid.protonj2.test.driver.expectations.SaslMechanismsExpectati
 import 
org.apache.qpid.protonj2.test.driver.expectations.SaslOutcomeExpectation;
 import 
org.apache.qpid.protonj2.test.driver.expectations.SaslResponseExpectation;
 import org.apache.qpid.protonj2.test.driver.expectations.TransferExpectation;
+import org.hamcrest.Matchers;
 
 /**
  * Class used to create test scripts using the {@link AMQPTestDriver}
@@ -174,7 +173,7 @@ public abstract class ScriptWriter {
         expecting.withHandle(notNullValue());
         expecting.withDeliveryId(notNullValue());
         expecting.withDeliveryTag(notNullValue());
-        expecting.withMessageFormat(anyOf(nullValue(), equalTo(0)));
+        expecting.withMessageFormat(Matchers.oneOf(null, 0, 
UnsignedInteger.ZERO));
 
         getDriver().addScriptedElement(expecting);
         return expecting;
@@ -186,7 +185,7 @@ public abstract class ScriptWriter {
         expecting.withHandle(notNullValue());
         expecting.withDeliveryId(notNullValue());
         expecting.withDeliveryTag(notNullValue());
-        expecting.withMessageFormat(anyOf(nullValue(), equalTo(0)));
+        expecting.withMessageFormat(Matchers.oneOf(null, 0, 
UnsignedInteger.ZERO));
 
         getDriver().addScriptedElement(expecting);
         return expecting;
diff --git 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java
 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java
index 82a44a3..4024d81 100644
--- 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java
+++ 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/actions/TransferInjectAction.java
@@ -137,11 +137,21 @@ public class TransferInjectAction extends 
AbstractPerformativeInjectAction<Trans
         return this;
     }
 
+    public TransferInjectAction withMessageFormat(int messageFormat) {
+        transfer.setMessageFormat(UnsignedInteger.valueOf(messageFormat));
+        return this;
+    }
+
     public TransferInjectAction withMessageFormat(long messageFormat) {
         transfer.setMessageFormat(UnsignedInteger.valueOf(messageFormat));
         return this;
     }
 
+    public TransferInjectAction withMessageFormat(UnsignedInteger 
messageFormat) {
+        transfer.setMessageFormat(messageFormat);
+        return this;
+    }
+
     public TransferInjectAction withSettled(Boolean settled) {
         transfer.setSettled(settled);
         return this;
diff --git 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DeclareExpectation.java
 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DeclareExpectation.java
index 88708b3..0c6b86d 100644
--- 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DeclareExpectation.java
+++ 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DeclareExpectation.java
@@ -16,14 +16,21 @@
  */
 package org.apache.qpid.protonj2.test.driver.expectations;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+
 import java.util.Random;
 
 import org.apache.qpid.protonj2.test.driver.AMQPTestDriver;
 import org.apache.qpid.protonj2.test.driver.actions.DispositionInjectAction;
 import org.apache.qpid.protonj2.test.driver.codec.primitives.Binary;
+import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedInteger;
 import org.apache.qpid.protonj2.test.driver.codec.transactions.Declare;
 import org.apache.qpid.protonj2.test.driver.codec.transactions.Declared;
+import org.apache.qpid.protonj2.test.driver.codec.transport.DeliveryState;
+import org.apache.qpid.protonj2.test.driver.codec.transport.ReceiverSettleMode;
 import 
org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher;
+import org.hamcrest.Matcher;
 
 /**
  * Expectation used to script incoming transaction declarations.
@@ -110,4 +117,169 @@ public class DeclareExpectation extends 
TransferExpectation {
         withPayload(new EncodedAmqpValueMatcher(null));
         return this;
     }
+
+    //----- Type specific with methods that perform simple equals checks
+
+    @Override
+    public DeclareExpectation withHandle(int handle) {
+        return withHandle(equalTo(UnsignedInteger.valueOf(handle)));
+    }
+
+    @Override
+    public DeclareExpectation withHandle(long handle) {
+        return withHandle(equalTo(UnsignedInteger.valueOf(handle)));
+    }
+
+    @Override
+    public DeclareExpectation withHandle(UnsignedInteger handle) {
+        return withHandle(equalTo(handle));
+    }
+
+    @Override
+    public DeclareExpectation withDeliveryId(int deliveryId) {
+        return withDeliveryId(equalTo(UnsignedInteger.valueOf(deliveryId)));
+    }
+
+    @Override
+    public DeclareExpectation withDeliveryId(long deliveryId) {
+        return withDeliveryId(equalTo(UnsignedInteger.valueOf(deliveryId)));
+    }
+
+    @Override
+    public DeclareExpectation withDeliveryId(UnsignedInteger deliveryId) {
+        return withDeliveryId(equalTo(deliveryId));
+    }
+
+    @Override
+    public DeclareExpectation withDeliveryTag(byte[] tag) {
+        return withDeliveryTag(new Binary(tag));
+    }
+
+    @Override
+    public DeclareExpectation withDeliveryTag(Binary deliveryTag) {
+        return withDeliveryTag(equalTo(deliveryTag));
+    }
+
+    @Override
+    public DeclareExpectation withMessageFormat(int messageFormat) {
+        return 
withMessageFormat(equalTo(UnsignedInteger.valueOf(messageFormat)));
+    }
+
+    @Override
+    public DeclareExpectation withMessageFormat(long messageFormat) {
+        return 
withMessageFormat(equalTo(UnsignedInteger.valueOf(messageFormat)));
+    }
+
+    @Override
+    public DeclareExpectation withMessageFormat(UnsignedInteger messageFormat) 
{
+        return withMessageFormat(equalTo(messageFormat));
+    }
+
+    @Override
+    public DeclareExpectation withSettled(boolean settled) {
+        return withSettled(equalTo(settled));
+    }
+
+    @Override
+    public DeclareExpectation withMore(boolean more) {
+        return withMore(equalTo(more));
+    }
+
+    @Override
+    public DeclareExpectation withRcvSettleMode(ReceiverSettleMode 
rcvSettleMode) {
+        return withRcvSettleMode(equalTo(rcvSettleMode.getValue()));
+    }
+
+    @Override
+    public DeclareExpectation withState(DeliveryState state) {
+        return withState(equalTo(state));
+    }
+
+    @Override
+    public DeclareExpectation withNullState() {
+        return withState(nullValue());
+    }
+
+    @Override
+    public DeclareExpectation withResume(boolean resume) {
+        return withResume(equalTo(resume));
+    }
+
+    @Override
+    public DeclareExpectation withAborted(boolean aborted) {
+        return withAborted(equalTo(aborted));
+    }
+
+    @Override
+    public DeclareExpectation withBatchable(boolean batchable) {
+        return withBatchable(equalTo(batchable));
+    }
+
+    //----- Matcher based with methods for more complex validation
+
+    @Override
+    public DeclareExpectation withHandle(Matcher<?> m) {
+        super.withHandle(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withDeliveryId(Matcher<?> m) {
+        super.withDeliveryId(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withDeliveryTag(Matcher<?> m) {
+        super.withDeliveryTag(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withMessageFormat(Matcher<?> m) {
+        super.withMessageFormat(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withSettled(Matcher<?> m) {
+        super.withSettled(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withMore(Matcher<?> m) {
+        super.withMore(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withRcvSettleMode(Matcher<?> m) {
+        super.withRcvSettleMode(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withState(Matcher<?> m) {
+        super.withState(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withResume(Matcher<?> m) {
+        super.withResume(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withAborted(Matcher<?> m) {
+        super.withAborted(m);
+        return this;
+    }
+
+    @Override
+    public DeclareExpectation withBatchable(Matcher<?> m) {
+        super.withBatchable(m);
+        return this;
+    }
 }
diff --git 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DischargeExpectation.java
 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DischargeExpectation.java
index cf6e431..f3956dd 100644
--- 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DischargeExpectation.java
+++ 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DischargeExpectation.java
@@ -16,11 +16,18 @@
  */
 package org.apache.qpid.protonj2.test.driver.expectations;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+
 import org.apache.qpid.protonj2.test.driver.AMQPTestDriver;
 import org.apache.qpid.protonj2.test.driver.codec.primitives.Binary;
+import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedInteger;
 import org.apache.qpid.protonj2.test.driver.codec.transactions.Discharge;
+import org.apache.qpid.protonj2.test.driver.codec.transport.DeliveryState;
+import org.apache.qpid.protonj2.test.driver.codec.transport.ReceiverSettleMode;
 import 
org.apache.qpid.protonj2.test.driver.matchers.transactions.DischargeMatcher;
 import 
org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher;
+import org.hamcrest.Matcher;
 
 /**
  * Expectation used to script incoming transaction declarations.
@@ -66,4 +73,169 @@ public class DischargeExpectation extends 
TransferExpectation {
         withPayload(new EncodedAmqpValueMatcher(null));
         return this;
     }
+
+    //----- Type specific with methods that perform simple equals checks
+
+    @Override
+    public DischargeExpectation withHandle(int handle) {
+        return withHandle(equalTo(UnsignedInteger.valueOf(handle)));
+    }
+
+    @Override
+    public DischargeExpectation withHandle(long handle) {
+        return withHandle(equalTo(UnsignedInteger.valueOf(handle)));
+    }
+
+    @Override
+    public DischargeExpectation withHandle(UnsignedInteger handle) {
+        return withHandle(equalTo(handle));
+    }
+
+    @Override
+    public DischargeExpectation withDeliveryId(int deliveryId) {
+        return withDeliveryId(equalTo(UnsignedInteger.valueOf(deliveryId)));
+    }
+
+    @Override
+    public DischargeExpectation withDeliveryId(long deliveryId) {
+        return withDeliveryId(equalTo(UnsignedInteger.valueOf(deliveryId)));
+    }
+
+    @Override
+    public DischargeExpectation withDeliveryId(UnsignedInteger deliveryId) {
+        return withDeliveryId(equalTo(deliveryId));
+    }
+
+    @Override
+    public DischargeExpectation withDeliveryTag(byte[] tag) {
+        return withDeliveryTag(new Binary(tag));
+    }
+
+    @Override
+    public DischargeExpectation withDeliveryTag(Binary deliveryTag) {
+        return withDeliveryTag(equalTo(deliveryTag));
+    }
+
+    @Override
+    public DischargeExpectation withMessageFormat(int messageFormat) {
+        return 
withMessageFormat(equalTo(UnsignedInteger.valueOf(messageFormat)));
+    }
+
+    @Override
+    public DischargeExpectation withMessageFormat(long messageFormat) {
+        return 
withMessageFormat(equalTo(UnsignedInteger.valueOf(messageFormat)));
+    }
+
+    @Override
+    public DischargeExpectation withMessageFormat(UnsignedInteger 
messageFormat) {
+        return withMessageFormat(equalTo(messageFormat));
+    }
+
+    @Override
+    public DischargeExpectation withSettled(boolean settled) {
+        return withSettled(equalTo(settled));
+    }
+
+    @Override
+    public DischargeExpectation withMore(boolean more) {
+        return withMore(equalTo(more));
+    }
+
+    @Override
+    public DischargeExpectation withRcvSettleMode(ReceiverSettleMode 
rcvSettleMode) {
+        return withRcvSettleMode(equalTo(rcvSettleMode.getValue()));
+    }
+
+    @Override
+    public DischargeExpectation withState(DeliveryState state) {
+        return withState(equalTo(state));
+    }
+
+    @Override
+    public DischargeExpectation withNullState() {
+        return withState(nullValue());
+    }
+
+    @Override
+    public DischargeExpectation withResume(boolean resume) {
+        return withResume(equalTo(resume));
+    }
+
+    @Override
+    public DischargeExpectation withAborted(boolean aborted) {
+        return withAborted(equalTo(aborted));
+    }
+
+    @Override
+    public DischargeExpectation withBatchable(boolean batchable) {
+        return withBatchable(equalTo(batchable));
+    }
+
+    //----- Matcher based with methods for more complex validation
+
+    @Override
+    public DischargeExpectation withHandle(Matcher<?> m) {
+        super.withHandle(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withDeliveryId(Matcher<?> m) {
+        super.withDeliveryId(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withDeliveryTag(Matcher<?> m) {
+        super.withDeliveryTag(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withMessageFormat(Matcher<?> m) {
+        super.withMessageFormat(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withSettled(Matcher<?> m) {
+        super.withSettled(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withMore(Matcher<?> m) {
+        super.withMore(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withRcvSettleMode(Matcher<?> m) {
+        super.withRcvSettleMode(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withState(Matcher<?> m) {
+        super.withState(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withResume(Matcher<?> m) {
+        super.withResume(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withAborted(Matcher<?> m) {
+        super.withAborted(m);
+        return this;
+    }
+
+    @Override
+    public DischargeExpectation withBatchable(Matcher<?> m) {
+        super.withBatchable(m);
+        return this;
+    }
 }
diff --git 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/TransactionHandlingTest.java
 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/TransactionHandlingTest.java
index 3690890..0a40d60 100644
--- 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/TransactionHandlingTest.java
+++ 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/TransactionHandlingTest.java
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.notNullValue;
 import java.net.URI;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedInteger;
 import org.apache.qpid.protonj2.test.driver.codec.transport.AMQPHeader;
 import org.apache.qpid.protonj2.test.driver.utils.TestPeerTestsBase;
 import org.junit.jupiter.api.Test;
@@ -164,7 +165,16 @@ class TransactionHandlingTest extends TestPeerTestsBase {
     }
 
     @Test
-    public void testTxnDeclarationAndDischarge() throws Exception {
+    public void testTxnDeclarationAndDischargeNullMessageFormat() throws 
Exception {
+        doTestTxnDeclarationAndDischarge(null);
+    }
+
+    @Test
+    public void testTxnDeclarationAndDischargeZeroMessageFormat() throws 
Exception {
+        doTestTxnDeclarationAndDischarge(UnsignedInteger.ZERO);
+    }
+
+    private void doTestTxnDeclarationAndDischarge(UnsignedInteger 
messageFormat) throws Exception {
         try (ProtonTestServer peer = new ProtonTestServer();
              ProtonTestClient client = new ProtonTestClient()) {
 
@@ -173,7 +183,7 @@ class TransactionHandlingTest extends TestPeerTestsBase {
             peer.expectBegin().respond();
             peer.expectCoordinatorAttach().ofSender().respond();
             peer.remoteFlow().withLinkCredit(2).queue();
-            peer.expectDeclare().declared(new byte[] { 0, 1, 2, 3 });
+            peer.expectDeclare().withMessageFormat(messageFormat).declared(new 
byte[] { 0, 1, 2, 3 });
             peer.expectDischarge().accept();
             peer.expectDetach().respond();
             peer.expectEnd().respond();
@@ -198,7 +208,7 @@ class TransactionHandlingTest extends TestPeerTestsBase {
             client.expectFlow().withLinkCredit(2);
             client.waitForScriptToComplete(5, TimeUnit.SECONDS);
             client.expectDisposition().withState().declared(new byte[] {0, 1, 
2, 3});
-            client.remoteDeclare().withDeliveryTag(new byte[] 
{0}).withDeliveryId(0).now();
+            
client.remoteDeclare().withMessageFormat(messageFormat).withDeliveryTag(new 
byte[] {0}).withDeliveryId(0).now();
 
             client.waitForScriptToComplete(5, TimeUnit.SECONDS);
             client.expectDisposition().withState().accepted();

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

Reply via email to