Each mock service contains several mock responses.
A mock response is a configured reply for a request. The response has a pre-configured payload (often scripted), HTTP status, delay and other properties that the calling application expects to receive to continue the test scenario.
In the simplest form, there is one mock response per service operation (SOAP operation or a REST method+URI).
In more complex cases, there could be multiple responses per operation, one response handling multiple operations or even responses that do not correspond to any specific operation.
Responses in a mock service are organized as a list.
For each incoming request, each response is tried in turn, starting from the top of the list until one of them matches.
If there are no responses left in the list and the match is still not found, MockMotor generates an HTTP 404 response.
For example, in the service above, the incoming request will be:
1 First checked for HTTP operation POST and the relative URL /pet.
2 Then, if either of these conditions fails to match, the request will be checked for HTTP POST and URL /user.
3 And so on.
Response Order Change
As already mentioned, the responses are matched in order of their appearance on the list.
To change the order of responses, drag and drop a response to its new place using the reorder control :
Adding a New Response
Adding a Mock Response from Request and Response
It is a common situation when development provides a request/response pair saying, “This is our request, and this is the response we want to have.”
Perfect! We can do just that.
On the Responses page, click
Add Response... and then
From Request/Response Pair....
A new dialog appears. Enter your request and response into the dialog window.
You can provide the request and response headers:
Or, you can just provide the payloads:
In the second case, you'll have to provide the HTTP-related fields in the mock response after it is created.
Create and MockMotor creates a new mock response that matches your request and returns your response.
Adding a Response Manually, Step by Step
To add a new response, click on provide
Add Response and then
Provide the required properties. The minimum is the Match Options and Response Payload. When the changes are complete, click
More on response properties in:
Editing a Response
To edit a response, navigate to the Response page by clicking on either the edit icon in the response row or on the response name.
Cloning a Response
To create a copy of an existing response, navigate to the Response page and click
Clone. Read more details on this here.
Deleting a Response
To delete a response, navigate to the Response page and click
Delete. You are asked for confirmation.
Note that this operation is not reversible.
Disabling a Response
A safer alternative to deleting a response is to disable it.
Navigate to the Response page and click “Disabled” in the Status line, then click
Save. The response will be disabled, i.e. ignored by any incoming requests.
The disabled responses are strike-through in the response list: