A response can use values of one or more mock accounts selected for this transaction. The values can be populated into the response payload, used to control the delay or select the HTTP status.
The selection usually happens based on some value in the request. For example, the request can contain an account number, and a mock account with the same account number can be selected.
The accounts selection is performed in the Accounts Selection section of the response configuration, and the selected accounts are placed into
Execution with No Accounts
By default, every response has no accounts selected. The accounts selection dialog looks like this:
accounts variables are empty. Only the values from the request are available to build the response.
Execution with Accounts
To select an account (or a group of accounts), we need to add a selection expression.
Click on the plus button:
A new selection equation is added.
Select the mock account property name from the drop-down list. On the right side of the equation, write a script of value the property should be equal to
for an account to be selected. Most often the value on the right side is read from the request, e.g. here it is read from the request XML element which is named
In other words, we:
1 Read the value from the request using XQuery
$input//*:office-id (say it is equal to 1234)
2 Search for all mock accounts that have the property
officeId with the value 1234
3 Set all the found accounts to the variable
4 Set one random account of the found ones to the variable
Selection with Multiple Conditions
There could be more than one condition to select an account. For example, an account can be selected by its property
flowName (a subset of accounts seeded to test a specific
test flow) and then by the
office-id value from the request, like below:
All conditions must be true for an account to be selected (i.e., logical AND join). MockMotor currently doesn't support logical OR join.
Actions if Not Found
What if the search for accounts doesn't yield any results? There are three options available: fail, ignore and continue and create.
If no conditions are defined, Actions if Not Found are not in effect.
This is the default option.
With this option, when no accounts found matching the conditions, MockMotor fails the request with HTTP 500 and a descriptive error message:
HTTP/1.1 500 Server Error Date: Mon, 04 Sep 2017 19:45:33 GMT Content-Length: 406 com.rfctr.mockmotor.engine.MockMotorException: No accounts found with variable officeId matching values '' computed as '$input//*:office-id' in response 'GetOfficeDetails' com.rfctr.mockmotor.responses.ResponseExecutor.matchAndExecuteResponse(ResponseExecutor.java:111) com.rfctr.mockmotor.engine.MockMotorRequestsHandler.handle(MockMotorRequestsHandler.java:188) ...
Ignore and Continue
This option allows you to continue the execution of the current response even if no accounts were found to satisfy our conditions.
The values of
the lack of the accounts - for example, set the response payload error code to
ACCOUNT_NOT_FOUND or similar to simulate the behaviour of a real backend service.
The last option allows you to create a mock account if it doesn't exist. This option is useful for testing scenarios such as registration flows, where the registration ID is generated by some other system and cannot be predicted (and cannot be seeded into a mock account).
MockMotor creates an empty mock account with all properties null except the ones specified in the selection condition.
In the example above, the value from the request element <office-id> will be populated into the
officeId property of the new account.
The new account is bound to
The response may also update the account after the execution using the dialog in the Update Accounts section.