Skip to content

Commit

Permalink
PROTON-2845 Improve output of failed match when validating messages
Browse files Browse the repository at this point in the history
When checking on scripted transfer payload contents the output should
provide more information to make it clear what failed in the contents
matching.
  • Loading branch information
tabish121 committed Aug 7, 2024
1 parent 26dd822 commit 9eaf5e0
Show file tree
Hide file tree
Showing 2 changed files with 348 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpTypeMatcher;
import org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher;
import org.apache.qpid.protonj2.test.driver.matchers.types.EncodedDataMatcher;
import org.apache.qpid.protonj2.test.driver.util.StringUtils;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
Expand Down Expand Up @@ -88,8 +89,9 @@ protected boolean matchesSafely(ByteBuffer receivedBinary) {
bytesConsumed += headersMatcher.getInnerMatcher().verify(receivedSlice.slice());
receivedSlice.position(bytesConsumed);
} catch (Throwable t) {
headerMatcherFailureDescription = "\nActual encoded form of remaining bytes passed to MessageHeaderMatcher: " + receivedSlice;
headerMatcherFailureDescription += "\nMessageHeaderMatcher generated throwable: " + t;
headerMatcherFailureDescription = "\nBuffer of bytes passed to Header Matcher: " + receivedSlice;
headerMatcherFailureDescription += "\nActual encoded form of remaining bytes passed: " + StringUtils.toQuotedString(receivedSlice);
headerMatcherFailureDescription += "\nHeader Matcher generated throwable: " + t.getMessage();

return false;
}
Expand All @@ -101,9 +103,9 @@ protected boolean matchesSafely(ByteBuffer receivedBinary) {
bytesConsumed += deliveryAnnotationsMatcher.getInnerMatcher().verify(receivedSlice.slice());
receivedSlice.position(bytesConsumed);
} catch (Throwable t) {
deliveryAnnotationsMatcherFailureDescription = "\nActual encoded form of remaining bytes passed " +
"to DeliveryAnnotationsMatcher: " + receivedSlice;
deliveryAnnotationsMatcherFailureDescription += "\nDeliveryAnnotationsMatcher generated throwable: " + t;
deliveryAnnotationsMatcherFailureDescription = "\nBuffer of bytes passed to Delivery Annotations Matcher: " + receivedSlice;
deliveryAnnotationsMatcherFailureDescription += "\nActual encoded form of remaining bytes passed: " + StringUtils.toQuotedString(receivedSlice);
deliveryAnnotationsMatcherFailureDescription += "\nDelivery Annotations Matcher generated throwable: " + t.getMessage();

return false;
}
Expand All @@ -115,9 +117,9 @@ protected boolean matchesSafely(ByteBuffer receivedBinary) {
bytesConsumed += messageAnnotationsMatcher.getInnerMatcher().verify(receivedSlice.slice());
receivedSlice.position(bytesConsumed);
} catch (Throwable t) {
messageAnnotationsMatcherFailureDescription = "\nActual encoded form of remaining bytes passed to " +
"MessageAnnotationsMatcher: " + receivedSlice;
messageAnnotationsMatcherFailureDescription += "\nMessageAnnotationsMatcher generated throwable: " + t;
messageAnnotationsMatcherFailureDescription = "\nBuffer of bytes passed to Message Annotations Matcher: " + receivedSlice;
messageAnnotationsMatcherFailureDescription += "\nActual encoded form of remaining bytes passed: " + StringUtils.toQuotedString(receivedSlice);
messageAnnotationsMatcherFailureDescription += "\nMessage Annotations Matcher generated throwable: " + t.getMessage();

return false;
}
Expand All @@ -129,9 +131,9 @@ protected boolean matchesSafely(ByteBuffer receivedBinary) {
bytesConsumed += propertiesMatcher.getInnerMatcher().verify(receivedSlice.slice());
receivedSlice.position(bytesConsumed);
} catch (Throwable t) {
propertiesMatcherFailureDescription = "\nActual encoded form of remaining bytes passed to " +
"PropertiesMatcher: " + receivedSlice;
propertiesMatcherFailureDescription += "\nPropertiesMatcher generated throwable: " + t;
propertiesMatcherFailureDescription = "\nBuffer of bytes passed to Properties Matcher: " + receivedSlice;
propertiesMatcherFailureDescription += "\nActual encoded form of remaining bytes passed: " + StringUtils.toQuotedString(receivedSlice);
propertiesMatcherFailureDescription += "\nProperties Matcher generated throwable: " + t.getMessage();

return false;
}
Expand All @@ -143,9 +145,9 @@ protected boolean matchesSafely(ByteBuffer receivedBinary) {
bytesConsumed += applicationPropertiesMatcher.getInnerMatcher().verify(receivedSlice.slice());
receivedSlice.position(bytesConsumed);
} catch (Throwable t) {
applicationPropertiesMatcherFailureDescription = "\nActual encoded form of remaining bytes passed to " +
"ApplicationPropertiesMatcher: " + receivedSlice;
applicationPropertiesMatcherFailureDescription += "\nApplicationPropertiesMatcher generated throwable: " + t;
applicationPropertiesMatcherFailureDescription = "\nBuffer of bytes passed to Application Properties Matcher: " + receivedSlice;
applicationPropertiesMatcherFailureDescription += "\nActual encoded form of remaining bytes passed: " + StringUtils.toQuotedString(receivedSlice);
applicationPropertiesMatcherFailureDescription += "\nApplication Properties Matcher generated throwable: " + t.getMessage();

return false;
}
Expand All @@ -161,9 +163,11 @@ protected boolean matchesSafely(ByteBuffer receivedBinary) {
if (!contentMatches) {
Description desc = new StringDescription();
msgContentMatcher.describeTo(desc);
msgContentMatcher.describeMismatch(receivedSlice, desc);
msgContentMatcher.describeMismatch(slicedMsgContext, desc);

msgContentMatcherFailureDescription = "\nMessageContentMatcher mismatch Description:";
msgContentMatcherFailureDescription = "\nBuffer of bytes passed to message contents Matcher: " + slicedMsgContext;
msgContentMatcherFailureDescription += "\nActual encoded form of remaining bytes passed: " + StringUtils.toQuotedString(receivedSlice);
msgContentMatcherFailureDescription += "\nMessageContentMatcher mismatch Description:";
msgContentMatcherFailureDescription += desc.toString();

return false;
Expand All @@ -181,7 +185,7 @@ protected boolean matchesSafely(ByteBuffer receivedBinary) {
} catch (Throwable t) {
footerMatcherFailureDescription = "\nActual encoded form of remaining bytes passed to " +
"FooterMatcher: " + receivedSlice;
footerMatcherFailureDescription += "\nFooterMatcher generated throwable: " + t;
footerMatcherFailureDescription += "\nFooterMatcher generated throwable: " + t.getMessage();

return false;
}
Expand Down
Loading

0 comments on commit 9eaf5e0

Please sign in to comment.