You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: support built-in WireMock matchers on properties and list entries (#109)
- adding `property` configuration for request matching
- adding `list` configuration for request matching
- supporting WireMock's built-in matchers for request matching
- cleaned template helper tests to be more elaborate
- cleaned up state request matcher tests to be more elaborate
<!-- Please describe your pull request here. -->
## References
#64
<!-- References to relevant GitHub issues and pull requests, esp.
upstream and downstream changes -->
## Submitter checklist
- [ ] Recommended: Join [WireMock Slack](https://slack.wiremock.org/) 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](https://github.com/wiremock/wiremock.org)
<!--
Put an `x` into the [ ] to show you have filled the information.
The template comes from
https://github.com/wiremock/.github/blob/main/.github/pull_request_template.md
You can override it by creating .github/pull_request_template.md in your
own repository
-->
The state is recorded in `serveEventListeners` of a stub. The following functionalities are provided:
309
309
310
310
-`state` : stores a state in a context. Storing the state multiple times can be used to selectively overwrite existing properties.
311
-
- to delete a selective property, set it to `null` (as string).
311
+
- to delete a selective property, set it to `null` (as string).
312
312
-`list` : stores a state in a list. Can be used to prepend/append new states to an existing list. List elements cannot be modified (only read/deleted).
313
313
314
314
`state` and `list` can be used in the same `ServeEventListener` (would count as two updates). Adding multiple `recordState``ServeEventListener` is supported.
@@ -702,8 +702,8 @@ to avoid memory leaks).
702
702
The default expiration is 60 minutes. The default value can be overwritten (`0` = default = 60 minutes):
703
703
704
704
```java
705
-
int expiration=1024;
706
-
var store=newCaffeineStore(expiration);
705
+
int expiration=1024;
706
+
var store=newCaffeineStore(expiration);
707
707
```
708
708
709
709
## Match a request against a context
@@ -760,6 +760,46 @@ As for other matchers, templating is supported.
760
760
}
761
761
```
762
762
763
+
### Full flexible property match
764
+
765
+
In case you want full flexibility into matching on a property, you can simply specify `property` and use one of WireMock's built-in matchers, allowing you to
766
+
configure
767
+
logical operators, regex, date matchers, absence and much more. The basic syntax:
768
+
769
+
```json
770
+
"property": {
771
+
<property-a>: <matcher-a>,
772
+
<property-b>: <matcher-b>
773
+
}
774
+
```
775
+
776
+
Example:
777
+
778
+
```json
779
+
{
780
+
"request": {
781
+
"method": "GET",
782
+
"urlPattern": "/test/[^\/]+/[^\/]+",
783
+
"customMatcher": {
784
+
"name": "state-matcher",
785
+
"parameters": {
786
+
"property": {
787
+
"myProperty": {
788
+
"contains": "myValue"
789
+
}
790
+
}
791
+
}
792
+
},
793
+
"response": {
794
+
"status": 200
795
+
}
796
+
}
797
+
```
798
+
799
+
The implementation makes use of WireMock's internal matching system and supports any implementation of `StringValuePattern`. As of WireMock 3.3, this includes
For documentation on using these matchers, check the [WireMock documentation](https://wiremock.org/docs/request-matching/)
763
803
764
804
### Context update count match
765
805
@@ -770,7 +810,8 @@ for request matching as well. The following matchers are available:
770
810
- `updateCountLessThan`
771
811
- `updateCountMoreThan`
772
812
773
-
As for other matchers, templating is supported. In case the provided value for this check is not numeric, it is handled as non-matching. No error will be reported or logged.
813
+
As for other matchers, templating is supported. In case the provided value for this check is not numeric, it is handled as non-matching. No error will be
814
+
reported or logged.
774
815
775
816
```json
776
817
{
@@ -800,7 +841,8 @@ for request matching as well. The following matchers are available:
800
841
- `listSizeLessThan`
801
842
- `listSizeMoreThan`
802
843
803
-
As for other matchers, templating is supported. In case the provided value for this check is not numeric, it is handled as non-matching. No error will be reported or logged.
844
+
As for other matchers, templating is supported. In case the provided value for this check is not numeric, it is handled as non-matching. No error will be
845
+
reported or logged.
804
846
805
847
```json
806
848
{
@@ -821,6 +863,57 @@ As for other matchers, templating is supported. In case the provided value for t
821
863
}
822
864
```
823
865
866
+
### Full flexible list entry property match
867
+
868
+
Similar to properties, you have full flexibility into matching on a property of a list entry by specifying `list` and using one of WireMock's built-in matchers
869
+
The basic syntax:
870
+
871
+
```json
872
+
"list": {
873
+
<index-a>: {
874
+
<property-a>: <matcher-a>,
875
+
<property-b>: <matcher-b>
876
+
},
877
+
<index-b>: {
878
+
<property-a>: <matcher-a>,
879
+
<property-b>: <matcher-b>
880
+
}
881
+
}
882
+
```
883
+
884
+
As index, you can use the actual index as well as `first`, `last`, `-1`.
885
+
886
+
Example:
887
+
888
+
```json
889
+
{
890
+
"request": {
891
+
"method": "GET",
892
+
"urlPattern": "/test/[^\/]+/[^\/]+",
893
+
"customMatcher": {
894
+
"name": "state-matcher",
895
+
"parameters": {
896
+
"list": {
897
+
"1": {
898
+
"myProperty": {
899
+
"contains": "myValue"
900
+
}
901
+
}
902
+
}
903
+
}
904
+
},
905
+
"response": {
906
+
"status": 200
907
+
}
908
+
}
909
+
```
910
+
911
+
The implementation makes use of WireMock's internal matching system and supports any implementation of `StringValuePattern`. As of WireMock 3.3, this includes
0 commit comments