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 bd261dd8 PROTON-2750 Provide more flexible matching API for error 
conditions
bd261dd8 is described below

commit bd261dd8a69b7a89d012513c309c2c17b049bd8b
Author: Timothy Bish <tabish...@gmail.com>
AuthorDate: Mon Jul 10 17:01:50 2023 -0400

    PROTON-2750 Provide more flexible matching API for error conditions
    
    Allows for simpler tests of conditions from Close, Detach and End frames
---
 .../test/driver/expectations/CloseExpectation.java | 13 +++++++++
 .../driver/expectations/DetachExpectation.java     | 13 +++++++++
 .../test/driver/expectations/EndExpectation.java   | 13 +++++++++
 .../protonj2/test/driver/SenderHandlingTest.java   | 31 ++++++++++++++++++++++
 4 files changed, 70 insertions(+)

diff --git 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/CloseExpectation.java
 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/CloseExpectation.java
index 1d53cd78..bbb4c925 100644
--- 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/CloseExpectation.java
+++ 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/CloseExpectation.java
@@ -32,6 +32,7 @@ import 
org.apache.qpid.protonj2.test.driver.codec.transport.Close;
 import org.apache.qpid.protonj2.test.driver.codec.transport.ErrorCondition;
 import org.apache.qpid.protonj2.test.driver.codec.util.TypeMapper;
 import org.apache.qpid.protonj2.test.driver.matchers.transport.CloseMatcher;
+import 
org.apache.qpid.protonj2.test.driver.matchers.transport.ErrorConditionMatcher;
 import org.hamcrest.Matcher;
 
 /**
@@ -104,6 +105,18 @@ public class CloseExpectation extends 
AbstractExpectation<Close> {
         return withError(equalTo(new ErrorCondition(condition, description, 
info)));
     }
 
+    public CloseExpectation withError(String condition) {
+        return withError(new ErrorConditionMatcher().withCondition(condition));
+    }
+
+    public CloseExpectation withError(String condition, Matcher<?> 
descriptionMatcher) {
+        return withError(new 
ErrorConditionMatcher().withCondition(condition).withDescription(descriptionMatcher));
+    }
+
+    public CloseExpectation withError(String condition, Matcher<?> 
descriptionMatcher, Matcher<?> infoMapMatcher) {
+        return withError(new 
ErrorConditionMatcher().withCondition(condition).withDescription(descriptionMatcher).withInfo(infoMapMatcher));
+    }
+
     //----- Matcher based with methods for more complex validation
 
     public CloseExpectation withError(Matcher<?> m) {
diff --git 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DetachExpectation.java
 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DetachExpectation.java
index 7f6bbd89..8a127e0b 100644
--- 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DetachExpectation.java
+++ 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/DetachExpectation.java
@@ -37,6 +37,7 @@ import 
org.apache.qpid.protonj2.test.driver.codec.transport.Detach;
 import org.apache.qpid.protonj2.test.driver.codec.transport.ErrorCondition;
 import org.apache.qpid.protonj2.test.driver.codec.util.TypeMapper;
 import org.apache.qpid.protonj2.test.driver.matchers.transport.DetachMatcher;
+import 
org.apache.qpid.protonj2.test.driver.matchers.transport.ErrorConditionMatcher;
 import org.hamcrest.Matcher;
 
 /**
@@ -155,6 +156,18 @@ public class DetachExpectation extends 
AbstractExpectation<Detach> {
         return withError(equalTo(new ErrorCondition(condition, description, 
info)));
     }
 
+    public DetachExpectation withError(String condition) {
+        return withError(new ErrorConditionMatcher().withCondition(condition));
+    }
+
+    public DetachExpectation withError(String condition, Matcher<?> 
descriptionMatcher) {
+        return withError(new 
ErrorConditionMatcher().withCondition(condition).withDescription(descriptionMatcher));
+    }
+
+    public DetachExpectation withError(String condition, Matcher<?> 
descriptionMatcher, Matcher<?> infoMapMatcher) {
+        return withError(new 
ErrorConditionMatcher().withCondition(condition).withDescription(descriptionMatcher).withInfo(infoMapMatcher));
+    }
+
     //----- Matcher based with methods for more complex validation
 
     public DetachExpectation withHandle(Matcher<?> m) {
diff --git 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/EndExpectation.java
 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/EndExpectation.java
index 76f817c4..edc84868 100644
--- 
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/EndExpectation.java
+++ 
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/expectations/EndExpectation.java
@@ -34,6 +34,7 @@ import 
org.apache.qpid.protonj2.test.driver.codec.transport.End;
 import org.apache.qpid.protonj2.test.driver.codec.transport.ErrorCondition;
 import org.apache.qpid.protonj2.test.driver.codec.util.TypeMapper;
 import org.apache.qpid.protonj2.test.driver.matchers.transport.EndMatcher;
+import 
org.apache.qpid.protonj2.test.driver.matchers.transport.ErrorConditionMatcher;
 import org.hamcrest.Matcher;
 
 /**
@@ -111,6 +112,18 @@ public class EndExpectation extends 
AbstractExpectation<End> {
         return withError(equalTo(new ErrorCondition(condition, description, 
info)));
     }
 
+    public EndExpectation withError(String condition) {
+        return withError(new ErrorConditionMatcher().withCondition(condition));
+    }
+
+    public EndExpectation withError(String condition, Matcher<?> 
descriptionMatcher) {
+        return withError(new 
ErrorConditionMatcher().withCondition(condition).withDescription(descriptionMatcher));
+    }
+
+    public EndExpectation withError(String condition, Matcher<?> 
descriptionMatcher, Matcher<?> infoMapMatcher) {
+        return withError(new 
ErrorConditionMatcher().withCondition(condition).withDescription(descriptionMatcher).withInfo(infoMapMatcher));
+    }
+
     //----- Matcher based with methods for more complex validation
 
     public EndExpectation withError(Matcher<?> m) {
diff --git 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java
 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java
index 42c3e968..e5720836 100644
--- 
a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java
+++ 
b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/SenderHandlingTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.qpid.protonj2.test.driver;
 
+import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.net.URI;
@@ -549,4 +550,34 @@ class SenderHandlingTest extends TestPeerTestsBase {
             peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
         }
     }
+
+    @Test
+    public void testDetachCanExpectMatcherInDescription() throws Exception {
+        try (ProtonTestServer peer = new ProtonTestServer();
+             ProtonTestClient client = new ProtonTestClient()) {
+
+            peer.expectAMQPHeader().respondWithAMQPHeader();
+            peer.expectOpen();
+            peer.expectBegin();
+            peer.expectAttach().ofSender();
+            peer.expectDetach().withError("amqp:not-authorized", 
equalTo("test"));
+            peer.start();
+
+            URI remoteURI = peer.getServerURI();
+
+            LOG.info("Test started, peer listening on: {}", remoteURI);
+
+            client.connect(remoteURI.getHost(), remoteURI.getPort());
+            client.expectAMQPHeader();
+            client.remoteAMQPHeader().now();
+            client.remoteOpen().now();
+            client.remoteBegin().now();
+            client.remoteAttach().ofSender().now();
+            client.remoteDetach().withErrorCondition("amqp:not-authorized", 
"test").now();
+
+            // Wait for the above and then script next steps
+            client.waitForScriptToComplete(5, TimeUnit.SECONDS);
+            peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+        }
+    }
 }


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

Reply via email to