Matching System
System used to select a Scenario based on the received request
For each request received, Copycat will parse a Scenario Key an get all Scenarios grouped by this key. Then, it will iterate over the array of Scenarios, on the declared order, until a match occurs.
The match is made in a way that every declared restriction must match and additional fields received, that have no restrictions declared, are ignored.
Matches are evaluated using one of the following strategies.
Equals
This strategy is the simplest one, it just compares the received request with an hardcoded value. If the values are equals, then it is considered a match.
"request": {
"body": {
"name": "Gustavo Lima"
}
}
Regular Expressions
The Regular Expression strategy will compare the received value with the declared expression.
Any valid regular expression is accepted by this strategy, and to use it, the expression should
be wrapped on #{}
.
If the declared expression matches the received value, then it is considered a match.
"request": {
"body": {
"name": "#{Gustavo.*}"
}
}
Code Expressions
Code Expressions works like an Expression Language with a limited number of available operations.
If the expression evaluates to boolean, it will be considered a match if true
, otherwise, the
evaluated value will be compared to the received value, the same way as the Equals strategy.
"request": {
"body": {
"name": "${request.body.name.length() > 5}"
}
}
Check all the available operations on the Commands section.