Accounts Selection

A reaction 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 reaction configuration, and the selected accounts are placed into $account/$accounts and account/accounts variables for XQuery and Javascript. Read more about account variables here.

Execution with No Accounts

By default, every reaction has no accounts selected. The accounts selection dialog looks like this:

The account/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 office-id:

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 $accounts (accounts for Javascript)
4 Set one random account of the found ones to the variable $account (account for Javascript)

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.

Fail Immediately

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 '[100500]' computed as '$input//*:office-id'
in reaction '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 reaction even if no accounts were found to satisfy our conditions.

The values of $accounts/accounts and $account/account will be empty (null for Javascript). The reaction scripts can then make decisions based on 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.

Create New

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 $accounts/accounts and $account/account variables.

The reaction may also update the account after the execution using the dialog in the Update Accounts section.