#####INCLUDE z.upperside.html
If the request is in GraphQL format, this field specifies where to look for GraphQL query or mutation.
If the whole request payload is GraphQL, as in
{ hero { name class }}
input
If GraphQL is in a JSON property of the request payload, as in
{ "query":"{ hero { name class }}" }
input.query
If GraphQL is in an HTTP parameter, as in
/npc?q={%20hero%20{%20name%20class%20}}
http.parameters.q
See the variables cheatsheet for more info.
The part of the URI left after the service URL is removed.
The URI can contain parameters, like in
/user/{userId}/statement/{statementId}
The special catch-all variable format is
/acc/{alltherest:.*}
The action is read from SOAPAction HTTP header (SOAP 1.1) or from the action attribute of Content-Type (SOAP 1.2).
The quotations are not used to compare, i.e. "GetSOCInfo" is the same as GetSOCInfo.
For SOAP payloads, this is the name of the first element under soap-env:Body, without the namespace.
For example, in
<soap-env:Envelope><soap-env:Body><user:GetCurrentUser>...</soap-env:Body></soap-env:Envelope>
For non-SOAP payloads, this is the name of the first element of the payload, without the namespace.
<id:GenerateID><id2:Format>UUID</id2:Format></id2:GenerateID>
The script can use any of the inbound variables.
For Javascript expressions, the boolean true value or any non-null value means a match.
For XQuery expressions, the boolean true value or any non-empty sequence value means a match.
Examples:
Use logical OR or AND when necessary
Test-execute the script using the Run button on the right side of the field.
The script is executed for every mock account. Those that result in Boolean true are selected for the transaction execution.
In fact, optimizations are performed, and so the selection usually does NOT check every account. Note that any scripts that contain conditions other than equals, logical AND, or logical OR can trigger a full accounts scan.
Each tested account is bound to a JS variable account or an XQ variable $account.
Note that the account variable names are case-sensitive, i.e. account.ban and account.BAN are not the same!
If the script evaluates to true for more than one account, all matching accounts are selected: they are placed into the $account sequence (for XQ) and into the accounts array (for JS). The total number of selected accounts is capped by the "Max Accounts" configuration drop down below.
Example: Select accounts where the BAN variable equals the request's BAN field:
account.BAN == input.query.BAN
Example: Select accounts where the NAG variable equals 1 or 2:
$account//NAG = "1" or $account//NAG = "2"
Example: Select accounts where the secondsAgo variable is more than the request's field age. Note that this script would cause a full accounts scan and may take some time because the greater-than comparison is not indexed in MM.
account.secondsAgo > $..age
For static XML response, place XML as-is:
<Data> <Error Code="0011"/> </Data>
Note: for SOAP responses, add Envelope, Header and Body. MockMotor doesn't do that automagically.
For computed XML response, use XQuery:
<Data> { for $code in $input//*:code return <Warning Message="Not Found" Code="{$code}"/> } </Data>
For static JSON, YAML or text responses, use the response payload as-is:
{ "profile": { "id": 100500, "firstName": "John" }, "status": "success" }
For computed JSON responses, use Javascript and assign the result to the output variable:
var fibo = []; fibo.push(1); fibo.push(1); for(var i=1; i<10; i++) { var len = fibo.length; var next = fibo[len-2] + fibo[len-1]; fibo.push(next); } output = { "fibo": fibo, "status": "success", "ref": jsonPath("$..transactionId") }
If forward to a live backend is used, you can leave this field empty to return the response that the backend provided. That response is saved into the output variable, so you can alter it before sending it back to the application.
Use static value (e.g. 200) or a script.
A made-up status 444 is used to simulate a network failure. It terminates the connection before the response is sent.
One header per line in Name: Value format. The value may be a script expression.
Example: Set a static header:
X-Correlation-ID: abc123
Example: Echo the request's correlation ID back:
X-Correlation-ID: $..correlationId
Example: Set multiple headers:
Content-Language: en Cache-Control: no-store X-Request-ID: http.headers["X-Request-ID"]
For a multi-line script value, indent the continuation lines with a space or tab:
X-Token: var parts = input.user.id.split('-'); parts[0] + '-' + parts[1]
Note: CORS headers are set automatically when needed and do not need to be listed here.
Specify the attachment names and optionally properties.
Adding one attachment by name:
Contract.pdf
Adding a group of attachments by name, their IDs and Content-Types are read from the mock environment:
["Contract.pdf","Addendum.pdf"]
Adding a group of attachments by name, with specific IDs and Content-Types:
[{"name":"Contract.pdf","content-id":"100","content-type":"application/pdf"},{"name":"Addendum.pdf","content-id":"200","content-type":"application/pdf"}]
One account property update per line in varName: value format. The value may be a script expression.
Example: Set a static value:
status: DONE
Example: Copy a value from the request:
balance: $..newBalance
Example: Update multiple properties:
status: ACTIVE lastUpdated: $..timestamp attempts: 0
balance: var b = parseFloat(account.balance) + parseFloat(input.amount); b.toString()
The Same / Distinct Values option below controls whether scripts are evaluated once for all accounts or once per account.
The script is exacuted with every selected account. If the result is true, the account is deleted.
To delete all selected accounts, put 'true' or 'all' into this field:
true
To delete some of the selected accounts, use a script that returns true for accounts that must be deleted:
JS:
// remember that account values are strings. Use parse* functions to compare to numbers. output = account.status == "DONE" || parseInt(account.priority) < 10;
XQ:
$account/status="DONE"
Specify the expressions for the values that differ one transaction from another, one per line. Usually those are the account numbers, but can also be addresses, currencies etc. Enter each expression in full, not just the name of the field.
For each unique combination of keys' values, a new cached reaction is created. The reaction uses a script to match any request that contains the same key values, as well as the same HTTP method, relative URI and SOAPAction/top XML element (for XML requests).
For instance, the key
input.account.id
input.account.id=='18474332674'
input.account.id=='22274332811'
Keep the request expressions in one language: either all XQuery or all JavaScript/JSONPath, because they are combined into one matching script. A key that cannot be computed is skipped.
The cached reactions are marked as such in the reactions list. They can be deleted in bulk from the service and environment pages.
Example: Set a static authorization header:
Authorization: Bearer mytoken
Example: Forward a correlation ID from the original request:
X-Correlation-ID: input.headers["X-Correlation-ID"]
Content-Language: en X-Request-ID: $..requestId