Multiple Mock Data Files
  • 11 Jan 2023
  • Dark
    Light
  • PDF

Multiple Mock Data Files

  • Dark
    Light
  • PDF

Article Summary

Multiple Mock Data Files

The adapter has a hierarchy for determining which response to use for a request.

Mock data hierarchy:

  1. Match data in the body.
  2. Match data in a path variable.
  3. Match data in a query or option.
  4. If there is a body (withBody).
  5. If there is a path variable (withPathv#).
  6. If there is a query (withQuery).
  7. If there is an option (withOption).
  8. Otherwise default.

Note: The old mock data format will still work since #5-8 are effectively the old way.

  • On a call with a body { name: ‘abc123’ } the a.json would be returned.
  • On a call with a path variable – http://system:80/path/ver/addresses/error the b.json would be returned.
  • On a call with a query variable – http://system:80/path/ver/addresses?name=happy the c.json would be returned.

Example: Action.json

    {
      "name": "getIP",
      "entitypath": "{base_path}/{version}/addresses/{pathv1}?{query}",
	….
      "responseObjects": [
        {
          "type": "name-abc123",
          "key": "",
          "mockFile": "a.json"
        },
        {
          "type": "error",
          "key": "",
          "mockFile": "b.json"
        },
        {
          "type": "name=happy",
          "key": "",
          "mockFile": "c.json"
        }
      ]
    },
  • Can still support different mock data based on the URI structure:
    • path variables (withPathv#)
    • query (withQuery)
  • On a call with a path variable – http://system:80/path/ver/addresses/abc123 the y.json is returned
  • On a call with a query variable – http://system:80/path/ver/addresses?name=abc123 the z.json is returned.
  • Otherwise the x.json is returned.

Example: Action.json

    {
      "name": "getIP",
      "entitypath": "{base_path}/{version}/addresses/{pathv1}?{query}",
	….
      "responseObjects": [
        {
          "type": "default",
          "key": "",
          "mockFile": "x.json"
        },
        {
          "type": "withPathv1",
          "key": "",
          "mockFile": "y.json"
        },
        {
          "type": "withQuery",
          "key": "",
          "mockFile": "z.json"
        }
      ]
    },

Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.