When Traffic Parrot receives a request via any protocol or technology like HTTP, JMS, gRPC and others, it will try to simulate the system it is replacing by sending back a response to the client that sent the request.
To decide which response to send, it will go through all the request to response mappings it has available to find the response to be returned.
A request to response mapping defines which response to return given a request.
For example, in HTTP, you could say:
For any request to URL '/hello' that is a GET request return a response with body 'Hello World!'
The way you do that in Traffic Parrot is by using the user interface to record mappings, import them or add them manually.
{ "id" : "a6263f39-5826-48a5-a409-4d78037c303e", "request" : { "url" : "/MODApis/Api/v2/Quote/json?AAPL", "method" : "GET" }, "response" : { "status" : 200, "body" : "{\r\n \"Status\": \"SUCCESS\",\r\n \"High\": 116.91,\r\n \"MSDate\": 42664,\r\n \"Change\": -0.46,\r\n \"LastPrice\": 116.6,\r\n \"Timestamp\": \"Fri Oct 21 00:00:00 UTC-04:00 2016\",\r\n \"ChangePercentYTD\": 105.26,\r\n \"Name\": \"Apple Inc\",\r\n \"Open\": 116.81,\r\n \"Volume\": 23192665,\r\n \"Low\": 116.28,\r\n \"ChangeYTD\": 105.26,\r\n \"ChangePercent\": -0.3929608748,\r\n \"MarketCap\": 628292453800\r\n}", "headers" : { "Content-Type" : "text/javascript; charset=UTF-8" } }, "uuid" : "a6263f39-5826-48a5-a409-4d78037c303e" }
Traffic Parrot support matching attributes of requests using the following matchers.
Protocol/technology | Matchers available |
---|---|
HTTP(S) | list of HTTP(S) matchers |
JMS | list of JMS matchers |
Native IBM MQ | list of MQ matchers |
gRPC | list of gRPC matchers |
Thrift | list of Thrift matchers |
Files | list of files matchers |
Here is a collection of matcher examples that cover typical request matching use cases.
Use case | JSON to match | JSONPath |
---|---|---|
Has field that exists, even if it contains a null value | { "field" : null } |
$[?(@.field)] |
Does not have a particular field at all | { "other" : "any" } |
$[?(!(@.field))] |
Has field matching regular expression | { "name" : "John" } |
$[?(@.name =~ /^J[a-z]+$/)] |
Has field not matching regular expression | { "name" : "Other" } |
$[?(!(@.name =~ /^J[a-z]+$/))] |
Has field with value equal to | { "name" : "John" } |
$[?(@.name == 'John')] |
Has multiple fields with value equal to | { "name" : "John", "lastName" : "Smith" } |
$[?(@.name == 'John' && @.lastName == 'Smith')] |
Has field with value equal to either | { "name" : "Bob" } { "name" : "John" } |
$[?(@.name == 'John' || @.name == 'Bob')] |
Has array containing field with value equal to | { "root" : { "items" : [ { "id": "1111" } ] } } |
$.root[?('1' in @.items[*].id)] |
Has array containing fields with values equal to | { "root" : { "items" : [ { "id": "1" }, { "id": "2" } ] } } |
$.root[?('1' in @.items[*].id && '2' in @.items[*].id)] |
Has fields at multiple depths | { "id": 1, "items": [ { "id": 2, } ] } |
$[?(@.id == 1 && 2 in @.items[*].id)] |
Traffic Parrot stores request to response mappings on the filesystem.
Protocol/technology | Mappings location |
---|---|
HTTP(S) | mappings and __files (where it stores bodies of responses during a recording) |
JMS | jms-mappings |
Native IBM MQ | ibm-mq-mappings |
gRPC | grpc-mappings |
Thrift | thrift-mappings |
Files | file-mappings |
You can change the root directory by changing the value of the trafficparrot.virtualservice.trafficFilesRootUrl property.
XPath (XML Path Language) is a query language for finding and selecting elements in an XML document. Traffic Parrot allows to match requests using XPath.
We recommend the following reading to users who would like to take their XPaths skills to an advanced level:
This documentation is for an old version of Traffic Parrot. There is a more recent Traffic Parrot version available for download at trafficparrot.com