Mock Data Adapter

The Quantum Mock Data adapter capability helps you to continue to develop apps when the back-end services that an app connects to are not ready to be leveraged.

There are several instances in an app development life-cycle when back-end systems and app development happen in parallel and only the contract or interface for the app to communicate to a backend is finalized. In this scenario, you can create a response template to stub the response that is expected from the actual backend. The response template can have hard-coded values or use pre-built functions such as concat, firstName, lastName, gender, random, email, and phone, and options to randomize the output within the required criteria.

For example, in the scenario mentioned earlier, a Quantum app developer can create the service based on a stub template. The stub response template can be set for each operation of a service. The app developers can continue to develop apps based on a sample back-end response from the stub template.

IMPORTANT: Services built with Mock Data adapter will always give you mock data and cannot be switch between live backend and mock data like Stub backend response feature.

Configure Mock Data Adapter

To configure your Mock Data Adapter, provide the following details:

  1. In the Name field, provide a unique name for your service.
  2. From the Service Type list, select Mock Data.


  3. NOTE: All options in the Advanced section are optional.

  4. In the Description field, provide a suitable description for the service.

  5. Click Save to save your service definition.

Create Operations for Mock Data

The Operations List tab appears only after the service definition is saved.

NOTE: Click Operations List tab > Configure Operation. The Configured Operations list appears.

To create an operation, follow these steps:

  1. Click SAVE & ADD OPERATION in your service definition page to save your service definition and display the NewOperation tab for adding operations.
                        OR
    Click Add Operation to add a new operation or from the tree in the left pane, click Add > Add New Operation.
  2. In the Operation Modal tab, follow these steps:

    This tab contains the request input, response output, and advanced sections. The input values are data types, scope, and format types. By default, the system will display the Request Input tab.

    NOTE: You can add an entry by clicking the Add button if entries for the input and the output tabs do not exist.

    You can also delete an entry. Select the check box for an entry, and then click the Delete button.

  3. To configure an operation, provide the following details:
  4. Field Description
    Name It is prepopulated with the operation name. You can change the name if required.
    Operation Security Level

    It specifies how a client must authenticate to invoke this operation.

  5. Configure your Mock data template in the Mock Data JSON Template text field. By default this field is enabled with a sample mock response template.

    NOTE: For more information on Pre-built functions supported in Mock Data template, refer Mock Data Template and Supported Pre-built functions in Mock Data

  6. NOTE: All options in the Advanced section are optional.

Configure Request Operation for Mock Data

Integration services accept only form-url-encoded inputs for all the input parameters provided in the service input parameters (request input).

  1. In the Request Input > Body tab, do the following:
    1. To forward the body of the client's request to backend as it is, select the Enable pass-through input body check box. For more details on API Proxy service, refer to How to Enable Pass-through Proxy for Operations.
    2. Click Add Parameter button to create new entries for the input.

      NOTE: - To make duplicate entries, select the check box for the entry, click Copy, and then click Paste.

      - To delete an entry, select the check box for an entry, and then click the Delete button.

    3. Configure parameters in the client's body, do the following:
      FieldDescription
      NameIt Contains a Unique Identifier. Change the name if required.
      Value

      Select Request or Session. It is set to Request by default.

      1. Request indicates that the value must be retrieved from the HTTP request received from the mobile device.
      2. Session indicates that the value must be retrieved from the HTTP session stored on Quantum Fabric.
      3. Identity: If this is selected, you can filter the request parameters based on the response from the identity provider. For more details to configure identity filters, refer to Enhanced Identity Filters - Integration Services.

      NOTE: For more information on Externalizing Identity Services, refer to Replace the Identity Service references in a Fabric app.

      TEST VALUEEnter a value. A test value is used for testing the service.
      DEFAULT VALUEEnter the value, if required. The default value will be used if the test value is empty.
      Datatype
      Encode

      Select the check box to enable encoding of an input parameter. For example, the name New York Times would be encoded as New%20York%20Times when the encoding is set to True. The encoding must also adhere to the HTML URL encoding standards.

      DescriptionProvide a suitable description.
  1. In the Request Input > Header tab, do the following:
    1. To forward the body of the client's request to backend as it is, select the Enable pass-through input body check box. For more details on API Proxy service, refer to How to Enable Pass-through Proxy for Operations.
    2. Click Add Parameter button to create new entries for the input.

      NOTE: - To make duplicate entries, select the check box for the entry, click Copy, and then click Paste.

      - To delete an entry, select the check box for an entry, and then click the Delete button.

    3. Configure parameters in the client's header, do the following:
      FieldDescription
      NameIt Contains a Unique Identifier. Change the name if required.
      Value

      Select Request or Session. It is set to Request by default.

      By default, this field is set to Request. Five different options are available in Quantum Fabric under Request Input > Headers > VALUE during configuration of any operation. When you start editing this field, dependent identity services are auto populated. These options primarily determine the source of the value of the header.

      • Request: If this option is selected, the Integration Server picks the value pairs from the client's request during run time and forwards the same to the back-end.

        User has the option to configure the default value. This default value is taken if the request does not have the header.

      • Session: If this option is selected, the value of header is picked from session context based on the user configuration.
      • Constant: Constant is used to configure the value that is picked and sent to back-end by the Integration Server during the run-time.
      • Expression: Select this option to configure the velocity template expressions for the header values.

        You cannot edit the default value for expression.

      • Identity: If this is selected, you can filter the request parameters based on the response from the identity provider. For more details to configure identity filters, refer to Enhanced Identity Filters - Integration Services.

        NOTE: If the header value is scoped as a Request (or) Session and the same header is accessed under the Expression header value, then the expression must be represented as $request.header (or) $session.header.

        Example: If a header 1 value is a request and header 2 value is an expression, then the value of the expression must be $Request.header1.

        NOTE: For more information on Externalizing Identity Services, refer to Replace the Identity Service references in a Fabric app.

      TEST VALUEEnter a value. A test value is used for testing the service.
      DEFAULT VALUEEnter the value, if required. The default value will be used if the test value is empty.
      Datatype
      DescriptionProvide a suitable description.
  2. Click SAVE OPERATION to save the operation. The system updates the operation definition.

Create Response Operation for Mock Data

To forward the response to the client as it is, select the Enable pass-through input body check box. For more details on API Proxy service, refer to How to Enable Pass-through Proxy for Operations.

  1. Click the Response Output tab, and enter the values for required fields such as name, scope, data type, collection ID, record ID, format and format value.

    NOTE: If you define parameters inside a record as the session, the session scope will not get reflected for the parameters.

  2. Click SAVE OPERATION to save the operation. The system updates the operation definition.

    If you click Cancel, the Edit Service Parameters window will close without saving any information.

    NOTE: Only JSON Path is supported for Mock Data response parsing.

    NOTE: You can view the service in the Data Panel feature of Quantum Visualizer. By using the Data Panel, you can link back-end data services to your application UI elements seamlessly with low-code to no code. For more information on Data Panel, click here.

 

How to Test a Mock Data Response from Admin Console

  1. Publish your app to a runtime server.
  2. Go to the runtime server in Admin Console.
  3. Go to the Integration Services tab.
  4. For the Mock Data service that you created, select the stubbed operation from the Operations list.
  5. Click Get Response.

    NOTE: The X-Kony-Stub-Response header as true in the back-end response indicates that the response is generated from the Mock Data template.

Advanced Parameters in Mock Data

How to Configure a Request Input and Request Header Parameters in Mock Data

You can access input parameters in a Stub template by using the {{requestBody("<request_param_name>")}} function. Additionally, you can access headers by using the {{requestHeader("<header_name>")}} function.

For example, you want to send the testUser request input parameter to the Stub template and the value of the parameter is defined in the Input Parameters section of Console. You can access the input parameter in the stub template as "inputtest": "{{requestBody("testUser")}}".

The following sample Stub template has been configured with the testUser request input parameter.

 [
  '{{repeat(30,40)}}',
  {
    "locationID": "{{index()}}",
    "company": "{{toUpperCase(company())}}",
    "phone": "+1 {{phone()}}",
    "address": "{{integer(100, 999)}} {{street()}}, {{city()}}, {{state()}}, {{integer(100, 10000)}}",
   "inputtest": "{{requestBody("testUser")}}", "latitude": "{{float(-90.000001, 90)}}",
"longitude": "{{float(-180.000001, 180)}}", "office":"{{random("HR Head Office","Sales Head Office","Marketing Head Office","Development Center")}}" } ]

NOTE: Quantum functions for request input and header are as follows:

-  To access any header with name, requestHeader: Syntax: {{requestHeader("<header_name>")}}
-  To access a request parameter, requestBody: Syntax: {{requestBody("<request_param_name>")}}

 

Mock Data Template and Pre-built Functions Supported in Mock Data Template