Skip to content

Conversation

@armanb1989
Copy link

This PR adds numeric comparisons functionality to the state-matcher, allowing matching requests based on numeric conditions for state properties. The implementation supports comparison operators (gt, gte, lt, lte, eq, ne) with both constant values and state property values via templating.

References

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

Changes

  • Added ComparisonOperator enum to handle numeric comparison operations
  • Extended StateRequestMatcher to support numericComparisons parameter
  • Added comprehensive unit tests covering all comparison operators and edge cases
  • Updated documentation with usage examples and configuration details

Testing

  • Unit tests verify all comparison operators work correctly
  • Tests cover both constant values and templated state property values
  • Edge cases like non-numeric values and missing properties are tested
  • Integration tests demonstrate real-world usage scenarios

Documentation

Added new "Numeric comparisons match" section to README.md with:

  • Supported operators reference
  • Basic usage example with constant values
  • Advanced example with state property templating
  • Multiple property comparisons example
  • Important usage notes and limitations

Comment on lines +1081 to +1086
"numericComparisons": {
"amount": {
"gt": "0",
"lte": "100"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all other matchers, we have the following structure:

"amount": {
  "contains": "100"
} 

applying this to your matchers, it should look like:

"amount": {
  "gt": "100"
} 

If you can make it fit into this structure, you get and, or, not for free - and it would also work on list properties:

"amount": {
  "and": [
    { "gt": "100" },
    { "lt": "200" }
  ]
} 

Copy link
Collaborator

@dirkbolte dirkbolte Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just seeing that this would require a bit more work, but it looks like a cleaner approach. I will give it a try.

Copy link
Author

@armanb1989 armanb1989 Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I agree, implementing the and, or, and not operators will make the system much more coherent. I will add them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw your comment on the issue about implementing this logic in Wiremock core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants