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 e77fd987 PROTON-2802 Make using matchers for map type message sections
easier
e77fd987 is described below
commit e77fd987909043e7fbfd0bf2cbe3808e24d66602
Author: Timothy Bish <[email protected]>
AuthorDate: Tue Mar 5 18:20:48 2024 -0500
PROTON-2802 Make using matchers for map type message sections easier
Provide simpler APIs for MessageAnnotations, DeliveryAnnotations,
Footers and ApplicationProperties matchers to allow just setting the
expected types and not needing to provide a matcher for every single
one. Also make key type more explicit in the simple APIs
---
.../qpid/protonj2/client/impl/MessageSendTest.java | 12 ++++----
.../protonj2/client/impl/StreamSenderTest.java | 36 +++++++++++-----------
.../messaging/AbstractListSectionMatcher.java | 2 +-
.../messaging/AbstractMapSectionMatcher.java | 18 +++++++++--
.../messaging/AbstractMessageSectionMatcher.java | 8 ++---
.../messaging/ApplicationPropertiesMatcher.java | 18 +++++++++--
.../messaging/DeliveryAnnotationsMatcher.java | 31 +++++++++++--------
.../driver/matchers/messaging/FooterMatcher.java | 35 ++++++++++++---------
.../driver/matchers/messaging/HeaderMatcher.java | 2 +-
.../messaging/MessageAnnotationsMatcher.java | 35 ++++++++++++---------
.../matchers/messaging/PropertiesMatcher.java | 2 +-
11 files changed, 122 insertions(+), 77 deletions(-)
diff --git
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/MessageSendTest.java
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/MessageSendTest.java
index 73aa64d4..319597c3 100644
---
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/MessageSendTest.java
+++
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/MessageSendTest.java
@@ -242,8 +242,8 @@ class MessageSendTest extends ImperativeClientTestCase {
session.openReceiver("dummy").openFuture().get();
DeliveryAnnotationsMatcher daMatcher = new
DeliveryAnnotationsMatcher(true);
- daMatcher.withEntry("one", Matchers.equalTo(1));
- daMatcher.withEntry("two", Matchers.equalTo(2));
+ daMatcher.withEntry("one", 1);
+ daMatcher.withEntry("two", 2);
daMatcher.withEntry("three", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new
EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new
TransferPayloadCompositeMatcher();
@@ -305,7 +305,7 @@ class MessageSendTest extends ImperativeClientTestCase {
MessageAnnotationsMatcher maMatcher = new
MessageAnnotationsMatcher(true);
maMatcher.withEntry("one", Matchers.equalTo(1));
- maMatcher.withEntry("two", Matchers.equalTo(2));
+ maMatcher.withEntry("two", 2);
maMatcher.withEntry("three", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new
EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new
TransferPayloadCompositeMatcher();
@@ -365,9 +365,9 @@ class MessageSendTest extends ImperativeClientTestCase {
session.openReceiver("dummy").openFuture().get();
ApplicationPropertiesMatcher apMatcher = new
ApplicationPropertiesMatcher(true);
- apMatcher.withEntry("one", Matchers.equalTo(1));
- apMatcher.withEntry("two", Matchers.equalTo(2));
- apMatcher.withEntry("three", Matchers.equalTo(3));
+ apMatcher.withEntry("one", 1);
+ apMatcher.withEntry("two", 2);
+ apMatcher.withEntry("three", 3);
EncodedAmqpValueMatcher bodyMatcher = new
EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new
TransferPayloadCompositeMatcher();
payloadMatcher.setApplicationPropertiesMatcher(apMatcher);
diff --git
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamSenderTest.java
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamSenderTest.java
index 24de6f3b..677f5f69 100644
---
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamSenderTest.java
+++
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/StreamSenderTest.java
@@ -1537,9 +1537,9 @@ public class StreamSenderTest extends
ImperativeClientTestCase {
// Populate delivery annotations
final Map<String, Object> deliveryAnnotations = new HashMap<>();
- deliveryAnnotations.put("da1", 1);
- deliveryAnnotations.put("da2", 2);
- deliveryAnnotations.put("da3", 3);
+ deliveryAnnotations.put("da1", "a");
+ deliveryAnnotations.put("da2", "b");
+ deliveryAnnotations.put("da3", "c");
StreamSender sender = connection.openStreamSender("test-queue");
StreamSenderMessage message =
sender.beginMessage(deliveryAnnotations);
@@ -1567,17 +1567,17 @@ public class StreamSenderTest extends
ImperativeClientTestCase {
propertiesMatcher.withGroupSequence(8192);
propertiesMatcher.withReplyToGroupId("/dev/null");
DeliveryAnnotationsMatcher daMatcher = new
DeliveryAnnotationsMatcher(true);
- daMatcher.withEntry("da1", Matchers.equalTo(1));
- daMatcher.withEntry("da2", Matchers.equalTo(2));
- daMatcher.withEntry("da3", Matchers.equalTo(3));
+ daMatcher.withEntry("da1", "a");
+ daMatcher.withEntry("da2", "b");
+ daMatcher.withEntry("da3", "c");
MessageAnnotationsMatcher maMatcher = new
MessageAnnotationsMatcher(true);
- maMatcher.withEntry("ma1", Matchers.equalTo(1));
- maMatcher.withEntry("ma2", Matchers.equalTo(2));
- maMatcher.withEntry("ma3", Matchers.equalTo(3));
+ maMatcher.withEntry("ma1", 1);
+ maMatcher.withEntry("ma2", 2);
+ maMatcher.withEntry("ma3", 3);
ApplicationPropertiesMatcher apMatcher = new
ApplicationPropertiesMatcher(true);
- apMatcher.withEntry("ap1", Matchers.equalTo(1));
- apMatcher.withEntry("ap2", Matchers.equalTo(2));
- apMatcher.withEntry("ap3", Matchers.equalTo(3));
+ apMatcher.withEntry("ap1", 10);
+ apMatcher.withEntry("ap2", 20);
+ apMatcher.withEntry("ap3", 30);
EncodedDataMatcher bodyMatcher = new EncodedDataMatcher(payload);
TransferPayloadCompositeMatcher payloadMatcher = new
TransferPayloadCompositeMatcher();
payloadMatcher.setHeadersMatcher(headerMatcher);
@@ -1642,13 +1642,13 @@ public class StreamSenderTest extends
ImperativeClientTestCase {
// Populate message application properties
assertFalse(message.hasProperties());
assertFalse(message.hasProperty("ma1"));
- message.property("ap1", 1);
- assertEquals(1, message.property("ap1"));
+ message.property("ap1", 10);
+ assertEquals(10, message.property("ap1"));
assertTrue(message.hasProperty("ap1"));
- message.property("ap2", 2);
- assertEquals(2, message.property("ap2"));
- message.property("ap3", 3);
- assertEquals(3, message.property("ap3"));
+ message.property("ap2", 20);
+ assertEquals(20, message.property("ap2"));
+ message.property("ap3", 30);
+ assertEquals(30, message.property("ap3"));
assertTrue(message.hasProperties());
OutputStream stream = message.body();
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractListSectionMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractListSectionMatcher.java
index 7fc93616..b0d1fc3b 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractListSectionMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractListSectionMatcher.java
@@ -26,7 +26,7 @@ import
org.apache.qpid.protonj2.test.driver.codec.primitives.Symbol;
import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong;
import org.hamcrest.Matcher;
-public abstract class AbstractListSectionMatcher extends
AbstractMessageSectionMatcher {
+public abstract class AbstractListSectionMatcher<T extends
AbstractListSectionMatcher<T>> extends AbstractMessageSectionMatcher<T> {
public AbstractListSectionMatcher(UnsignedLong numericDescriptor, Symbol
symbolicDescriptor, Map<Object, Matcher<?>> fieldMatchers, boolean
expectTrailingBytes) {
super(numericDescriptor, symbolicDescriptor, fieldMatchers,
expectTrailingBytes);
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMapSectionMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMapSectionMatcher.java
index 3ae4ba20..2be8c652 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMapSectionMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMapSectionMatcher.java
@@ -24,7 +24,7 @@ import
org.apache.qpid.protonj2.test.driver.codec.primitives.Symbol;
import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong;
import org.hamcrest.Matcher;
-public abstract class AbstractMapSectionMatcher extends
AbstractMessageSectionMatcher {
+public abstract class AbstractMapSectionMatcher<T extends
AbstractMapSectionMatcher<T>> extends AbstractMessageSectionMatcher<T> {
public AbstractMapSectionMatcher(UnsignedLong numericDescriptor, Symbol
symbolicDescriptor, Map<Object, Matcher<?>> fieldMatchers, boolean
expectTrailingBytes) {
super(numericDescriptor, symbolicDescriptor, fieldMatchers,
expectTrailingBytes);
@@ -41,8 +41,20 @@ public abstract class AbstractMapSectionMatcher extends
AbstractMessageSectionMa
verifyReceivedFields((Map<Object, Object>) described);
}
- public AbstractMapSectionMatcher withEntry(Object key, Matcher<?> m) {
+ protected abstract T self();
+
+ public T withEntry(Object key, Matcher<?> m) {
+ validateMepKeyType(key);
getMatchers().put(key, m);
- return this;
+ return self();
}
+
+ /**
+ * Validate the map entry key type and throw an error if the type is not
allowed in the map
+ *
+ * @param key
+ * The key that will be used for matching map entries
+ */
+ protected abstract void validateMepKeyType(Object key);
+
}
\ No newline at end of file
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMessageSectionMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMessageSectionMatcher.java
index 5c1e822f..ac174685 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMessageSectionMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/AbstractMessageSectionMatcher.java
@@ -31,7 +31,7 @@ import org.hamcrest.Matcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractMessageSectionMatcher {
+public abstract class AbstractMessageSectionMatcher<T extends
AbstractMessageSectionMatcher<T>> {
private final Logger LOG = LoggerFactory.getLogger(getClass());
@@ -41,13 +41,13 @@ public abstract class AbstractMessageSectionMatcher {
private final Map<Object, Matcher<?>> fieldMatchers;
private Map<Object, Object> receivedFields;
- private final boolean expectTrailingBytes;
+ private final boolean allowTrailingBytes;
protected AbstractMessageSectionMatcher(UnsignedLong numericDescriptor,
Symbol symbolicDescriptor, Map<Object, Matcher<?>> fieldMatchers, boolean
expectTrailingBytes) {
this.numericDescriptor = numericDescriptor;
this.symbolicDescriptor = symbolicDescriptor;
this.fieldMatchers = fieldMatchers;
- this.expectTrailingBytes = expectTrailingBytes;
+ this.allowTrailingBytes = expectTrailingBytes;
}
protected Map<Object, Matcher<?>> getMatchers() {
@@ -76,7 +76,7 @@ public abstract class AbstractMessageSectionMatcher {
throw new IllegalStateException("Decoded more bytes than Binary
supports holding");
}
- if (decoded < length && !expectTrailingBytes) {
+ if (decoded < length && !allowTrailingBytes) {
throw new IllegalArgumentException(
"Expected to consume all bytes, but trailing bytes remain: Got
" + length + ", consumed " + decoded);
}
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/ApplicationPropertiesMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/ApplicationPropertiesMatcher.java
index 23b4ea80..6dc73f5b 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/ApplicationPropertiesMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/ApplicationPropertiesMatcher.java
@@ -23,8 +23,9 @@ import java.util.HashMap;
import org.apache.qpid.protonj2.test.driver.codec.primitives.Symbol;
import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong;
import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
-public class ApplicationPropertiesMatcher extends AbstractMapSectionMatcher {
+public class ApplicationPropertiesMatcher extends
AbstractMapSectionMatcher<ApplicationPropertiesMatcher> {
public static final Symbol DESCRIPTOR_SYMBOL =
Symbol.valueOf("amqp:application-properties:map");
public static final UnsignedLong DESCRIPTOR_CODE =
UnsignedLong.valueOf(0x0000000000000074L);
@@ -33,12 +34,23 @@ public class ApplicationPropertiesMatcher extends
AbstractMapSectionMatcher {
super(DESCRIPTOR_CODE, DESCRIPTOR_SYMBOL, new HashMap<Object,
Matcher<?>>(), expectTrailingBytes);
}
+ public ApplicationPropertiesMatcher withEntry(String key, Matcher<?> m) {
+ return super.withEntry(key, m);
+ }
+
+ public ApplicationPropertiesMatcher withEntry(String key, Object value) {
+ return super.withEntry(key, Matchers.equalTo(value));
+ }
+
@Override
- public ApplicationPropertiesMatcher withEntry(Object key, Matcher<?> m) {
+ protected void validateMepKeyType(Object key) {
if (!(key instanceof String)) {
throw new RuntimeException("ApplicationProperties maps must use
non-null String keys");
}
+ }
- return (ApplicationPropertiesMatcher) super.withEntry(key, m);
+ @Override
+ protected ApplicationPropertiesMatcher self() {
+ return this;
}
}
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/DeliveryAnnotationsMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/DeliveryAnnotationsMatcher.java
index 990f0115..97483499 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/DeliveryAnnotationsMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/DeliveryAnnotationsMatcher.java
@@ -24,8 +24,9 @@ import java.util.Map;
import org.apache.qpid.protonj2.test.driver.codec.primitives.Symbol;
import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong;
import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
-public class DeliveryAnnotationsMatcher extends AbstractMapSectionMatcher {
+public class DeliveryAnnotationsMatcher extends
AbstractMapSectionMatcher<DeliveryAnnotationsMatcher> {
public static final Symbol DESCRIPTOR_SYMBOL =
Symbol.valueOf("amqp:delivery-annotations:map");
public static final UnsignedLong DESCRIPTOR_CODE =
UnsignedLong.valueOf(0x0000000000000071L);
@@ -34,26 +35,27 @@ public class DeliveryAnnotationsMatcher extends
AbstractMapSectionMatcher {
super(DESCRIPTOR_CODE, DESCRIPTOR_SYMBOL, new HashMap<Object,
Matcher<?>>(), expectTrailingBytes);
}
- @Override
- public DeliveryAnnotationsMatcher withEntry(Object key, Matcher<?> m) {
- validateType(key);
+ public DeliveryAnnotationsMatcher withEntry(String key, Matcher<?> m) {
+ return super.withEntry(Symbol.valueOf(key), m);
+ }
- return (DeliveryAnnotationsMatcher) super.withEntry(key, m);
+ public DeliveryAnnotationsMatcher withEntry(String key, Object value) {
+ return super.withEntry(Symbol.valueOf(key), Matchers.equalTo(value));
}
- private void validateType(Object key) {
+ public DeliveryAnnotationsMatcher withEntry(Symbol key, Object value) {
+ return super.withEntry(key, Matchers.equalTo(value));
+ }
+
+ @Override
+ protected void validateMepKeyType(Object key) {
if (!(key instanceof Long || key instanceof Symbol)) {
throw new IllegalArgumentException("Delivery Annotation keys must
be of type Symbol or long (reserved)");
}
}
- public DeliveryAnnotationsMatcher withEntry(String key, Matcher<?> m) {
- getMatchers().put(Symbol.valueOf(key), m);
- return this;
- }
-
public boolean keyExistsInReceivedAnnotations(Object key) {
- validateType(key);
+ validateMepKeyType(key);
Map<Object, Object> receivedFields = super.getReceivedFields();
@@ -69,4 +71,9 @@ public class DeliveryAnnotationsMatcher extends
AbstractMapSectionMatcher {
return receivedFields.get(key);
}
+
+ @Override
+ protected DeliveryAnnotationsMatcher self() {
+ return this;
+ }
}
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/FooterMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/FooterMatcher.java
index 8cecc690..f9136e00 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/FooterMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/FooterMatcher.java
@@ -24,8 +24,9 @@ import java.util.Map;
import org.apache.qpid.protonj2.test.driver.codec.primitives.Symbol;
import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong;
import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
-public class FooterMatcher extends AbstractMapSectionMatcher {
+public class FooterMatcher extends AbstractMapSectionMatcher<FooterMatcher> {
public static final Symbol DESCRIPTOR_SYMBOL =
Symbol.valueOf("amqp:footer:map");
public static final UnsignedLong DESCRIPTOR_CODE =
UnsignedLong.valueOf(0x0000000000000078L);
@@ -34,26 +35,20 @@ public class FooterMatcher extends
AbstractMapSectionMatcher {
super(DESCRIPTOR_CODE, DESCRIPTOR_SYMBOL, new HashMap<Object,
Matcher<?>>(), expectTrailingBytes);
}
- @Override
- public FooterMatcher withEntry(Object key, Matcher<?> m) {
- validateType(key);
-
- return (FooterMatcher) super.withEntry(key, m);
+ public FooterMatcher withEntry(String key, Matcher<?> m) {
+ return super.withEntry(Symbol.valueOf(key), m);
}
- private void validateType(Object key) {
- if (!(key instanceof Long || key instanceof Symbol)) {
- throw new IllegalArgumentException("Footer keys must be of type
Symbol or long (reserved)");
- }
+ public FooterMatcher withEntry(String key, Object value) {
+ return super.withEntry(Symbol.valueOf(key), Matchers.equalTo(value));
}
- public FooterMatcher withEntry(String key, Matcher<?> m) {
- getMatchers().put(Symbol.valueOf(key), m);
- return this;
+ public FooterMatcher withEntry(Symbol key, Object value) {
+ return super.withEntry(key, Matchers.equalTo(value));
}
public boolean keyExistsInReceivedAnnotations(Object key) {
- validateType(key);
+ validateMepKeyType(key);
Map<Object, Object> receivedFields = super.getReceivedFields();
@@ -69,4 +64,16 @@ public class FooterMatcher extends AbstractMapSectionMatcher
{
return receivedFields.get(key);
}
+
+ @Override
+ protected void validateMepKeyType(Object key) {
+ if (!(key instanceof Long || key instanceof Symbol)) {
+ throw new IllegalArgumentException("Footer keys must be of type
Symbol or long (reserved)");
+ }
+ }
+
+ @Override
+ protected FooterMatcher self() {
+ return this;
+ }
}
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/HeaderMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/HeaderMatcher.java
index 699165ee..85265a0c 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/HeaderMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/HeaderMatcher.java
@@ -32,7 +32,7 @@ import org.hamcrest.Matcher;
* Generated by generate-message-section-matchers.xsl, which resides in this
* package.
*/
-public class HeaderMatcher extends AbstractListSectionMatcher {
+public class HeaderMatcher extends AbstractListSectionMatcher<HeaderMatcher> {
public static final Symbol DESCRIPTOR_SYMBOL =
Symbol.valueOf("amqp:header:list");
public static final UnsignedLong DESCRIPTOR_CODE =
UnsignedLong.valueOf(0x0000000000000070L);
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/MessageAnnotationsMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/MessageAnnotationsMatcher.java
index 15c44e80..ab1d5e1d 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/MessageAnnotationsMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/MessageAnnotationsMatcher.java
@@ -24,8 +24,9 @@ import java.util.Map;
import org.apache.qpid.protonj2.test.driver.codec.primitives.Symbol;
import org.apache.qpid.protonj2.test.driver.codec.primitives.UnsignedLong;
import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
-public class MessageAnnotationsMatcher extends AbstractMapSectionMatcher {
+public class MessageAnnotationsMatcher extends
AbstractMapSectionMatcher<MessageAnnotationsMatcher> {
public static final Symbol DESCRIPTOR_SYMBOL =
Symbol.valueOf("amqp:message-annotations:map");
public static final UnsignedLong DESCRIPTOR_CODE =
UnsignedLong.valueOf(0x0000000000000072L);
@@ -34,26 +35,20 @@ public class MessageAnnotationsMatcher extends
AbstractMapSectionMatcher {
super(DESCRIPTOR_CODE, DESCRIPTOR_SYMBOL, new HashMap<Object,
Matcher<?>>(), expectTrailingBytes);
}
- @Override
- public MessageAnnotationsMatcher withEntry(Object key, Matcher<?> m) {
- validateType(key);
-
- return (MessageAnnotationsMatcher) super.withEntry(key, m);
+ public MessageAnnotationsMatcher withEntry(String key, Matcher<?> m) {
+ return super.withEntry(Symbol.valueOf(key), m);
}
- private void validateType(Object key) {
- if (!(key instanceof Long || key instanceof Symbol)) {
- throw new IllegalArgumentException("Message Annotation keys must
be of type Symbol or long (reserved)");
- }
+ public MessageAnnotationsMatcher withEntry(String key, Object value) {
+ return super.withEntry(Symbol.valueOf(key), Matchers.equalTo(value));
}
- public MessageAnnotationsMatcher withEntry(String key, Matcher<?> m) {
- getMatchers().put(Symbol.valueOf(key), m);
- return this;
+ public MessageAnnotationsMatcher withEntry(Symbol key, Object value) {
+ return super.withEntry(key, Matchers.equalTo(value));
}
public boolean keyExistsInReceivedAnnotations(Object key) {
- validateType(key);
+ validateMepKeyType(key);
Map<Object, Object> receivedFields = super.getReceivedFields();
@@ -69,4 +64,16 @@ public class MessageAnnotationsMatcher extends
AbstractMapSectionMatcher {
return receivedFields.get(key);
}
+
+ @Override
+ protected void validateMepKeyType(Object key) {
+ if (!(key instanceof Long || key instanceof Symbol)) {
+ throw new IllegalArgumentException("Message Annotation keys must
be of type Symbol or long (reserved)");
+ }
+ }
+
+ @Override
+ protected MessageAnnotationsMatcher self() {
+ return this;
+ }
}
diff --git
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/PropertiesMatcher.java
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/PropertiesMatcher.java
index 37f87f10..69c6d253 100644
---
a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/PropertiesMatcher.java
+++
b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/matchers/messaging/PropertiesMatcher.java
@@ -34,7 +34,7 @@ import org.hamcrest.Matcher;
* Generated by generate-message-section-matchers.xsl, which resides in this
* package.
*/
-public class PropertiesMatcher extends AbstractListSectionMatcher {
+public class PropertiesMatcher extends
AbstractListSectionMatcher<PropertiesMatcher> {
public static final Symbol DESCRIPTOR_SYMBOL =
Symbol.valueOf("amqp:properties:list");
public static final UnsignedLong DESCRIPTOR_CODE =
UnsignedLong.valueOf(0x0000000000000073L);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]